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

◆ NCCoefficientMatrix() [2/2]

Matrix * NCCoefficientMatrix ( ModuleMonomialSet & H,
const Matrix * M )

Definition at line 1639 of file matrix.cpp.

1640{
1641 const M2FreeAlgebraOrQuotient* Q = dynamic_cast<const M2FreeAlgebraOrQuotient*>(M->get_ring());
1642 if (Q == nullptr)
1643 {
1644 ERROR("expected NC polynomial algebra");
1645 return nullptr;
1646 }
1647
1648 // should not get here unless 'M' is a matrix over a M2FreeAlgebraOrQuotient
1649
1650 MatrixConstructor mat(Q->make_FreeModule(H.size()), M->cols());
1651 for (int c = 0; c < M->n_cols(); c++)
1652 {
1653 vec v = M->elem(c);
1654 for (; v != nullptr; v = v->next)
1655 {
1656 int comp = v->comp;
1657 auto f = Q->toPoly(v->coeff);
1658 for (auto i = f->cbegin(); i != f->cend(); ++i)
1659 {
1660 auto result = H.find(i.monom(), comp);
1661 if (result.second)
1662 {
1663 ring_elem cf = Q->from_coefficient(i.coeff());
1664 mat.set_entry(result.first, c, cf);
1665 }
1666 }
1667 }
1668 }
1669 return mat.to_matrix();
1670}
std::pair< int, bool > find(Monom m, int comp)
std::size_t size() const
virtual ring_elem from_coefficient(const ring_elem a) const =0
const Poly * toPoly(const ring_elem f) const
Abstract Ring subclass that lifts either a FreeAlgebra or a FreeAlgebraQuotient into the engine's Rin...
const Ring * get_ring() const
Definition matrix.hpp:134
ring_elem elem(int i, int j) const
Definition matrix.cpp:307
int n_cols() const
Definition matrix.hpp:147
const FreeModule * cols() const
Definition matrix.hpp:145
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
virtual FreeModule * make_FreeModule() const
Definition ring.cpp:53
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)

References Matrix::cols(), Matrix::elem(), ERROR, IntsSet< Configuration >::find(), M2FreeAlgebraOrQuotient::from_coefficient(), Matrix::get_ring(), Ring::make_FreeModule(), Matrix, Matrix::n_cols(), result(), MatrixConstructor::set_entry(), IntsSet< Configuration >::size(), MatrixConstructor::to_matrix(), and M2FreeAlgebraOrQuotient::toPoly().

Referenced by Matrix::coeffs().