41 [[nodiscard]]
bool is_empty()
const override;
42 void zeros()
override;
44 void unify(uword)
override;
47 [[nodiscard]]
T max()
const override;
48 [[nodiscard]] Col<T>
diag()
const override;
51 T&
at(uword, uword)
override;
53 [[nodiscard]]
const T*
memptr()
const override;
62 Mat<T>
operator*(
const Mat<T>&)
const override;
66 [[nodiscard]]
int sign_det()
const override;
81 this->factored =
false;
86 triplet_mat.at(idx, idx) = 1.;
90 using index_t =
typename decltype(triplet_mat)::index_type;
92 const auto t_idx =
static_cast<index_t
>(idx);
94 suanpan_for(
static_cast<index_t
>(0), triplet_mat.n_elem, [&](
const index_t I) { if(triplet_mat.row(I) == t_idx || triplet_mat.col(I) == t_idx) triplet_mat.val_mem()[I] = 0.; });
96 this->factored =
false;
104 using index_t =
typename decltype(triplet_mat)::index_type;
105 return triplet_mat(
static_cast<index_t
>(in_row),
static_cast<index_t
>(in_col));
109 this->factored =
false;
110 using index_t =
typename decltype(triplet_mat)::index_type;
111 return triplet_mat.at(
static_cast<index_t
>(in_row),
static_cast<index_t
>(in_col));
119 if(
nullptr == in_mat)
return;
121 if(!in_mat->triplet_mat.is_empty())
return this->
operator+=(in_mat->triplet_mat);
123 for(uword I = 0llu; I < in_mat->n_rows; ++I)
for(uword J = 0llu; J < in_mat->n_cols; ++J)
if(
const auto t_val = in_mat->operator()(I, J); !
suanpan::approx_equal(0., t_val)) at(I, J) = t_val;
127 if(
nullptr == in_mat)
return;
129 if(!in_mat->triplet_mat.is_empty())
return this->
operator-=(in_mat->triplet_mat);
131 for(uword I = 0llu; I < in_mat->n_rows; ++I)
for(uword J = 0llu; J < in_mat->n_cols; ++J)
if(
const auto t_val = in_mat->operator()(I, J); !
suanpan::approx_equal(0., t_val)) at(I, J) = -t_val;
135 this->triplet_mat += in_mat;
136 this->factored =
false;
140 this->triplet_mat -= in_mat;
141 this->factored =
false;
A SparseMat class that holds matrices.
Definition: SparseMat.hpp:34
std::enable_if_t<!std::numeric_limits< T >::is_integer, bool > approx_equal(T x, T y, int ulp=2)
Definition: utility.h:58
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