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)
79 [[nodiscard]]
T max()
const override {
81 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;
85 [[nodiscard]] Col<T>
diag()
const override {
86 Col<T> diag_vec(std::min(this->
n_rows, this->
n_cols), fill::none);
87 suanpan_for(0llu, diag_vec.n_elem, [&](
const uword I) { diag_vec(I) = this->operator()(I, I); });
96 if(
nullptr ==
M)
return;
97 if(!
M->triplet_mat.is_empty())
return this->
operator+=(
M->triplet_mat);
98 if(this->
n_rows !=
M->n_rows || this->n_cols !=
M->n_cols || this->n_elem !=
M->n_elem)
throw invalid_argument(
"size mismatch");
99 if(
nullptr ==
M->memptr())
return;
101 arrayops::inplace_plus(
memptr(),
M->memptr(), this->n_elem);
105 if(
nullptr ==
M)
return;
106 if(!
M->triplet_mat.is_empty())
return this->
operator-=(
M->triplet_mat);
107 if(this->
n_rows !=
M->n_rows || this->n_cols !=
M->n_cols || this->n_elem !=
M->n_elem)
throw invalid_argument(
"size mismatch");
108 if(
nullptr ==
M->memptr())
return;
110 arrayops::inplace_minus(
memptr(),
M->memptr(), this->n_elem);
114 if(this->
n_rows != M.
n_rows || this->n_cols !=
M.n_cols)
throw invalid_argument(
"size mismatch");
116 const auto row =
M.row_mem();
117 const auto col =
M.col_mem();
118 const auto val =
M.val_mem();
119 for(uword I = 0llu; I <
M.n_elem; ++I) this->
at(row[I], col[I]) += val[I];
123 if(this->
n_rows != M.
n_rows || this->n_cols !=
M.n_cols)
throw invalid_argument(
"size mismatch");
125 const auto row =
M.row_mem();
126 const auto col =
M.col_mem();
127 const auto val =
M.val_mem();
128 for(uword I = 0llu; I <
M.n_elem; ++I) this->
at(row[I], col[I]) -= val[I];
137 if(IterativeSolver::NONE != this->
setting.
iterative_solver)
throw invalid_argument(
"analysis requires the sign of determinant but iterative solver does not support it");
139 for(
unsigned I = 0; I <
pivot.n_elem; ++I)
if((this->
operator()(I, I) <
T(0)) ^ (
static_cast<int>(I) + 1 !=
pivot(I))) det_sign = -det_sign;
A DenseMat class that holds matrices.
Definition: DenseMat.hpp:39
podarray< float > to_float()
Definition: DenseMat.hpp:50
Col< T > diag() const override
Definition: DenseMat.hpp:85
void operator-=(const shared_ptr< MetaMat< T > > &M) override
Definition: DenseMat.hpp:104
const T * memptr() const override
Definition: DenseMat.hpp:91
podarray< int > pivot
Definition: DenseMat.hpp:45
podarray< float > s_memory
Definition: DenseMat.hpp:46
void zeros() override
Definition: DenseMat.hpp:74
DenseMat(const DenseMat &old_mat)
Definition: DenseMat.hpp:61
void operator-=(const triplet_form< T, uword > &M) override
Definition: DenseMat.hpp:122
void operator+=(const shared_ptr< MetaMat< T > > &M) override
Definition: DenseMat.hpp:95
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 operator*=(const T value) override
Definition: DenseMat.hpp:131
T max() const override
Definition: DenseMat.hpp:79
bool is_empty() const override
Definition: DenseMat.hpp:72
int sign_det() const override
Definition: DenseMat.hpp:136
DenseMat(DenseMat &&) noexcept=delete
T * memptr() override
Definition: DenseMat.hpp:93
int direct_solve(Mat< T > &X, const Mat< T > &B) override
Definition: DenseMat.hpp:43
void operator+=(const triplet_form< T, uword > &M) override
Definition: DenseMat.hpp:113
IterativeSolver iterative_solver
Definition: SolverSetting.hpp:46
void suanpan_for(const IT start, const IT end, F &&FN)
Definition: utility.h:27