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;
141 const auto t_size = std::min(this->n_rows, this->n_cols);
142 for(uword I = 0; I < t_size; ++I)
if(
const auto t_val = this->
operator()(I, I); t_val > max_value) max_value = t_val;
147 Col<T> diag_vec(std::min(this->n_rows, this->n_cols), fill::none);
149 suanpan_for(0llu, diag_vec.n_elem, [&](
const uword I) { diag_vec(I) = this->operator()(I, I); });
159 if(
nullptr ==
M)
return;
160 if(!
M->triplet_mat.is_empty())
return this->
operator+=(
M->triplet_mat);
161 if(this->n_rows !=
M->n_rows || this->n_cols !=
M->n_cols || this->n_elem !=
M->n_elem)
return;
162 if(
nullptr ==
M->memptr())
return;
163 arrayops::inplace_plus(memptr(),
M->memptr(), this->n_elem);
164 this->factored =
false;
168 if(
nullptr ==
M)
return;
169 if(!
M->triplet_mat.is_empty())
return this->
operator-=(
M->triplet_mat);
170 if(this->n_rows !=
M->n_rows || this->n_cols !=
M->n_cols || this->n_elem !=
M->n_elem)
return;
171 if(
nullptr ==
M->memptr())
return;
172 arrayops::inplace_minus(memptr(),
M->memptr(), this->n_elem);
173 this->factored =
false;
177 if(this->n_rows !=
M.n_rows || this->n_cols !=
M.n_cols)
return;
179 const auto row =
M.row_mem();
180 const auto col =
M.col_mem();
181 const auto val =
M.val_mem();
182 for(uword I = 0llu; I <
M.n_elem; ++I) this->at(row[I], col[I]) += val[I];
186 if(this->n_rows !=
M.n_rows || this->n_cols !=
M.n_cols)
return;
188 const auto row =
M.row_mem();
189 const auto col =
M.col_mem();
190 const auto val =
M.val_mem();
191 for(uword I = 0llu; I <
M.n_elem; ++I) this->at(row[I], col[I]) -= val[I];
197 if(
IterativeSolver::NONE != this->setting.iterative_solver)
throw invalid_argument(
"analysis requires the sign of determinant but iterative solver does not support it");
199 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
Definition: suanPan.h:318
const shared_ptr< MetaMat< T > > & operator-=(const shared_ptr< MetaMat< T > > &M, const shared_ptr< MetaMat< T > > &A)
Definition: operator_times.hpp:91
const shared_ptr< MetaMat< T > > & operator+=(const shared_ptr< MetaMat< T > > &M, const shared_ptr< MetaMat< T > > &A)
Definition: operator_times.hpp:50
void suanpan_for(const IT start, const IT end, F &&FN)
Definition: utility.h:27