55 [[nodiscard]]
bool is_empty() const override;
56 void zeros() override;
58 [[nodiscard]]
T max() const override;
59 [[nodiscard]] Col<
T>
diag() const override;
61 const
T*
memptr() const override;
64 void operator+=(const shared_ptr<
MetaMat<
T>>&) override;
65 void operator-=(const shared_ptr<
MetaMat<
T>>&) override;
70 void operator*=(
T) override;
72 [[nodiscard]]
int sign_det() const override;
76 if(
nullptr !=
memory) memory::release(access::rw(
memory));
81 podarray<float> f_memory(this->
n_elem);
89 :
MetaMat<
T>(in_rows, in_cols, in_elem) {
96 , pivot(old_mat.pivot)
97 , s_memory(old_mat.s_memory) {
104 , pivot(std::move(old_mat.pivot))
105 , s_memory(std::move(old_mat.s_memory)) {
106 access::rw(memory) = old_mat.memory;
107 access::rw(old_mat.memory) =
nullptr;
111 if(
this == &old_mat)
return *
this;
113 pivot = old_mat.
pivot;
121 if(
this == &old_mat)
return *
this;
123 pivot = std::move(old_mat.pivot);
124 s_memory = std::move(old_mat.s_memory);
125 access::rw(memory) = old_mat.memory;
126 access::rw(old_mat.memory) =
nullptr;
135 arrayops::fill_zeros(memptr(), this->n_elem);
136 this->factored =
false;
139 template<sp_d T>
T DenseMat<T>::max()
const {
return op_max::direct_max(memptr(), this->n_elem); }
142 Col<T> diag_vec(std::min(this->n_rows, this->n_cols), fill::none);
144 suanpan_for(0llu, diag_vec.n_elem, [&](
const uword I) { diag_vec(I) = this->operator()(I, I); });
154 if(
nullptr ==
M)
return;
155 if(!
M->triplet_mat.is_empty())
return this->
operator+=(
M->triplet_mat);
156 if(this->n_rows !=
M->n_rows || this->n_cols !=
M->n_cols || this->n_elem !=
M->n_elem)
return;
157 if(
nullptr ==
M->memptr())
return;
158 arrayops::inplace_plus(memptr(),
M->memptr(), this->n_elem);
159 this->factored =
false;
163 if(
nullptr ==
M)
return;
164 if(!
M->triplet_mat.is_empty())
return this->
operator-=(
M->triplet_mat);
165 if(this->n_rows !=
M->n_rows || this->n_cols !=
M->n_cols || this->n_elem !=
M->n_elem)
return;
166 if(
nullptr ==
M->memptr())
return;
167 arrayops::inplace_minus(memptr(),
M->memptr(), this->n_elem);
168 this->factored =
false;
172 if(this->n_rows !=
M.n_rows || this->n_cols !=
M.n_cols)
return;
174 const auto row =
M.row_mem();
175 const auto col =
M.col_mem();
176 const auto val =
M.val_mem();
177 for(uword I = 0llu; I <
M.n_elem; ++I) this->at(row[I], col[I]) += val[I];
181 if(this->n_rows !=
M.n_rows || this->n_cols !=
M.n_cols)
return;
183 const auto row =
M.row_mem();
184 const auto col =
M.col_mem();
185 const auto val =
M.val_mem();
186 for(uword I = 0llu; I <
M.n_elem; ++I) this->at(row[I], col[I]) -= val[I];
192 if(
IterativeSolver::NONE != this->setting.iterative_solver)
throw invalid_argument(
"analysis requires the sign of determinant but iterative solver does not support it");
194 for(
unsigned I = 0; I < pivot.n_elem; ++I)
if((this->
operator()(I, I) < 0.) ^ (
static_cast<int>(I) + 1 != pivot(I))) det_sign = -det_sign;
A DenseMat class that holds matrices.
Definition: DenseMat.hpp:34
podarray< int > pivot
Definition: DenseMat.hpp:38
podarray< float > s_memory
Definition: DenseMat.hpp:39
const T *const memory
Definition: DenseMat.hpp:43
const shared_ptr< MetaMat< T > > & operator+=(const shared_ptr< MetaMat< T >> &M, const shared_ptr< MetaMat< T >> &A)
Definition: operator_times.hpp:45
const shared_ptr< MetaMat< T > > & operator-=(const shared_ptr< MetaMat< T >> &M, const shared_ptr< MetaMat< T >> &A)
Definition: operator_times.hpp:86
concept sp_d
Definition: suanPan.h:227
void suanpan_for(const IT start, const IT end, F &&FN)
Definition: utility.h:24