34template<sp_d T> uword
round_up(
const uword in_size) {
35 constexpr auto multiple = 64llu /
sizeof(
T);
36 return (in_size + multiple - 1llu) / multiple * multiple;
48 std::unique_ptr<T[]>
memory =
nullptr;
51 podarray<float> f_memory(this->
n_elem);
57 DenseMat(
const uword in_rows,
const uword in_cols,
const uword in_elem)
58 :
MetaMat<
T>(in_rows, in_cols, in_elem)
60 if(in_elem > std::numeric_limits<la_it>::max())
throw std::runtime_error(
"matrix size exceeds limit, please enable 64-bit indexing");
82 [[nodiscard]]
T max()
const override {
84 for(uword I = 0; I < std::min(this->
n_rows, this->
n_cols); ++I)
if(
const auto t_val = this->
operator()(I, I); t_val > max_value) max_value = t_val;
93 if(
nullptr ==
M)
return;
94 if(!
M->triplet_mat.is_empty())
return this->
scale_accu(scalar,
M->triplet_mat);
95 if(this->
n_rows !=
M->n_rows || this->n_cols !=
M->n_cols || this->n_elem !=
M->n_elem)
throw invalid_argument(
"size mismatch");
96 if(
nullptr ==
M->memptr())
return;
98 if(1. == scalar) arrayops::inplace_plus(
memptr(),
M->memptr(), this->n_elem);
99 else if(-1. == scalar) arrayops::inplace_minus(
memptr(),
M->memptr(), this->n_elem);
104 if(this->
n_rows != M.
n_rows || this->n_cols !=
M.n_cols)
throw invalid_argument(
"size mismatch");
106 const auto row =
M.row_mem();
107 const auto col =
M.col_mem();
108 const auto val =
M.val_mem();
109 if(1. == scalar)
for(
auto I = 0llu; I <
M.n_elem; ++I) this->
at(row[I], col[I]) += val[I];
110 else if(-1. == scalar)
for(
auto I = 0llu; I <
M.n_elem; ++I) this->
at(row[I], col[I]) -= val[I];
111 else for(
auto I = 0llu; I <
M.n_elem; ++I) this->
at(row[I], col[I]) += scalar * val[I];
120#ifdef SUANPAN_DISTRIBUTED
121 comm_world.allreduce(mpl::plus<T>(),
memory.get(), mpl::contiguous_layout<T>{this->n_elem});
A DenseMat class that holds matrices.
Definition DenseMat.hpp:39
podarray< float > to_float()
Definition DenseMat.hpp:50
const T * memptr() const override
Definition DenseMat.hpp:88
podarray< float > s_memory
Definition DenseMat.hpp:46
podarray< blas_int > pivot
Definition DenseMat.hpp:45
void zeros() override
Definition DenseMat.hpp:77
DenseMat(const DenseMat &old_mat)
Definition DenseMat.hpp:64
DenseMat(const uword in_rows, const uword in_cols, const uword in_elem)
Definition DenseMat.hpp:57
std::unique_ptr< T[]> memory
Definition DenseMat.hpp:48
void scale_accu(const T scalar, const shared_ptr< MetaMat< T > > &M) override
Definition DenseMat.hpp:92
void operator*=(const T value) override
Definition DenseMat.hpp:114
T max() const override
Definition DenseMat.hpp:82
void scale_accu(const T scalar, const triplet_form< T, uword > &M) override
Definition DenseMat.hpp:103
bool is_empty() const override
Definition DenseMat.hpp:75
void allreduce() override
Definition DenseMat.hpp:119
DenseMat(DenseMat &&) noexcept=delete
T * memptr() override
Definition DenseMat.hpp:90
int direct_solve(Mat< T > &X, const Mat< T > &B) override
Definition DenseMat.hpp:43
void for_each(const IT start, const IT end, F &&FN)
Definition utility.h:28