7 template <
typename Float>
class vector;
8 template <
typename TYPE,
typename Float>
class view1D;
10 template <
typename Float>
class tensor_Dense;
28 std::vector<std::vector<size_t>>
index;
34 std::shared_ptr<Float>
val;
116 const std::vector<std::vector<size_t>> &index_,
169 return get_nnz() *
sizeof(Float) / 1.0e+9;
181 [[nodiscard]] Float
at(
const std::vector<size_t> &pos)
const;
192 [[nodiscard]] Float
at(
const std::vector<size_t> &pos) {
207 const std::vector<std::vector<size_t>> &
index,
208 const std::vector<Float> &v);
222 const std::vector<std::vector<size_t>> &
index,
223 const size_t vsize,
const Float *v);
237 const std::vector<std::vector<size_t>> &
index,
238 const size_t vsize,
const Float v);
289 [[nodiscard]]
const Float *
data()
const {
return val.get(); }
297 [[nodiscard]] Float *
data() {
return val.get(); }
307 void resize(
const size_t N, Float Val = 0) {
309 throw std::runtime_error(
"Error, GPU matrix cant use resize");
312 std::shared_ptr<Float> tmp(
new Float[N], std::default_delete<Float[]>());
314 for (
size_t i = 0; i < copy_size; ++i) {
315 tmp.get()[i] =
data()[i];
317 for (
size_t i = copy_size; i < N; ++i) {
326 throw std::runtime_error(
"Error, not create vector cant use resize");
337 [[nodiscard]] std::string
type()
const {
return "tensor_COO"; }
345 [[nodiscard]]
const Float *
begin()
const {
return data(); }
407 throw std::runtime_error(
"Error, GPU vector cant use operator[]");
423 bool compare_cpu_and_device =
false)
const;
461 if (pos.size() != this->shape.size()) {
462 throw std::runtime_error(
"pos size should be same with the shape");
465 for (
auto i = 0; i < pos.size(); ++i) {
466 ind *= this->shape[i];
482 std::vector<size_t> ind(this->shape.size(), 0);
484 for (
int i = (
int)this->shape.size() - 1; i >= 0; --i) {
485 ind[i] = pos_copy % this->shape[i];
486 pos_copy /= this->shape[i];
500 void insert(
const std::vector<size_t> &pos,
const Float
val);
void convert(const tensor::tensor_Dense< Float > &tens)
Create tensor_COO tensor from tensor_Dense tensor.
void diag(view1D< tensor::tensor_Dense< Float >, Float > &vec) const
bool operator!=(const tensor_COO< Float > &tens) const
Comparing tensors (A != tens)
std::size_t alloc_nnz
alloced matrix size
void resize(const size_t N, Float Val=0)
resize tensor value
void diag(vector< Float > &vec) const
get diag. vector
void sort(bool merge)
sort tensor_COO tensor elements (and merge elements)
std::string type() const
get format name "tensor_COO"
Float * begin()
returns a begin iterator
void _q_sort(int lo, int hi)
tensor_COO(const std::vector< size_t > &shape_)
Initialize tensor_COO tensor.
const Float * end() const
returns a end iterator
Float * end()
returns a end iterator
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.
const Float * data() const
returns a direct pointer to the tensor
const Float * begin() const
returns a begin iterator
bool get_device_mem_stat() const
true: sended, false: not send
size_t get_index(const std::vector< size_t > &pos)
get aligned index from vector index (A[pos] = A[ind[0]][ind[1]]...)
std::vector< size_t > get_index(const size_t pos)
get vector index from aligned index (A[pos[0]][pos[1]]... = A[ind])
void print_all(bool force_cpu=false) const
print all elements to standard I/O
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.
std::vector< size_t > shape
shape
std::shared_ptr< Float > val
Coodinate format value array (pointer), which stores values of the non-zero elements.
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.
void print_all(const std::string filename) const
print all elements to file
std::vector< std::vector< size_t > > index
Coodinate format index, which stores index numbers of the non-zero elements (size nnz)
Float * data()
returns a direct pointer to the tensor
size_t get_nnz() const
get # of non-zeros
bool operator==(const tensor_COO< Float > &tens) const
Comparing tensors (A == tens)
std::vector< size_t > get_shape() const
get shape
bool equal(const tensor_COO< Float > &tens, bool compare_cpu_and_device=false) const
Comparing tensors (A == tens)
size_t val_nnz
# of non-zero element
bool val_create_flag
matrix create flag;
Float & operator[](size_t i)
reference to the element at position (v[i])
void operator=(const tensor_COO< Float > &tens)
tensor copy
void set_shape(const std::vector< size_t > &shape)
Set shape.
tensor_COO(const tensor_COO< Float > &coo, Float value)
Initialize tensor_COO tensor of the same size as input tensor.
Float at(const std::vector< size_t > &pos)
get element A[pos[0]][pos[1]]... (onlu CPU)
bool gpu_status
true: sended, false: not send
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.
void fill(Float value)
fill tensor elements with a scalar value
void diag(view1D< matrix::Dense< Float >, Float > &vec) const
Float at(const std::vector< size_t > &pos) const
get element A[pos[0]][pos[1]]...
void diag(view1D< vector< Float >, Float > &vec) const
tensor_COO(const tensor::tensor_Dense< Float > &tens)
Create tensor_COO tensor from tensor_Dense tensor.
tensor_COO(const tensor_COO< Float > &coo)
Create tensor_COO tensor from tensor_COO tensor.
tensor_COO(const std::initializer_list< size_t > &shape_)
Initialize tensor_COO tensor.
void insert(const std::vector< size_t > &pos, const Float val)
insert element A[pos[0]][pos[1]]...
double get_data_size() const
Memory data space required by the matrix.
void min(const matrix::CRS< double > &A, const matrix::CRS< double > &B, matrix::CRS< double > &C)
Create a new CRS matrix with smallest elements of two matrices (C[0:nnz] = min(A[0:nnz],...