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

◆ to_M2_MutableMatrix() [2/2]

MutableMatrix * ResF4toM2Interface::to_M2_MutableMatrix ( SchreyerFrame & C,
const Ring * R,
int lev )
static

Definition at line 242 of file res-f4-m2-interface.cpp.

245{
246 // Ring will be R, which should be a polynomial ring with the same monoid as
247 // ring of C.
248 const PolynomialRing* RP = R->cast_to_PolynomialRing();
249 const Monoid* M = RP->getMonoid();
250
251 if (lev <= 0 or lev > C.maxLevel())
252 {
254 R,
255 0, // TODO: set this correctly?
256 0, // TODO: set this correctly? i.e. one of these might be in range,
257 // so getting the rank correct might be good.
258 true);
259 }
260
261 auto& thislevel = C.level(lev);
262 int ncols = static_cast<int>(thislevel.size());
263 int nrows = static_cast<int>(C.level(lev - 1).size());
264
265 // create the mutable matrix
266 MutableMatrix* result = MutableMatrix::zero_matrix(R, nrows, ncols, true);
267
268 // Nterm **comps = newarray(Nterm *, nrows);
269 Nterm** comps = newarray(Nterm*, nrows);
270 Nterm** last = newarray(Nterm*, nrows);
271
272 monomial m1 = M->make_one();
273 // FIXME: is exp a monomial or exponent vector?
274 int* exp = new int[M->n_vars() + 1];
275
276 int j = 0;
277 for (auto j1 = thislevel.cbegin(); j1 != thislevel.cend(); ++j1, ++j)
278 {
279 // Now we create the polynomials for column j
280 // into 'comps', 'last'.
281 const ResPolynomial& f = (*j1).mSyzygy;
282 for (int i = 0; i < nrows; i++)
283 {
284 comps[i] = nullptr;
285 last[i] = nullptr; // used to easily place monomials in the correct
286 // bin, at the end of the polynomials.
287 }
288 const res_monomial_word* w = f.monoms.data();
289 for (int i = 0; i < f.len; i++)
290 {
291 component_index comp;
292 C.ring().monoid().to_expvector(w, exp, comp);
293 w = w + C.ring().monoid().monomial_size(w);
294 M->from_expvector(exp, m1);
295 ring_elem a = C.vectorArithmetic().ringElemFromElementArray(f.coeffs, i);
296 Nterm* g = RP->make_flat_term(a, m1);
297 if (g == nullptr) continue;
298 g->next = nullptr;
299 if (last[comp] == nullptr)
300 {
301 comps[comp] = g;
302 last[comp] = g;
303 }
304 else
305 {
306 last[comp]->next = g;
307 last[comp] = g;
308 }
309 }
310 // Now we have run through the entire vector, so put it into result
311 for (int r = 0; r < nrows; r++) result->set_entry(r, j, comps[r]);
312 }
313
314 delete[] exp;
315 freemem(comps);
316 freemem(last);
317 return result;
318}
int n_vars() const
Definition monoid.hpp:207
monomial make_one() const
Definition monoid.cpp:455
void from_expvector(const_exponents exp, monomial result) const
Definition monoid.cpp:742
static MutableMatrix * zero_matrix(const Ring *R, size_t nrows, size_t ncols, bool dense)
Definition mat.cpp:54
virtual const Monoid * getMonoid() const
Definition polyring.hpp:282
virtual ring_elem make_flat_term(const ring_elem a, const_monomial m) const =0
bool to_expvector(res_const_packed_monomial m, res_ntuple_monomial result, component_index &result_comp) const
int monomial_size(res_const_packed_monomial m) const
const ResMonoid & monoid() const
std::vector< res_monomial_word > monoms
ElementArray coeffs
virtual const PolynomialRing * cast_to_PolynomialRing() const
Definition ring.hpp:243
std::vector< FrameElement > & level(int lev)
const ResPolyRing & ring() const
const VectorArithmetic & vectorArithmetic() const
ring_elem ringElemFromElementArray(const ElementArray &coeffs, int index) const
#define monomial
Definition gb-toric.cpp:11
void freemem(void *s)
Definition m2-mem.cpp:103
VALGRIND_MAKE_MEM_DEFINED & result(result)
const mpreal exp(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition mpreal.h:2298
#define newarray(T, len)
Definition newdelete.hpp:82
myword component_index
myword res_monomial_word
Nterm * next
Definition ringelem.hpp:157

References Ring::cast_to_PolynomialRing(), ResPolynomial::coeffs, freemem(), Monoid::from_expvector(), PolynomialRing::getMonoid(), ResPolynomial::len, SchreyerFrame::level(), PolynomialRing::make_flat_term(), Monoid::make_one(), SchreyerFrame::maxLevel(), ResPolyRing::monoid(), monomial, ResMonoidDense::monomial_size(), ResPolynomial::monoms, Monoid::n_vars(), newarray, Nterm::next, result(), SchreyerFrame::ring(), VectorArithmetic::ringElemFromElementArray(), ResMonoidDense::to_expvector(), SchreyerFrame::vectorArithmetic(), and MutableMatrix::zero_matrix().

Referenced by F4ResComputation::get_matrix(), F4ResComputation::get_mutable_matrix(), and F4ResComputation::get_mutable_matrix().