monolish  0.17.1
MONOlithic LInear equation Solvers for Highly-parallel architecture
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
monolish::tensor::tensor_COO< Float > Class Template Reference

#include <monolish_tensor_coo.hpp>

Collaboration diagram for monolish::tensor::tensor_COO< Float >:
Collaboration graph

Public Member Functions

Float at (const std::vector< size_t > &pos)
 get element A[pos[0]][pos[1]]... (onlu CPU) More...
 
Float at (const std::vector< size_t > &pos) const
 get element A[pos[0]][pos[1]]... More...
 
void convert (const tensor::tensor_Dense< Float > &tens)
 Create tensor_COO tensor from tensor_Dense tensor. More...
 
Float * data ()
 returns a direct pointer to the tensor More...
 
const Float * data () const
 returns a direct pointer to the tensor More...
 
void diag (vector< Float > &vec) const
 get diag. vector More...
 
void diag (view1D< matrix::Dense< Float >, Float > &vec) const
 
void diag (view1D< tensor::tensor_Dense< Float >, Float > &vec) const
 
void diag (view1D< vector< Float >, Float > &vec) const
 
bool equal (const tensor_COO< Float > &tens, bool compare_cpu_and_device=false) const
 Comparing tensors (A == tens) More...
 
void fill (Float value)
 fill tensor elements with a scalar value More...
 
double get_data_size () const
 Memory data space required by the matrix. More...
 
bool get_device_mem_stat () const
 true: sended, false: not send More...
 
std::vector< size_t > get_index (const size_t pos)
 get vector index from aligned index (A[pos[0]][pos[1]]... = A[ind]) More...
 
size_t get_index (const std::vector< size_t > &pos)
 get aligned index from vector index (A[pos] = A[ind[0]][ind[1]]...) More...
 
size_t get_nnz () const
 get # of non-zeros More...
 
std::vector< size_t > get_shape () const
 get shape More...
 
void insert (const std::vector< size_t > &pos, const Float val)
 insert element A[pos[0]][pos[1]]... More...
 
bool operator!= (const tensor_COO< Float > &tens) const
 Comparing tensors (A != tens) More...
 
void operator= (const tensor_COO< Float > &tens)
 tensor copy More...
 
bool operator== (const tensor_COO< Float > &tens) const
 Comparing tensors (A == tens) More...
 
Float & operator[] (size_t i)
 reference to the element at position (v[i]) More...
 
void print_all (bool force_cpu=false) const
 print all elements to standard I/O More...
 
void print_all (const std::string filename) const
 print all elements to file More...
 
void resize (const size_t N, Float Val=0)
 resize tensor value More...
 
void set_ptr (const std::vector< size_t > &shape, const std::vector< std::vector< size_t >> &index, const size_t vsize, const Float *v)
 Set tensor_COO array from array. More...
 
void set_ptr (const std::vector< size_t > &shape, const std::vector< std::vector< size_t >> &index, const std::vector< Float > &v)
 Set tensor_COO array from std::vector. More...
 
void set_shape (const std::vector< size_t > &shape)
 Set shape. More...
 
void sort (bool merge)
 sort tensor_COO tensor elements (and merge elements) More...
 
 tensor_COO ()
 
 tensor_COO (const std::vector< size_t > &shape_)
 Initialize tensor_COO tensor. More...
 
 tensor_COO (const std::vector< size_t > &shape_, const std::vector< std::vector< size_t >> &index_, const Float *value)
 Create tensor_COO tensor from n-origin array. More...
 
 tensor_COO (const tensor::tensor_Dense< Float > &tens)
 Create tensor_COO tensor from tensor_Dense tensor. More...
 
 tensor_COO (const tensor_COO< Float > &coo)
 Create tensor_COO tensor from tensor_COO tensor. More...
 
 tensor_COO (const tensor_COO< Float > &coo, Float value)
 Initialize tensor_COO tensor of the same size as input tensor. More...
 
std::string type () const
 get format name "tensor_COO" More...
 

Public Attributes

std::size_t alloc_nnz = 0
 alloced matrix size More...
 
std::vector< std::vector< size_t > > index
 Coodinate format index, which stores index numbers of the non-zero elements (size nnz) More...
 
std::shared_ptr< Float > val
 Coodinate format value array (pointer), which stores values of the non-zero elements. More...
 
bool val_create_flag = false
 matrix create flag; More...
 
size_t val_nnz = 0
 # of non-zero element More...
 

Private Member Functions

void _q_sort (int lo, int hi)
 

Private Attributes

bool gpu_status = false
 true: sended, false: not send More...
 
std::vector< size_t > shape
 shape More...
 

Detailed Description

template<typename Float>
class monolish::tensor::tensor_COO< Float >

Definition at line 11 of file monolish_tensor_coo.hpp.

Constructor & Destructor Documentation

◆ tensor_COO() [1/6]

template<typename Float >
monolish::tensor::tensor_COO< Float >::tensor_COO ( )
inline

Definition at line 51 of file monolish_tensor_coo.hpp.

◆ tensor_COO() [2/6]

template<typename Float >
monolish::tensor::tensor_COO< Float >::tensor_COO ( const std::vector< size_t > &  shape_)
inline

Initialize tensor_COO tensor.

Parameters
shapeshape of tensor
Note
  • # of computation: 0
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 63 of file monolish_tensor_coo.hpp.

◆ tensor_COO() [3/6]

template<typename Float >
monolish::tensor::tensor_COO< Float >::tensor_COO ( const tensor::tensor_Dense< Float > &  tens)
inline

Create tensor_COO tensor from tensor_Dense tensor.

Parameters
tensinput tensor_Dense tensor
Note
  • # of computation: size
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 86 of file monolish_tensor_coo.hpp.

Here is the call graph for this function:

◆ tensor_COO() [4/6]

template<typename Float >
monolish::tensor::tensor_COO< Float >::tensor_COO ( const std::vector< size_t > &  shape_,
const std::vector< std::vector< size_t >> &  index_,
const Float *  value 
)

Create tensor_COO tensor from n-origin array.

Parameters
shape_shape of tensor
index_n-origin index, which stores the numbers of the non-zero elements (size nnz)
valuen-origin value, which stores the non-zero elements (size nnz)
Note
  • # of computation: size
  • Multi-threading: false
  • GPU acceleration: false

◆ tensor_COO() [5/6]

template<typename Float >
monolish::tensor::tensor_COO< Float >::tensor_COO ( const tensor_COO< Float > &  coo)

Create tensor_COO tensor from tensor_COO tensor.

Parameters
tensinput tensor_COO tensor
Note
  • # of computation: nnz
  • Multi-threading: false
  • GPU acceleration: false

◆ tensor_COO() [6/6]

template<typename Float >
monolish::tensor::tensor_COO< Float >::tensor_COO ( const tensor_COO< Float > &  coo,
Float  value 
)

Initialize tensor_COO tensor of the same size as input tensor.

Parameters
tensinput tensor_COO tensor
valuethe value to initialize elements
Note
  • # of computation: nnz
  • Multi-threading: false
  • GPU acceleration: false

Member Function Documentation

◆ _q_sort()

template<typename Float >
void monolish::tensor::tensor_COO< Float >::_q_sort ( int  lo,
int  hi 
)
private

◆ at() [1/2]

template<typename Float >
Float monolish::tensor::tensor_COO< Float >::at ( const std::vector< size_t > &  pos)
inline

get element A[pos[0]][pos[1]]... (onlu CPU)

Parameters
posstd::vector position
Returns
A[pos[0]][pos[1]]...
Note
  • # of computation: nnz
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 179 of file monolish_tensor_coo.hpp.

Here is the call graph for this function:

◆ at() [2/2]

template<typename Float >
Float monolish::tensor::tensor_COO< Float >::at ( const std::vector< size_t > &  pos) const

get element A[pos[0]][pos[1]]...

Parameters
posstd::vector position
Returns
A[pos[0]][pos[1]]...
Note
  • # of computation: nnz
  • Multi-threading: false
  • GPU acceleration: false
Here is the caller graph for this function:

◆ convert()

template<typename Float >
void monolish::tensor::tensor_COO< Float >::convert ( const tensor::tensor_Dense< Float > &  tens)

Create tensor_COO tensor from tensor_Dense tensor.

Parameters
tensinput tensor_Dense tensor
Note
  • # of computation: size
  • Multi-threading: false
  • GPU acceleration: false
Here is the caller graph for this function:

◆ data() [1/2]

template<typename Float >
Float* monolish::tensor::tensor_COO< Float >::data ( )
inline

returns a direct pointer to the tensor

Returns
A pointer to the first element
Note
  • # of computation: 1

Definition at line 269 of file monolish_tensor_coo.hpp.

◆ data() [2/2]

template<typename Float >
const Float* monolish::tensor::tensor_COO< Float >::data ( ) const
inline

returns a direct pointer to the tensor

Returns
A const pointer to the first element
Note
  • # of computation: 1

Definition at line 261 of file monolish_tensor_coo.hpp.

Here is the caller graph for this function:

◆ diag() [1/4]

template<typename Float >
void monolish::tensor::tensor_COO< Float >::diag ( vector< Float > &  vec) const

get diag. vector

Parameters
vecdiag. vector
Note
  • # of computation: nnz
  • Multi-threading: false
  • GPU acceleration: false

◆ diag() [2/4]

template<typename Float >
void monolish::tensor::tensor_COO< Float >::diag ( view1D< matrix::Dense< Float >, Float > &  vec) const

◆ diag() [3/4]

template<typename Float >
void monolish::tensor::tensor_COO< Float >::diag ( view1D< tensor::tensor_Dense< Float >, Float > &  vec) const

◆ diag() [4/4]

template<typename Float >
void monolish::tensor::tensor_COO< Float >::diag ( view1D< vector< Float >, Float > &  vec) const

◆ equal()

template<typename Float >
bool monolish::tensor::tensor_COO< Float >::equal ( const tensor_COO< Float > &  tens,
bool  compare_cpu_and_device = false 
) const

Comparing tensors (A == tens)

Parameters
tenstensor_COO tensor
compare_cpu_and_devicecompare data on both CPU and GPU
Returns
true or false
Note
  • # of computation: size
  • Multi-threading: true
  • GPU acceleration: true

◆ fill()

template<typename Float >
void monolish::tensor::tensor_COO< Float >::fill ( Float  value)

fill tensor elements with a scalar value

Parameters
valuescalar value
Note
  • # of computation: N
  • Multi-threading: true
  • GPU acceleration: true

◆ get_data_size()

template<typename Float >
double monolish::tensor::tensor_COO< Float >::get_data_size ( ) const
inline

Memory data space required by the matrix.

Note
  • # of computation: 3
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 155 of file monolish_tensor_coo.hpp.

Here is the call graph for this function:

◆ get_device_mem_stat()

template<typename Float >
bool monolish::tensor::tensor_COO< Float >::get_device_mem_stat ( ) const
inline

true: sended, false: not send

Returns
gpu status

Definition at line 253 of file monolish_tensor_coo.hpp.

Here is the caller graph for this function:

◆ get_index() [1/2]

template<typename Float >
std::vector<size_t> monolish::tensor::tensor_COO< Float >::get_index ( const size_t  pos)
inline

get vector index from aligned index (A[pos[0]][pos[1]]... = A[ind])

Parameters
posposition (scalar)
Returns
vector position
Note
  • # of computation: shape size
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 421 of file monolish_tensor_coo.hpp.

◆ get_index() [2/2]

template<typename Float >
size_t monolish::tensor::tensor_COO< Float >::get_index ( const std::vector< size_t > &  pos)
inline

get aligned index from vector index (A[pos] = A[ind[0]][ind[1]]...)

Parameters
posposition (std::vector)
Returns
aligned position
Note
  • # of computation: shape size
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 400 of file monolish_tensor_coo.hpp.

◆ get_nnz()

template<typename Float >
size_t monolish::tensor::tensor_COO< Float >::get_nnz ( ) const
inline

get # of non-zeros

Note
  • # of computation: 1
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 228 of file monolish_tensor_coo.hpp.

Here is the caller graph for this function:

◆ get_shape()

template<typename Float >
std::vector<size_t> monolish::tensor::tensor_COO< Float >::get_shape ( ) const
inline

get shape

Note
  • # of computation: 1
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 219 of file monolish_tensor_coo.hpp.

◆ insert()

template<typename Float >
void monolish::tensor::tensor_COO< Float >::insert ( const std::vector< size_t > &  pos,
const Float  val 
)

insert element A[pos[0]][pos[1]]...

Parameters
posstd::vector position
valscalar value
Note
  • # of computation: 1
  • Multi-threading: false
  • GPU acceleration: false

◆ operator!=()

template<typename Float >
bool monolish::tensor::tensor_COO< Float >::operator!= ( const tensor_COO< Float > &  tens) const

Comparing tensors (A != tens)

Parameters
tenstensor_COO tensor
Returns
true or false
Note
  • # of computation: size
  • Multi-threading: true
  • GPU acceleration: true
    • if gpu_status == true; compare data on GPU
    • else; compare data on CPU

◆ operator=()

template<typename Float >
void monolish::tensor::tensor_COO< Float >::operator= ( const tensor_COO< Float > &  tens)

tensor copy

Parameters
tensCOO tensor
Note
  • # of computation: size
  • Multi-threading: false
  • GPU acceleration: false
Warning
src. and dst. must be same non-zero structure (dont check in this function)

◆ operator==()

template<typename Float >
bool monolish::tensor::tensor_COO< Float >::operator== ( const tensor_COO< Float > &  tens) const

Comparing tensors (A == tens)

Parameters
tenstensor_COO tensor
Returns
true or false
Note
  • # of computation: size
  • Multi-threading: true
  • GPU acceleration: true
    • if gpu_status == true; compare data on GPU
    • else; compare data on CPU

◆ operator[]()

template<typename Float >
Float& monolish::tensor::tensor_COO< Float >::operator[] ( size_t  i)
inline

reference to the element at position (v[i])

Parameters
iPosition of an element in the vector
Returns
vector element (v[i])
Note
  • # of computation: 1
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 345 of file monolish_tensor_coo.hpp.

Here is the call graph for this function:

◆ print_all() [1/2]

template<typename Float >
void monolish::tensor::tensor_COO< Float >::print_all ( bool  force_cpu = false) const

print all elements to standard I/O

Parameters
force_cpuUnused options for integrity
Note
  • # of computation: 3nnz
  • Multi-threading: false
  • GPU acceleration: false

◆ print_all() [2/2]

template<typename Float >
void monolish::tensor::tensor_COO< Float >::print_all ( const std::string  filename) const

print all elements to file

Parameters
filenameoutput filename
Note
  • # of computation: 3nnz
  • Multi-threading: false
  • GPU acceleration: false

◆ resize()

template<typename Float >
void monolish::tensor::tensor_COO< Float >::resize ( const size_t  N,
Float  Val = 0 
)
inline

resize tensor value

Parameters
Ntensor size
Note
  • # of computation: N
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 279 of file monolish_tensor_coo.hpp.

Here is the call graph for this function:

◆ set_ptr() [1/2]

template<typename Float >
void monolish::tensor::tensor_COO< Float >::set_ptr ( const std::vector< size_t > &  shape,
const std::vector< std::vector< size_t >> &  index,
const size_t  vsize,
const Float *  v 
)

Set tensor_COO array from array.

Parameters
shapeshape of tensor
indixindex fo tensor
vsizesize of value
vvalue
Note
  • # of computation: 3
  • Multi-threading: false
  • GPU acceleration: false

◆ set_ptr() [2/2]

template<typename Float >
void monolish::tensor::tensor_COO< Float >::set_ptr ( const std::vector< size_t > &  shape,
const std::vector< std::vector< size_t >> &  index,
const std::vector< Float > &  v 
)

Set tensor_COO array from std::vector.

Parameters
shapeshape of tensor
indixindex fo tensor
vvalue
Note
  • # of computation: 3
  • Multi-threading: false
  • GPU acceleration: false

◆ set_shape()

template<typename Float >
void monolish::tensor::tensor_COO< Float >::set_shape ( const std::vector< size_t > &  shape)
inline

Set shape.

Parameters
shapeshape of tensor
  • # of computation: 1
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 247 of file monolish_tensor_coo.hpp.

◆ sort()

template<typename Float >
void monolish::tensor::tensor_COO< Float >::sort ( bool  merge)

sort tensor_COO tensor elements (and merge elements)

Parameters
mergeneed to merge (true or false)
Note
  • # of computation: 3nnz x log(3nnz) ~ 3nnz^2
  • Multi-threading: false
  • GPU acceleration: false

◆ type()

template<typename Float >
std::string monolish::tensor::tensor_COO< Float >::type ( ) const
inline

get format name "tensor_COO"

Note
  • # of computation: 1
  • Multi-threading: false
  • GPU acceleration: false

Definition at line 309 of file monolish_tensor_coo.hpp.

Member Data Documentation

◆ alloc_nnz

template<typename Float >
std::size_t monolish::tensor::tensor_COO< Float >::alloc_nnz = 0

alloced matrix size

Definition at line 44 of file monolish_tensor_coo.hpp.

◆ gpu_status

template<typename Float >
bool monolish::tensor::tensor_COO< Float >::gpu_status = false
mutableprivate

true: sended, false: not send

Definition at line 21 of file monolish_tensor_coo.hpp.

◆ index

template<typename Float >
std::vector<std::vector<size_t> > monolish::tensor::tensor_COO< Float >::index

Coodinate format index, which stores index numbers of the non-zero elements (size nnz)

Definition at line 28 of file monolish_tensor_coo.hpp.

◆ shape

template<typename Float >
std::vector<size_t> monolish::tensor::tensor_COO< Float >::shape
private

shape

Definition at line 16 of file monolish_tensor_coo.hpp.

◆ val

template<typename Float >
std::shared_ptr<Float> monolish::tensor::tensor_COO< Float >::val

Coodinate format value array (pointer), which stores values of the non-zero elements.

Definition at line 34 of file monolish_tensor_coo.hpp.

◆ val_create_flag

template<typename Float >
bool monolish::tensor::tensor_COO< Float >::val_create_flag = false

matrix create flag;

Definition at line 49 of file monolish_tensor_coo.hpp.

◆ val_nnz

template<typename Float >
size_t monolish::tensor::tensor_COO< Float >::val_nnz = 0

# of non-zero element

Definition at line 39 of file monolish_tensor_coo.hpp.


The documentation for this class was generated from the following files: