9 namespace implementation_details {
11 template<
typename T,
typename S>
12 struct Row_Column_Operation {
19 Row_Column_Operation() =
default;
20 Row_Column_Operation(T scalar, S start, S end) :scalar(scalar), start(start), end(end) {}
24 template<
typename scalar,
typename storage>
29 template<
typename T,
bool a,
bool b>
30 Pivot(IteratorNNZ<T, a, b> it) : value(it.value()), row(it.row()), col(it.col()) {}
34 template<
typename T,
bool partial_pivoting = SFINAE::is_finite_cyclic<scalar_t<T>>::value,
bool sparse = SFINAE::is_Sparse<T>::value>
35 struct smith_conditional_members;
38 struct smith_conditional_members<T, 0, 0> {
39 std::vector<int64_t> Cnorm;
40 std::vector<int64_t> Rnorm;
44 struct smith_conditional_members<T, 0, 1> {
45 std::vector<int64_t> Cnorm;
46 std::vector<int64_t> Rnorm;
48 Eigen::SparseMatrix<scalar_t<T>, 1, storage_t<T>> S_row;
49 std::vector<Row_Column_Operation<scalar_t<T>, storage_t<T>>> Pops, Qops;
53 struct smith_conditional_members<T, 1, 0> {
55 std::vector<int64_t> Cnorm;
59 struct smith_conditional_members<T, 1, 1> {
61 std::vector<Row_Column_Operation<scalar_t<T>, storage_t<T>>> Pops, Qops;
76 template <
typename _S,
typename _R,
typename _C>
94 SmithNormalForm(
const _S& S,
bool do_P = 1,
bool do_Q = 1,
bool do_sort = 1,
bool do_verify = 0);
98 void verify(
const _S&)
const;
103 typedef typename S_t::StorageIndex ind;
111 implementation_details::Pivot<scalar_t<S_t>, ind> piv;
115 static constexpr
bool C_exists = !partial_pivoting || !sparse;
116 static constexpr
bool R_exists = !partial_pivoting;
118 typedef std::conditional_t<sparse && !partial_pivoting, typename Eigen::SparseMatrix<scalar_t<S_t>, 1, ind>,
int*> S_row_t;
120 int64_t metric(ind i, ind j)
const;
123 void initialize_norms();
124 bool initial_pivoting_per_loop(ind start);
125 bool doneRow(ind start);
126 bool doneCol(ind start);
128 void eliminateRow(ind start);
129 void eliminateCol(ind start);
130 template<
bool row,
bool col,
char increase_decrease_zero,
typename iter>
131 void update_norms(iter it);
135 void row_pivot(ind start,
bool tail = 0);
136 void col_pivot(ind start,
bool tail = 0);
138 void update(
int = 0);
140 template<
bool onlyrow,
bool onlycolumn>
141 void find_and_set_pivot(ind start);
148 #include "impl/Smith.ipp"
Contains general template aliases.
decltype(test_finite_cyclic(std::declval< T >())) is_finite_cyclic
Detects if T=Z<N>
Definition: SFINAE.hpp:86
decltype(test_Sparse(std::declval< T * >())) is_Sparse
Detects if T is a sparse matrix.
Definition: SFINAE.hpp:78
Everything in this library is under this namespace.
Definition: Box.hpp:9
std::vector< T > tail(const T *const &ptr, int size, int start)
Given vector or array returns vector starting from index start.
Eigen::Matrix< scalar_t< T >, 1,-1 > row_vector_t
Dense row matrix.
Definition: Aliases.hpp:22
typename T::StorageIndex storage_t
Storage type of matrix.
Definition: Aliases.hpp:18