7 template <
typename Float>
class vector;
8 template <
typename TYPE,
typename Float>
class view1D;
10 template <
typename Float>
class tensor_COO;
27 std::shared_ptr<Float>
val;
165 const std::vector<Float> &value);
192 const Float
max,
const std::uint32_t seed);
219 const std::vector<Float> &value);
266 [[nodiscard]] std::string
type()
const {
return "tensor_Dense"; }
277 return get_nnz() *
sizeof(Float) / 1.0e+9;
289 [[nodiscard]] Float
at(
const std::vector<size_t> &pos)
const;
300 template <
typename... Args>
301 [[nodiscard]] Float
at(
const std::vector<size_t> &pos,
const size_t dim,
302 const Args... args)
const {
303 std::vector<size_t> pos_copy = pos;
304 pos_copy.push_back(dim);
305 return this->
at(pos_copy, args...);
317 template <
typename... Args>
318 [[nodiscard]] Float
at(
const size_t dim,
const Args... args)
const {
319 std::vector<size_t> pos(1);
321 return this->
at(pos, args...);
333 [[nodiscard]] Float
at(
const std::vector<size_t> &pos) {
346 template <
typename... Args>
347 [[nodiscard]] Float
at(
const std::vector<size_t> &pos,
const Args... args) {
360 template <
typename... Args>
361 [[nodiscard]] Float
at(
const size_t dim,
const Args... args) {
374 void insert(
const std::vector<size_t> &pos,
const Float Val);
451 [[nodiscard]]
const Float *
data()
const {
return val.get(); }
459 [[nodiscard]] Float *
data() {
return val.get(); }
469 void resize(
const size_t N, Float Val = 0) {
471 throw std::runtime_error(
"Error, GPU matrix cant use resize");
474 std::shared_ptr<Float> tmp(
new Float[N], std::default_delete<Float[]>());
476 for (
size_t i = 0; i < copy_size; ++i) {
477 tmp.get()[i] =
data()[i];
479 for (
size_t i = copy_size; i < N; ++i) {
486 throw std::runtime_error(
"Error, not create vector cant use resize");
500 for (
auto n :
shape) {
556 throw std::runtime_error(
"Error, GPU vector cant use operator[]");
572 bool compare_cpu_and_device =
false)
const;
609 size_t get_index(
const std::vector<size_t> &pos)
const {
610 if (pos.size() != this->shape.size()) {
611 throw std::runtime_error(
"pos size should be same with the shape");
614 for (
auto i = 0; i < pos.size(); ++i) {
615 ind *= this->shape[i];
631 std::vector<size_t> ind(this->shape.size(), 0);
633 for (
int i = (
int)this->shape.size() - 1; i >= 0; --i) {
634 ind[i] = pos_copy % this->shape[i];
635 pos_copy /= this->shape[i];
658 template <
typename... Args>
660 const Args... args) {
661 std::vector<int> shape_copy =
shape;
662 shape_copy.push_back(dim);
675 template <
typename... Args>
void reshape(
const int dim,
const Args... args) {
676 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)
bool operator!=(const tensor_Dense< Float > &tens) const
Comparing tensors (A != tens)
void diag_div(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
std::vector< size_t > shape
shape
tensor_Dense(const std::vector< size_t > &shape, const std::vector< Float > &value)
Allocate tensor_Dense tensor.
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)
Float at(const std::vector< size_t > &pos)
get element A[pos[0]][pos[1]]... (onlu CPU)
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]]...
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
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 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.
bool val_create_flag
tensor create flag
void diag_div(const Float alpha)
Scalar and diag. vector of Dense format matrix div.
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 std::vector< size_t > &shape, const Float *value)
Allocate dense tensor.
Float & operator[](size_t i)
reference to the element at position (v[i])
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.
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
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)
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
tensor_Dense(const std::vector< size_t > &shape)
Allocate dense tensor.
bool gpu_status
true: sended, false: not send
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],...