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

◆ toMatrix() [2/2]

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

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

193{
194 int nrows = static_cast<int>(A.numRows());
195 int ncols = static_cast<int>(A.numColumns());
196 FreeModule* F = R->make_FreeModule(nrows);
197 MatrixConstructor result(F, ncols);
198 if (nrows == 0 || ncols == 0) return result.to_matrix();
199 ring_elem f;
200 auto i = A.begin();
201 for (int c = 0; c < ncols; c++)
202 {
203 ring_elem a;
204 for (i.set(c); i.valid(); i.next())
205 {
206 i.copy_elem(a);
207 int r = static_cast<int>(i.row());
208 result.set_entry(r, c, a);
209 }
210 }
211 result.compute_column_degrees();
212 return result.to_matrix();
213}
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
iterator begin() const
Definition smat.hpp:131
size_t numRows() const
Definition smat.hpp:99
size_t numColumns() const
Definition smat.hpp:100
VALGRIND_MAKE_MEM_DEFINED & result(result)

References SMat< ACoeffRing >::begin(), Ring::make_FreeModule(), Matrix, SMat< ACoeffRing >::numColumns(), SMat< ACoeffRing >::numRows(), and result().