13 template <
class el_type>
16 int i, j, idx, offset;
19 this->pivotA(s, in_set, k, r);
27 for (idx_it it = L.
list[k].begin(); it != L.
list[k].end(); it++)
30 if (L.
m_idx[*it][i] == k) {
38 for (idx_it it = L.
list[r].begin(); it != L.
list[r].end(); it++) {
40 if (L.
m_idx[*it][i] == r) {
48 for (
typename vector<idx_it>::iterator it = s.
swapk.begin(); it != s.
swapk.end(); it++) {
51 for (
typename vector<idx_it>::iterator it = s.
swapr.begin(); it != s.
swapr.end(); it++) {
67 template <
class el_type>
72 std::pair<idx_it, elt_it> its_k, its_r;
73 int i, j, idx, offset;
86 for (idx_it it = list[k].begin(); it != list[k].begin() + row_first[k]; ++it) {
87 s.
row_r.push_back(*it);
91 for (idx_it it = list[r].begin(); it != list[r].begin() + row_first[r]; ++it) {
92 s.
row_k.push_back(*it);
96 s.
all_swaps.assign(list[k].begin(), list[k].begin() + row_first[k]);
97 unordered_inplace_union(s.
all_swaps, list[r].begin(), list[r].begin() + row_first[r], in_set);
101 safe_swap(m_idx[*it], k, r);
113 el_type elem = coeff(r, r);
114 if (abs(elem) > eps){
116 s.
col_k.push_back(elem);
121 if (abs(elem) > eps){
123 s.
col_r.push_back(elem);
128 for (i = row_first[r]; i < (int) list[r].size(); i++) {
131 if (coeffRef(r, j, its_k)) {
134 s.
row_r.push_back(k);
138 s.
col_k.push_back(*its_k.second);
141 *its_k.first = m_idx[j].back();
142 *its_k.second = m_x[j].back();
149 if (m_idx[r].size() > 0) {
153 ensure_invariant(r, r, m_idx[r],
false);
154 offset = (m_idx[r][0] == r ? 1 : 0);
155 std::copy(m_x[r].begin()+offset, m_x[r].end(), std::back_inserter(s.
col_k));
156 std::copy(m_idx[r].begin()+offset, m_idx[r].end(), std::back_inserter(s.
col_k_nnzs));
158 for (idx_it it = m_idx[r].begin() + offset; it != m_idx[r].end(); it++) {
162 for (i = row_first[*it]; i < (int) list[*it].size(); i++) {
163 if (list[*it][i] == r) {
164 s.
swapk.push_back(list[*it].begin() + i);
172 if (m_idx[k].size() > 0) {
175 ensure_invariant(k, k, m_idx[k],
false);
176 offset = (m_idx[k][0] == k ? 1 : 0);
177 for (i = offset; i < (int) m_idx[k].size(); i++) {
184 m_idx[idx].push_back(r);
185 m_x[idx].push_back(m_x[k][i]);
189 ensure_invariant(idx, k, list[idx],
true);
190 std::swap(list[idx][row_first[idx]], list[idx][list[idx].size() - 1]);
191 list[idx].pop_back();
194 s.
row_r.push_back(idx);
196 }
else if (idx > r) {
199 s.
col_r.push_back(m_x[k][i]);
204 for (j = row_first[idx]; j < (int) list[idx].size(); j++) {
205 if (list[idx][j] == k) {
206 s.
swapr.push_back(list[idx].begin() + j);
215 for (
typename vector<idx_it>::iterator it = s.
swapk.begin(); it != s.
swapk.end(); it++) {
218 for (
typename vector<idx_it>::iterator it = s.
swapr.begin(); it != s.
swapr.end(); it++) {
224 if ((*it > k) && (*it < r)) {
225 list[*it].push_back(k);
231 m_x[k].swap(s.
col_k);
235 m_x[r].swap(s.
col_r);
238 list[k].swap(s.
row_k);
239 list[r].swap(s.
row_r);
242 std::swap(row_first[k], row_first[r]);
void col_clear()
Clears all col vectors (col_k, col_r, col_k_nnzs, col_r_nnzs).
Definition: swap_struct.h:38
void swap_clear()
Clears all swap vectors (swapk, swapr, all_swaps).
Definition: swap_struct.h:30
vector< idx_it > swapk
List of indices from row r that will be swapped to row k.
Definition: swap_struct.h:15
idx_vector_type col_k_nnzs
Row indices of non-zeros in the new column k.
Definition: swap_struct.h:19
idx_vector_type all_swaps
Column indices of all swaps done in swapk and swapr.
Definition: swap_struct.h:18
vector< idx_vector_type > m_idx
The row/col indices. The way m_idx is used depends on whether the matrix is in LIL-C or LIL-R...
Definition: lil_sparse_matrix.h:35
void row_clear()
Clears all row vectors (row_k, row_r).
Definition: swap_struct.h:47
void pivotA(swap_struct< el_type > &s, vector< bool > &in_set, const int &k, const int &r)
The inplace version of the function above.
Definition: lilc_matrix_pivot.h:68
vector< idx_it > swapr
List of indices from row k that will be swapped to row r.
Definition: swap_struct.h:16
A list-of-lists (LIL) matrix in column oriented format.
Definition: lilc_matrix.h:9
idx_vector_type col_r_nnzs
Row indices of non-zeros in the new column r.
Definition: swap_struct.h:20
A structure containing variables used in pivoting a LIL-C matrix.
Definition: swap_struct.h:6
elt_vector_type col_r
Non-zero values in the new column r (order dependent on col_r_nnzs).
Definition: swap_struct.h:23
std::vector< int > col_first
On iteration k, first[i] gives the number of non-zero elements on col i of A before A(i...
Definition: lilc_matrix_declarations.h:47
void pivot(swap_struct< el_type > &s, vector< bool > &in_set, lilc_matrix< el_type > &L, const int &k, const int &r)
Performs a symmetric permutation between row/col k & r of A.
Definition: lilc_matrix_pivot.h:14
std::vector< std::vector< int > > list
A list of linked lists that gives the non-zero elements in each row of A. Since at any time we may sw...
Definition: lilc_matrix_declarations.h:44
idx_vector_type row_r
Column indices of non-zeros in the new row r.
Definition: swap_struct.h:26
idx_vector_type row_k
Column indices of non-zeros in the new row k.
Definition: swap_struct.h:25
elt_vector_type col_k
Non-zero values in the new column k (order dependent on col_k_nnzs).
Definition: swap_struct.h:22