7 template <
typename Float>
class vector;
8 template <
typename TYPE,
typename Float>
class view1D;
9 template <
typename TYPE,
typename Float>
class view_Dense;
10 template <
typename TYPE,
typename Float>
class view_tensor_Dense;
12 template <
typename Float>
class tensor_COO;
23 mutable std::shared_ptr<bool>
gpu_status = std::make_shared<bool>(
false);
34 std::shared_ptr<Float>
val;
182 const std::vector<Float> &value);
209 const Float
max,
const std::uint32_t seed);
279 const std::vector<Float> &value);
378 [[nodiscard]] std::string
type()
const {
return "tensor_Dense"; }
389 return get_nnz() *
sizeof(Float) / 1.0e+9;
401 [[nodiscard]] Float
at(
const size_t pos)
const;
412 [[nodiscard]] Float
at(
const std::vector<size_t> &pos)
const;
423 template <
typename... Args>
424 [[nodiscard]] Float
at(
const std::vector<size_t> &pos,
const size_t dim,
425 const Args... args)
const {
426 std::vector<size_t> pos_copy = pos;
427 pos_copy.push_back(dim);
428 return this->
at(pos_copy, args...);
440 template <
typename... Args>
441 #if !defined(__clang__) && defined(__GNUC__)
442 [[nodiscard]] Float
at(
const size_t dim,
const size_t dim2,
443 const Args... args)
const {
444 std::vector<size_t> pos(1);
446 return this->
at(pos, dim2, args...);
449 [[nodiscard]] Float
at(
const size_t dim,
const Args... args)
const {
450 std::vector<size_t> pos(1);
452 return this->
at(pos, args...);
465 [[nodiscard]] Float
at(
const size_t pos) {
478 [[nodiscard]] Float
at(
const std::vector<size_t> &pos) {
491 template <
typename... Args>
492 [[nodiscard]] Float
at(
const std::vector<size_t> &pos,
const Args... args) {
505 template <
typename... Args>
506 [[nodiscard]] Float
at(
const size_t dim,
const Args... args) {
519 void insert(
const size_t pos,
const Float Val);
530 void insert(
const std::vector<size_t> &pos,
const Float Val);
615 [[nodiscard]]
const Float *
data()
const {
return val.get(); }
623 [[nodiscard]] Float *
data() {
return val.get(); }
633 void resize(
const size_t N, Float Val = 0) {
635 throw std::runtime_error(
"Error, GPU matrix cant use resize");
638 std::shared_ptr<Float> tmp(
new Float[N], std::default_delete<Float[]>());
640 for (
size_t i = 0; i < copy_size; ++i) {
641 tmp.get()[i] =
data()[i];
643 for (
size_t i = copy_size; i < N; ++i) {
650 throw std::runtime_error(
"Error, not create vector cant use resize");
664 for (
auto n :
shape) {
707 [[nodiscard]]
const Float *
end()
const {
797 throw std::runtime_error(
"Error, GPU vector cant use operator[]");
813 bool compare_cpu_and_device =
false)
const;
850 size_t get_index(
const std::vector<size_t> &pos)
const {
851 if (pos.size() != this->shape.size()) {
852 throw std::runtime_error(
"pos size should be same with the shape");
855 for (
auto i = 0; i < pos.size(); ++i) {
856 ind *= this->shape[i];
872 std::vector<size_t> ind(this->shape.size(), 0);
874 for (
int i = (
int)this->shape.size() - 1; i >= 0; --i) {
875 ind[i] = pos_copy % this->shape[i];
876 pos_copy /= this->shape[i];
899 template <
typename... Args>
901 const Args... args) {
902 std::vector<int> shape_copy =
shape;
903 shape_copy.push_back(dim);
916 template <
typename... Args>
void reshape(
const int dim,
const Args... args) {
917 std::vector<int>
shape(1);
void reshape(const std::vector< int > &shape)
Reshape tensor.
bool equal(const tensor_Dense< Float > &tens, bool compare_cpu_and_device=false) const
Comparing tensors (A == tens)
void reshape(const std::vector< int > &shape, const size_t dim, const Args... args)
Reshape tensor.
std::vector< size_t > get_index(const size_t pos) const
get vector index from aligned index (A[pos[0]][pos[1]]... = A[ind])
std::string type() const
get format name "tensor_Dense"
void diag_mul(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix mul.
size_t get_index(const std::vector< size_t > &pos) const
get aligned index from vector index (A[pos] = A[ind[0]][ind[1]]...)
void convert(const matrix::Dense< Float > &dense)
create tensor_Dense tensor from Dense matrix
void diag_add(const view1D< matrix::Dense< Float >, Float > &vec)
tensor_Dense(const std::initializer_list< size_t > &shape)
Allocate dense tensor.
size_t get_first() const
get first position
bool operator!=(const tensor_Dense< Float > &tens) const
Comparing tensors (A != tens)
void diag_div(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
tensor_Dense(const view_tensor_Dense< vector< Float >, Float > &tens)
Create Dense matrix from view Dense matrix.
void operator=(const view_tensor_Dense< tensor::tensor_Dense< Float >, Float > &tens)
tensor copy
std::vector< size_t > shape
shape
tensor_Dense(const std::vector< size_t > &shape, const std::vector< Float > &value)
Allocate tensor_Dense tensor.
void set_ptr(const std::vector< size_t > &shape, const Float value)
Set tensor_Dense array from array.
std::shared_ptr< Float > val
Dense tensor format value (pointer)
Float at(const std::vector< size_t > &pos, const Args... args)
get element A[pos[0]][pos[1]]... (onlu CPU)
void insert(const size_t pos, const Float Val)
set element A[index]...
Float at(const std::vector< size_t > &pos)
get element A[pos[0]][pos[1]]... (onlu CPU)
void operator=(const view_tensor_Dense< matrix::Dense< Float >, Float > &tens)
tensor copy
void diag_add(const Float alpha)
Scalar and diag. vector of Dense format matrix add.
void insert(const std::vector< size_t > &pos, const Float Val)
set element A[pos[0]][pos[1]]...
void recv()
recv. data to GPU, and free data on GPU
void send() const
send data to GPU
void diag_sub(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
void diag_sub(const view1D< matrix::Dense< Float >, Float > &vec)
size_t val_nnz
# of non-zero element (M * N)
tensor_Dense(const matrix::Dense< Float > &dense)
Create tensor_Dense tensor from Dense matrix.
void diag_add(const view1D< vector< Float >, Float > &vec)
std::vector< size_t > get_shape() const
get shape
void diag_add(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
void print_all(bool force_cpu=false) const
print all elements to standard I/O
void diag_sub(const view1D< vector< Float >, Float > &vec)
size_t alloc_nnz
allocated tensor size
void resize(const std::vector< size_t > &shape, Float val=0)
resize tensor value
void fill(Float value)
fill tensor elements with a scalar value
Float at(const size_t dim, const Args... args) const
get element A[pos[0]][pos[1]]...
size_t first
first position of data array
std::shared_ptr< bool > gpu_status
true: sended, false: not send
tensor_Dense(const tensor::tensor_Dense< Float > &tens)
Create tensor_Dense tensor from tensor_Dense tensor.
Float at(const std::vector< size_t > &pos) const
get element A[pos[0]][pos[1]]...
void move(const matrix::Dense< Float > &dense)
move tensor_Dense tensor from Dense matrix
Float * end()
returns a end iterator
void diag_div(const view1D< matrix::Dense< Float >, Float > &vec)
void diag_add(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix add.
Float * data()
returns a direct pointer to the tensor
void diag_mul(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
void nonfree_recv()
recv. data to GPU (w/o free)
void diag_mul(const view1D< matrix::Dense< Float >, Float > &vec)
const Float * data() const
returns a direct pointer to the tensor
Float at(const size_t pos)
get element A[index]... (onlu CPU)
Float at(const std::vector< size_t > &pos, const size_t dim, const Args... args) const
get element A[pos[0]][pos[1]]...
void set_shape(const std::vector< size_t > &shape)
Set shape.
tensor_Dense(const std::vector< size_t > &shape, const Float min, const Float max)
Allocate tensor_Dense tensor.
const Float * end() const
returns a end iterator
bool val_create_flag
tensor create flag
void diag_div(const Float alpha)
Scalar and diag. vector of Dense format matrix div.
void set_first(size_t i)
Set # of non-zero elements.
size_t get_alloc_nnz() const
get # of alloced non-zeros
void move(const vector< Float > &vec)
move tensor_Dense tensor from vector
void convert(const tensor::tensor_COO< Float > &tens)
Create tensor_Dense tensor from tensor_COO tensor.
size_t get_nnz() const
get # of non-zeros
tensor_Dense(const std::vector< size_t > &shape, const Float min, const Float max, const std::uint32_t seed)
Allocate tensor_Dense tensor.
void diag_sub(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix sub.
tensor_Dense(const view_tensor_Dense< tensor::tensor_Dense< Float >, Float > &tens)
Create Dense matrix from view Dense matrix.
const Float * begin() const
returns a begin iterator
tensor_Dense(const std::vector< size_t > &shape, const Float *value)
Allocate dense tensor.
Float & operator[](size_t i)
reference to the element at position (v[i])
tensor_Dense(const view_tensor_Dense< matrix::Dense< Float >, Float > &tens)
Create Dense matrix from view Dense matrix.
void diag_sub(const Float alpha)
Scalar and diag. vector of Dense format matrix sub.
tensor_Dense(const tensor::tensor_COO< Float > &tens)
Create tensor_Dense tensor from tensor_COO tensor.
tensor_Dense(const vector< Float > &vec)
create tensor_Dense tensor from vector
void convert(const vector< Float > &vec)
create tensor_Dense tensor from vector
void set_ptr(const std::vector< size_t > &shape, const Float *value)
Set tensor_Dense array from array.
void operator=(const tensor_Dense< Float > &tens)
tensor copy
void device_free() const
free data on GPU
Float at(const size_t dim, const Args... args)
get element A[pos[0]][pos[1]]... (onlu CPU)
void set_ptr(const std::vector< size_t > &shape, const std::vector< Float > &value)
Set tensor_Dense array from std::vector.
void reshape(const int dim, const Args... args)
Reshape tensor.
Float * begin()
returns a begin iterator
Float at(const size_t pos) const
get element A[index]...
double get_data_size() const
Memory data space required by the matrix.
void resize(const size_t N, Float Val=0)
resize tensor value
~tensor_Dense()
destructor of dense tensor, free GPU memory
std::shared_ptr< bool > get_gpu_status() const
gpu status shared pointer
tensor_Dense(const tensor_Dense< Float > &tens, Float value)
Create tensor_Dense tensor of the same size as input tensor.
void diag_mul(const Float alpha)
Scalar and diag. vector of Dense format matrix mul.
void diag_div(const view1D< vector< Float >, Float > &vec)
void operator=(const view_tensor_Dense< vector< Float >, Float > &tens)
tensor copy
bool operator==(const tensor_Dense< Float > &tens) const
Comparing tensors (A == tens)
void diag_div(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix div.
bool get_device_mem_stat() const
true: sended, false: not send
size_t get_offset() const
get first position (same as get_first())
tensor_Dense(const std::vector< size_t > &shape)
Allocate dense tensor.
void diag_mul(const view1D< vector< Float >, Float > &vec)
void convert(const tensor::tensor_Dense< Float > &tens)
Create tensor_Dense tensor from tensor_Dense tensor.
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],...