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

◆ toMatrix() [1/2]

template<typename CoeffRing>
Matrix * toMatrix ( const Ring * R,
const DMat< CoeffRing > & A )

Definition at line 168 of file mutablemat-defs.hpp.

169{
170 int nrows = static_cast<int>(A.numRows());
171 int ncols = static_cast<int>(A.numColumns());
172 FreeModule* F = R->make_FreeModule(nrows);
173 MatrixConstructor result(F, ncols);
174 if (nrows == 0 || ncols == 0) return result.to_matrix();
175
176 for (int r = 0; r < nrows; ++r)
177 for (int c = 0; c < ncols; ++c)
178 {
179 const typename CoeffRing::ElementType & a = A.entry(r,c);
180 if (not A.ring().is_zero(a))
181 {
182 ring_elem ra;
183 A.ring().to_ring_elem(ra, a);
184 result.set_entry(r, c, ra);
185 }
186 }
187
188 result.compute_column_degrees();
189 return result.to_matrix();
190}
size_t numRows() const
Definition dmat.hpp:144
ElementType & entry(size_t row, size_t column)
Definition dmat.hpp:148
const ACoeffRing & ring() const
Definition dmat.hpp:143
size_t numColumns() const
Definition dmat.hpp:145
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
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
VALGRIND_MAKE_MEM_DEFINED & result(result)

References DMat< ACoeffRing >::entry(), Ring::make_FreeModule(), Matrix, DMat< ACoeffRing >::numColumns(), DMat< ACoeffRing >::numRows(), result(), and DMat< ACoeffRing >::ring().

Referenced by MutableMat< Mat >::to_matrix().