52 DenseMat& operator=(DenseMat&&) noexcept;
55 [[nodiscard]]
bool is_empty() const override;
56 void zeros() override;
58 T max() const override;
60 const
T*
memptr() const override;
63 void operator+=(const shared_ptr<
MetaMat<
T>>&) override;
64 void operator-=(const shared_ptr<
MetaMat<
T>>&) override;
69 void operator*=(T) override;
71 [[nodiscard]]
int sign_det() const override;
74 template<
sp_d T>
void DenseMat<T>::init() {
75 if(
nullptr != memory) memory::release(access::rw(memory));
76 access::rw(memory) =
is_empty() ? nullptr : memory::acquire<T>(this->
n_elem);
80 podarray<float> f_memory(this->
n_elem);
82 suanpan_for(0llu, this->
n_elem, [&](
const uword I) { f_memory(I) =
static_cast<float>(memory[I]); });
88 :
MetaMat<T>(in_rows, in_cols, in_elem) {
95 , pivot(old_mat.pivot)
96 , s_memory(old_mat.s_memory) {
103 ,
pivot(std::move(old_mat.pivot))
104 ,
s_memory(std::move(old_mat.s_memory)) {
105 access::rw(memory) = old_mat.memory;
106 access::rw(old_mat.memory) =
nullptr;
110 if(
this == &old_mat)
return *
this;
112 pivot = old_mat.
pivot;
120 if(
this == &old_mat)
return *
this;
122 pivot = std::move(old_mat.pivot);
123 s_memory = std::move(old_mat.s_memory);
124 access::rw(memory) = old_mat.memory;
125 access::rw(old_mat.memory) =
nullptr;
145 if(
nullptr ==
M)
return;
146 if(!
M->triplet_mat.is_empty())
return this->
operator+=(
M->triplet_mat);
147 if(this->
n_rows !=
M->n_rows || this->n_cols !=
M->n_cols || this->n_elem !=
M->n_elem)
return;
148 if(
nullptr ==
M->memptr())
return;
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_minus(
memptr(),
M->memptr(), this->
n_elem);
168 for(uword I = 0llu; I < M.
n_elem; ++I) this->
at(row[I], col[I]) += val[I];
177 for(uword I = 0llu; I < M.
n_elem; ++I) this->
at(row[I], col[I]) -= val[I];
184 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;
const T *const memory
Definition: DenseMat.hpp:43
A DenseMat class that holds matrices.
Definition: DenseMat.hpp:34
podarray< float > s_memory
Definition: DenseMat.hpp:39
podarray< int > pivot
Definition: DenseMat.hpp:38
void suanpan_for(const IT start, const IT end, F &&FN)
Definition: utility.h:24
concept sp_d
Definition: suanPan.h:231