7 template <
typename Float>
class vector;
8 template <
typename TYPE,
typename Float>
class view1D;
10 template <
typename Float>
class tensor_Dense;
11 template <
typename Float>
class tensor_COO;
16 mutable std::shared_ptr<bool>
gpu_status = std::make_shared<bool>(
false);
23 std::shared_ptr<Float>
val;
71 const std::vector<std::vector<int>> &row_ptrs_,
72 const std::vector<std::vector<int>> &col_inds_,
126 return get_nnz() *
sizeof(Float) / 1.0e+9;
130 const std::vector<std::vector<int>> &rowptrs,
131 const std::vector<std::vector<int>> &colinds,
132 const std::vector<Float> &value);
135 const std::vector<std::vector<int>> &rowptrs,
136 const std::vector<std::vector<int>> &colinds,
const size_t vsize,
140 const std::vector<std::vector<int>> &rowptrs,
141 const std::vector<std::vector<int>> &colinds,
const size_t vsize,
160 [[nodiscard]] std::shared_ptr<Float>
get_val() {
return val; }
169 [[nodiscard]]
const std::shared_ptr<Float>
get_val()
const {
return val; }
249 [[nodiscard]]
const Float *
data()
const {
return val.get(); }
257 [[nodiscard]] Float *
data() {
return val.get(); }
267 void resize(
const size_t N, Float Val = 0) {
269 for (
size_t i =
val_nnz; i < N; ++i) {
276 throw std::runtime_error(
"Error, GPU matrix cant use resize");
279 std::shared_ptr<Float> tmp(
new Float[N], std::default_delete<Float[]>());
281 for (
size_t i = 0; i < copy_size; ++i) {
282 tmp.get()[i] =
data()[i];
284 for (
size_t i = copy_size; i < N; ++i) {
292 throw std::runtime_error(
"Error, not create vector cant use resize");
303 [[nodiscard]] std::string
type()
const {
return "tensor_CRS"; }
343 [[nodiscard]]
const Float *
end()
const {
388 throw std::runtime_error(
"Error, GPU vector cant use operator[]");
404 bool compare_cpu_and_device =
false)
const;
Compressed Row Storage (CRS) format Matrix.
bool operator==(const tensor_CRS< Float > &mat) const
Comparing matrices (A == mat)
double get_data_size() const
Memory data space required by the matrix.
void device_free() const
free data on GPU
Float * data()
returns a direct pointer to the tensor
tensor_CRS(const tensor::tensor_COO< Float > &coo)
tensor_CRS(const tensor_CRS< Float > &crs, Float value)
const std::shared_ptr< Float > get_val() const
get shared_ptr of val
std::shared_ptr< bool > get_gpu_status() const
gpu status shared pointer
size_t get_first() const
get first position
void nonfree_recv()
recv. data to GPU (w/o free)
void operator=(const tensor_CRS< Float > &mat)
matrix copy
std::string type() const
get format name "tensor_CRS"
size_t get_nnz() const
get # of non-zeros
void compute_hash()
compute index array hash (to compare structure)
std::vector< size_t > get_shape() const
get shape
void set_ptr(const std::vector< size_t > &shape, const std::vector< std::vector< int >> &rowptrs, const std::vector< std::vector< int >> &colinds, const size_t vsize, const Float value)
void set_shape(const std::vector< size_t > &shape)
Set shape.
const Float * begin() const
returns a begin iterator
void convert(const matrix::CRS< Float > &crs)
bool get_device_mem_stat() const
true: sended, false: not send
bool equal(const tensor_CRS< Float > &mat, bool compare_cpu_and_device=false) const
Comparing matrices (A == mat)
std::shared_ptr< Float > val
void set_ptr(const std::vector< size_t > &shape, const std::vector< std::vector< int >> &rowptrs, const std::vector< std::vector< int >> &colinds, const std::vector< Float > &value)
void convert(const tensor::tensor_CRS< Float > &crs)
void fill(Float value)
fill tensor elements with a scalar value
tensor_CRS(const std::vector< size_t > &shape_, const std::vector< std::vector< int >> &row_ptrs_, const std::vector< std::vector< int >> &col_inds_, const Float *value)
void resize(const size_t N, Float Val=0)
resize tensor value
const Float * data() const
returns a direct pointer to the tensor
Float * begin()
returns a begin iterator
std::vector< std::vector< int > > row_ptrs
tensor_CRS(const matrix::CRS< Float > &crs)
Float & operator[](size_t i)
reference to the element at position (v[i])
void send() const
send data to GPU
std::vector< size_t > shape
void set_first(size_t i)
change first position
Float * end()
returns a end iterator
size_t get_alloc_nnz() const
get # of alloced non-zeros
void set_ptr(const std::vector< size_t > &shape, const std::vector< std::vector< int >> &rowptrs, const std::vector< std::vector< int >> &colinds, const size_t vsize, const Float *value)
size_t get_offset() const
get first position (same as get_first())
size_t get_hash() const
get index array hash (to compare structure)
const Float * end() const
returns a end iterator
tensor_CRS(const std::vector< size_t > &shape_)
bool operator!=(const tensor_CRS< Float > &mat) const
Comparing matrices (A != mat)
void convert(const tensor::tensor_COO< Float > &coo)
void print_all(bool force_cpu=false) const
std::shared_ptr< bool > gpu_status
void recv()
recv. data to GPU, and free data on GPU
tensor_CRS(const std::initializer_list< size_t > &shape_)
std::shared_ptr< Float > get_val()
get shared_ptr of val
tensor_CRS(const tensor::tensor_CRS< Float > &crs)
std::vector< std::vector< int > > col_inds
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],...