Macaulay2 Engine
Loading...
Searching...
No Matches

◆ step()

int DetComputation::step ( )

Definition at line 190 of file det.cpp.

193{
194 if (done) return COMP_DONE;
195
196 ring_elem r;
197
198 if (strategy == DET_BAREISS)
199 {
201 r = bareiss_det();
202 }
203 else if (strategy == DET_DYNAMIC)
204 {
205 if (dynamic_cache.empty())
206 { // Cache minors if needed
207 dynamic_cache.resize(p);
209 }
210 std::vector<int> row_vec(p), col_vec(p);
211 for (int i = 0; i < p; ++i)
212 {
213 row_vec[i] = static_cast<int>(row_set[i]);
214 col_vec[i] = static_cast<int>(col_set[i]);
215 }
216 // Find row number
217 const Subdeterminant &map = dynamic_cache[p - 1][row_lookup[row_vec[0]]];
218 auto it = map.find({row_vec, col_vec});
219 if (it != map.end()) { r = it->second; }
220 else { r = ZERO_RINGELEM; }
221 }
222 else
223 r = calc_det(row_set, col_set, p);
224
225 if (!R->is_zero(r))
226 {
227 if (do_exterior)
228 result.set_entry(this_row, this_col, r);
229 else
230 result.append(R->make_vec(0, r));
231 }
232 else
233 R->remove(r);
234
235 this_row++;
236 if (!Subsets::increment(M->n_rows(), p, row_set))
237 {
238 // Now we increment column
239 if (!Subsets::increment(M->n_cols(), p, col_set))
240 {
241 done = true;
242 return COMP_DONE;
243 }
244 // Now set the row set back to initial value
245 this_col++;
246 this_row = 0;
247 for (size_t i = 0; i < p; i++) row_set[i] = i;
248 }
249 return COMP_COMPUTING;
250}
MinorsCache dynamic_cache
Definition det.hpp:99
const Ring * R
Definition det.hpp:56
size_t * row_set
Definition det.hpp:75
int make_dynamic_cache()
Definition det.cpp:94
std::map< ColRowIndices, ring_elem, std::less< ColRowIndices >, gc_allocator< std::pair< const ColRowIndices, ring_elem > > > Subdeterminant
Definition det.hpp:84
size_t * col_set
Definition det.hpp:76
ring_elem ** D
Definition det.hpp:80
MatrixConstructor result
Definition det.hpp:62
ring_elem bareiss_det()
Definition det.cpp:345
int strategy
Definition det.hpp:72
int this_col
Definition det.hpp:78
bool done
Definition det.hpp:66
bool do_exterior
Definition det.hpp:69
ring_elem calc_det(size_t *r, size_t *c, int p)
Definition det.cpp:387
void get_minor(size_t *r, size_t *c, int p, ring_elem **D)
Definition det.cpp:284
std::map< int, int > row_lookup
Definition det.hpp:100
int this_row
Definition det.hpp:77
const Matrix * M
Definition det.hpp:57
static bool increment(size_t n, Subset &s)
Definition comb.cpp:124
@ COMP_DONE
Definition computation.h:60
@ COMP_COMPUTING
Definition computation.h:71
@ COMP_INTERRUPTED
Definition computation.h:57
const int DET_BAREISS
Definition det.hpp:45
const int DET_DYNAMIC
Definition det.hpp:47
#define ZERO_RINGELEM
Definition ring.hpp:677

References bareiss_det(), calc_det(), col_set, COMP_COMPUTING, COMP_DONE, COMP_INTERRUPTED, D, DET_BAREISS, DET_DYNAMIC, do_exterior, done, dynamic_cache, get_minor(), Subsets::increment(), M, make_dynamic_cache(), p, R, result, row_lookup, row_set, strategy, this_col, this_row, and ZERO_RINGELEM.

Referenced by calc().