8 template <
typename Float>
class vector;
9 template <
typename TYPE,
typename Float>
class view1D;
10 template <
typename TYPE,
typename Float>
class view_Dense;
11 template <
typename TYPE,
typename Float>
class view_tensor_Dense;
14 template <
typename Float>
class tensor_Dense;
30 template <
typename Float>
class Dense {
50 mutable std::shared_ptr<bool>
gpu_status = std::make_shared<bool>(
false);
61 std::shared_ptr<Float>
val;
193 Dense(
const size_t M,
const size_t N);
205 Dense(
const size_t M,
const size_t N,
const Float *value);
217 Dense(
const size_t M,
const size_t N,
const std::vector<Float> &value);
241 Dense(
const size_t M,
const size_t N,
242 const std::initializer_list<Float> &list);
256 Dense(
const size_t M,
const size_t N,
const Float
min,
const Float
max);
270 Dense(
const size_t M,
const size_t N,
const Float
min,
const Float
max,
271 const std::uint32_t seed);
283 Dense(
const size_t M,
const size_t N,
const Float value);
295 void set_ptr(
const size_t M,
const size_t N,
const std::vector<Float> &value);
307 void set_ptr(
const size_t M,
const size_t N,
const Float *value);
319 void set_ptr(
const size_t M,
const size_t N,
const Float value);
414 [[nodiscard]] std::string
type()
const {
return "Dense"; }
446 return get_nnz() *
sizeof(Float) / 1.0e+9;
458 [[nodiscard]] Float
at(
const size_t i)
const;
470 [[nodiscard]] Float
at(
const size_t i,
const size_t j)
const;
481 [[nodiscard]] Float
at(
const size_t i) {
482 return static_cast<const Dense *
>(
this)->
at(i);
495 [[nodiscard]] Float
at(
const size_t i,
const size_t j) {
496 return static_cast<const Dense *
>(
this)->
at(i, j);
508 void insert(
const size_t i,
const Float Val);
520 void insert(
const size_t i,
const size_t j,
const Float Val);
605 [[nodiscard]]
const Float *
data()
const {
return val.get(); }
613 [[nodiscard]] Float *
data() {
return val.get(); }
625 for (
size_t i =
val_nnz; i < N; ++i) {
632 throw std::runtime_error(
"Error, GPU matrix cant use resize");
635 std::shared_ptr<Float> tmp(
new Float[N], std::default_delete<Float[]>());
637 for (
size_t i = 0; i < copy_size; ++i) {
638 tmp.get()[i] =
data()[i];
640 for (
size_t i = copy_size; i < N; ++i) {
647 throw std::runtime_error(
"Error, not create vector cant use resize");
695 [[nodiscard]]
const Float *
end()
const {
830 throw std::runtime_error(
"Error, GPU vector cant use operator[]");
846 bool compare_cpu_and_device =
false)
const;
Coodinate (COO) format Matrix (need to sort)
void row(const size_t r, view1D< vector< Float >, Float > &vec) const
Float at(const size_t i, const size_t j) const
get element A[i][j]
Dense(const view_Dense< matrix::Dense< Float >, Float > &dense)
Create Dense matrix from view Dense matrix.
Float at(const size_t i, const size_t j)
get element A[i][j] (only CPU)
void row(const size_t r, view1D< matrix::Dense< Float >, Float > &vec) const
void move(const view_tensor_Dense< vector< Float >, Float > &tensor_dense, int rowN, int colN)
std::string type() const
get format name "Dense"
void move(const view_tensor_Dense< tensor::tensor_Dense< Float >, Float > &tensor_dense)
Dense(const Dense< Float > &dense, Float value)
Create Dense matrix of the same size as input matrix.
bool operator!=(const Dense< Float > &mat) const
Comparing matrices (A != mat)
void set_first(size_t i)
Set # of non-zero elements.
bool get_device_mem_stat() const
true: sended, false: not send
const Float * end() const
returns a end iterator
void print_all(bool force_cpu=false) const
print all elements to standard I/O
void col(const size_t c, view1D< vector< Float >, Float > &vec) const
std::shared_ptr< bool > get_gpu_status() const
gpu status shared pointer
size_t val_nnz
# of non-zero element (M * N)
void diag_add(const view1D< vector< Float >, Float > &vec)
void operator=(const view_Dense< matrix::Dense< Float >, Float > &mat)
matrix copy
void diag_mul(const view1D< matrix::Dense< Float >, Float > &vec)
void convert(const Dense< Float > &dense)
Create Dense matrix from Dense matrix.
void set_ptr(const size_t M, const size_t N, const Float *value)
Set Dense array from std::vector.
Float at(const size_t i)
get element A[i/col][icol] (only CPU)
Dense(const size_t M, const size_t N, const Float min, const Float max, const std::uint32_t seed)
Create random dense matrix from dense matrix.
Dense(const size_t M, const size_t N, const Float value)
Create construct dense matrix.
void insert(const size_t i, const Float Val)
set element A[i/col][jcol]
void diag(view1D< tensor::tensor_Dense< Float >, Float > &vec) const
Dense(const COO< Float > &coo)
Create dense matrix from COO matrix.
void reshape(const size_t row, const size_t col)
Reshape matrix.
Dense(const size_t M, const size_t N, const Float *value)
Create dense matrix from array.
void diag(vector< Float > &vec) const
get diag. vector
Dense(const size_t M, const size_t N, const vector< Float > &value)
Create dense matrix from monolish::vector.
std::shared_ptr< Float > val
Dense format value (pointer)
void diag_mul(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
const Float * data() const
returns a direct pointer to the matrix
size_t get_col() const
get # of col
~Dense()
destructor of Dense matrix, free GPU memory
size_t get_first() const
get first position
void move(const view_tensor_Dense< matrix::Dense< Float >, Float > &tensor_dense)
void diag_mul(const view1D< vector< Float >, Float > &vec)
void transpose()
get transposed matrix (A = A^T)
bool operator==(const Dense< Float > &mat) const
Comparing matrices (A == mat)
void set_ptr(const size_t M, const size_t N, const std::vector< Float > &value)
Set Dense array from std::vector.
Float * end()
returns a end iterator
void col(const size_t c, view1D< matrix::Dense< Float >, Float > &vec) const
void diag_sub(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix sub.
Dense(const size_t M, const size_t N)
Allocate dense matrix.
void set_ptr(const size_t M, const size_t N, const Float value)
Set Dense array from std::vector.
void move(const view_tensor_Dense< matrix::Dense< Float >, Float > &tensor_dense, int rowN, int colN)
std::shared_ptr< bool > gpu_status
# of non-zero element (M * N)
void diag_add(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
void diag_div(const view1D< matrix::Dense< Float >, Float > &vec)
void move(const view_tensor_Dense< tensor::tensor_Dense< Float >, Float > &tensor_dense, int rowN, int colN)
void diag(view1D< vector< Float >, Float > &vec) const
bool equal(const Dense< Float > &mat, bool compare_cpu_and_device=false) const
Comparing matrices (A == mat)
size_t get_row() const
get # of row
void recv()
recv. data to GPU, and free data on GPU
void resize(size_t N, Float Val=0)
resize matrix value
const Float * begin() const
returns a begin iterator
void fill(Float value)
fill matrix elements with a scalar value
void transpose(const Dense &B)
create transposed matrix from Dense format matrix (A = B^T)
void diag_add(const Float alpha)
Scalar and diag. vector of Dense format matrix add.
void diag_add(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix add.
void row(const size_t r, vector< Float > &vec) const
get row vector
double get_data_size() const
Memory data space required by the matrix.
Float at(const size_t i) const
get element A[i/col][jcol]
void diag_sub(const view1D< matrix::Dense< Float >, Float > &vec)
size_t get_nnz() const
get # of non-zeros
void move(const view_tensor_Dense< vector< Float >, Float > &tensor_dense)
void device_free() const
free data on GPU
Dense(const Dense< Float > &dense)
Create Dense matrix from Dense matrix.
void diag_sub(const view1D< vector< Float >, Float > &vec)
Dense(const size_t M, const size_t N, const std::initializer_list< Float > &list)
Create dense matrix from std::initializer_list.
void diag_div(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
void diag_sub(const Float alpha)
Scalar and diag. vector of Dense format matrix sub.
Float & operator[](size_t i)
reference to the element at position (v[i])
void diag_div(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix div.
void move(const tensor::tensor_Dense< Float > &tensor_dense)
void col(const size_t c, vector< Float > &vec) const
get column vector
bool val_create_flag
matrix create flag;
size_t alloc_nnz
alloced matrix size
Dense(const view_Dense< tensor::tensor_Dense< Float >, Float > &dense)
Create Dense matrix from view Dense matrix.
size_t get_offset() const
get first position (same as get_first())
Float * data()
returns a direct pointer to the matrix
void col(const size_t c, view1D< tensor::tensor_Dense< Float >, Float > &vec) const
void diag_sub(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
void operator=(const Dense< Float > &mat)
matrix copy
void row(const size_t r, view1D< tensor::tensor_Dense< Float >, Float > &vec) const
void set_col(const size_t M)
Set column number.
size_t get_alloc_nnz() const
get # of alloced non-zeros
void move(const tensor::tensor_Dense< Float > &tensor_dense, int rowN, int colN)
void diag_div(const view1D< vector< Float >, Float > &vec)
void diag(view1D< matrix::Dense< Float >, Float > &vec) const
void diag_mul(const Float alpha)
Scalar and diag. vector of Dense format matrix mul.
void insert(const size_t i, const size_t j, const Float Val)
set element A[i][j]
void convert(const COO< Float > &coo)
Create Dense matrix from COO matrix.
void set_row(const size_t N)
Set row number.
Dense(const view_Dense< vector< Float >, Float > &dense)
Create Dense matrix from view Dense matrix.
void diag_mul(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix mul.
void diag_add(const view1D< matrix::Dense< Float >, Float > &vec)
Dense(const size_t M, const size_t N, const std::vector< Float > &value)
Create dense matrix from std::vector.
void operator=(const view_Dense< tensor::tensor_Dense< Float >, Float > &mat)
matrix copy
Dense(const size_t M, const size_t N, const Float min, const Float max)
Create random dense matrix from dense matrix.
void send() const
send data to GPU
void nonfree_recv()
recv. data to GPU (w/o free)
Float * begin()
returns a begin iterator
void diag_div(const Float alpha)
Scalar and diag. vector of Dense format matrix div.
size_t first
first position of data array
void operator=(const view_Dense< vector< Float >, Float > &mat)
matrix copy
void max(const matrix::CRS< double > &A, const matrix::CRS< double > &B, matrix::CRS< double > &C)
Create a new CRS matrix with greatest elements of two matrices (C[0:nnz] = max(A[0:nnz],...
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],...