27 template <
typename Float>
class vector;
30 template <
typename Float>
class Dense;
31 template <
typename Float>
class CRS;
32 template <
typename Float>
class LinearOperator;
36 template <
typename Float>
class tensor_Dense;
72 const std::vector<size_t> &shape_)
92 const std::vector<size_t> &shape_)
112 const std::vector<size_t> &shape_)
132 const size_t start,
const std::vector<size_t> &shape_)
134 first = x.get_first() + start;
153 const size_t start,
const std::vector<size_t> &shape_)
155 first = x.get_first() + start;
174 const size_t start,
const std::vector<size_t> &shape_)
176 first = x.get_first() + start;
190 [[nodiscard]] std::string
type()
const {
191 return "view_tensor_Dense(" +
target.type() +
")";
222 for (
auto n :
shape) {
307 [[nodiscard]] Float
at(
const size_t pos)
const {
320 [[nodiscard]] Float
at(
const std::vector<size_t> &pos)
const {
333 template <
typename... Args>
334 [[nodiscard]] Float
at(
const std::vector<size_t> &pos,
const size_t dim,
335 const Args... args)
const {
336 std::vector<size_t> pos_copy = pos;
337 pos_copy.push_back(dim);
338 return this->
at(pos_copy, args...);
350 template <
typename... Args>
351 [[nodiscard]] Float
at(
const size_t dim,
const Args... args)
const {
352 std::vector<size_t> pos(1);
354 return this->
at(pos, args...);
366 [[nodiscard]] Float
at(
const size_t pos) {
379 [[nodiscard]] Float
at(
const std::vector<size_t> &pos) {
392 template <
typename... Args>
393 [[nodiscard]] Float
at(
const std::vector<size_t> &pos,
const Args... args) {
406 template <
typename... Args>
407 [[nodiscard]] Float
at(
const size_t dim,
const Args... args) {
420 void insert(
const size_t i,
const Float Val) {
434 void insert(
const std::vector<size_t> &pos,
const Float Val) {
448 return target.get_device_mem_stat();
456 return target.get_gpu_status();
544 void resize(std::vector<size_t> &shape_) {
628 if (
target.get_device_mem_stat()) {
629 throw std::runtime_error(
"Error, GPU vector cant use operator[]");
643 size_t get_index(
const std::vector<size_t> &pos)
const {
644 if (pos.size() != this->shape.size()) {
645 throw std::runtime_error(
"pos size should be same with the shape");
648 for (
auto i = 0; i < pos.size(); ++i) {
649 ind *= this->shape[i];
665 std::vector<size_t> ind(this->shape.size(), 0);
667 for (
int i = (
int)this->shape.size() - 1; i >= 0; --i) {
668 ind[i] = pos_copy % this->shape[i];
669 pos_copy /= this->shape[i];
const Float * data() const
returns a direct pointer to the matrix
const Float * data() const
returns a direct pointer to the tensor
const Float * data() const
returns a direct pointer to the vector
view_tensor_Dense(view_tensor_Dense< tensor::tensor_Dense< Float >, Float > &x, const size_t start, const std::vector< size_t > &shape_)
create view_tensor_Dense from monolish::tensor::tensor_Dense(start:start+range)
void diag_div(const view1D< vector< Float >, Float > &vec)
Float at(const std::vector< size_t > &pos, const Args... args)
get element A[pos[0]][pos[1]]... (onlu CPU)
TYPE & get_target()
returns a reference of the target
size_t get_device_mem_stat() const
true: sended, false: not send
size_t get_last() const
get end position
std::vector< size_t > shape
void diag_add(const view1D< vector< Float >, Float > &vec)
view_tensor_Dense(view_tensor_Dense< vector< Float >, Float > &x, const size_t start, const std::vector< size_t > &shape_)
create view_tensor_Dense from monolish::vector(start:start+range)
view_tensor_Dense(view_tensor_Dense< matrix::Dense< Float >, Float > &x, const size_t start, const std::vector< size_t > &shape_)
create view_tensor_Dense from monolish::matrix::Dense(start:start+range)
size_t get_offset() const
get first position (same as get_first())
void diag_div(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
void diag_sub(const view1D< matrix::Dense< Float >, Float > &vec)
std::shared_ptr< bool > get_gpu_status() const
gpu status shared pointer
void set_last(size_t i)
change last position
void diag_mul(const Float alpha)
Scalar and diag. vector of Dense format matrix mul.
Float * end() const
returns a end iterator
Float at(const std::vector< size_t > &pos) const
get element A[pos[0]][pos[1]]...
view_tensor_Dense(tensor::tensor_Dense< Float > &A, const size_t start, const std::vector< size_t > &shape_)
create view_tensor_Dense from Dense tensor(start:start+range)
void diag_mul(const view1D< matrix::Dense< Float >, Float > &vec)
void diag_div(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix div.
void operator=(const view_tensor_Dense< matrix::Dense< Float >, Float > &tens)
tensor copy
void diag_div(const view1D< matrix::Dense< Float >, Float > &vec)
void diag_add(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
void diag_add(const Float alpha)
Scalar and diag. vector of Dense format matrix add.
std::vector< size_t > get_shape() const
get shape
Float * begin() const
returns begin iterator (include offset)
view_tensor_Dense(matrix::Dense< Float > &A, const size_t start, const std::vector< size_t > &shape_)
create view_tensor_Dense from Dense matrix(start:start+range)
Float * begin()
returns begin iterator (include offset)
Float at(const size_t pos)
get element A[index] (only CPU)
void diag_add(const view1D< matrix::Dense< Float >, Float > &vec)
void diag_mul(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
void set_first(size_t i)
change first position
void diag_sub(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix sub.
Float at(const size_t dim, const Args... args) const
get element A[pos[0]][pos[1]]...
void resize(std::vector< size_t > &shape_)
change last postion
Float * data()
returns a direct pointer to the vector (dont include offset)
size_t size() const
get view_tensor_Dense size (range)
size_t get_nnz() const
get view_tensor_Dense size (same as size())
void diag_sub(const view1D< vector< Float >, Float > &vec)
size_t get_alloc_nnz() const
void insert(const size_t i, const Float Val)
set element A[index]...
view_tensor_Dense(vector< Float > &x, const size_t start, const std::vector< size_t > &shape_)
create view_tensor_Dense from vector(start:start+range)
void operator=(const view_tensor_Dense< tensor::tensor_Dense< Float >, Float > &tens)
tensor copy
void diag_mul(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix mul.
TYPE & get_target() const
returns a reference of the target
std::string type() const
get format name "view_tensor_Dense"
size_t get_first() const
get first position
std::shared_ptr< Float > get_val() const
void print_all(bool force_cpu=false) const
print all elements to standart I/O
Float at(const size_t dim, const Args... args)
get element A[pos[0]][pos[1]]... (onlu CPU)
size_t get_index(const std::vector< size_t > &pos) const
get aligned index from vector index (A[pos] = A[ind[0]][ind[1]]...)
Float & operator[](const size_t i)
reference to the element at position
void send() const
send data to GPU
void diag_div(const Float alpha)
Scalar and diag. vector of Dense format matrix div.
void recv()
recv data from GPU, and free data on GPU
Float * end()
returns a end iterator
std::vector< size_t > get_index(const size_t pos) const
get vector index from aligned index (A[pos[0]][pos[1]]... = A[ind])
void fill(Float value)
fill vector elements with a scalar value
void operator=(const tensor::tensor_Dense< Float > &tens)
tensor copy
void diag_mul(const view1D< vector< Float >, Float > &vec)
Float at(const std::vector< size_t > &pos)
get element A[pos[0]][pos[1]]...
void operator=(const view_tensor_Dense< vector< Float >, Float > &tens)
tensor copy
Float at(const size_t pos) const
get element A[index]
void diag_sub(const view1D< tensor::tensor_Dense< Float >, Float > &vec)
size_t calc_range() const
calculate view_tensor_Dense size from shape
void diag_sub(const Float alpha)
Scalar and diag. vector of Dense format matrix sub.
void insert(const std::vector< size_t > &pos, const Float Val)
set element A[pos[0]][pos[1]]...
Float * data() const
returns a direct pointer to the original vector (dont include offset)
Float at(const std::vector< size_t > &pos, const size_t dim, const Args... args) const
get element A[pos[0]][pos[1]]...
void diag_add(const vector< Float > &vec)
Vector and diag. vector of Dense format matrix add.