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

◆ IM2_Matrix_get_entries()

engine_RawRingElementArrayArrayOrNull IM2_Matrix_get_entries ( const Matrix * M)

Definition at line 85 of file matrix.cpp.

86{
87 try
88 {
89 int ncols = M->n_cols();
90 int nrows = M->n_rows();
91 if(nrows < 0 || ncols < 0)
92 {
93 ERROR("internal error: matrix has a negative size %d by %d",
94 nrows,
95 ncols);
96 return nullptr;
97 }
98 engine_RawRingElementArrayArray entries =
99 getmemarraytype(engine_RawRingElementArrayArray, nrows);
100 entries->len = nrows;
103 for(int r = 0; r < nrows; r++)
104 {
105 engine_RawRingElementArray currRow =
106 getmemarraytype(engine_RawRingElementArray, ncols);
107 currRow->len = ncols;
108 std::fill_n(currRow->array, ncols, zero);
109 entries->array[r] = currRow;
110 }
111 //walk through the columns
112 for(int c = 0; c < ncols; c++)
113 {
114 const vec &column = M->elem(c);
115 for(const vecterm &term : column)
116 {
117 if(term.comp < 0 || term.comp >= nrows)
118 {
119 ERROR("internal error: matrix contains invalid entries:"
120 "row index %d out of range 0 .. %d",
121 term.comp,
122 nrows - 1);
123 //Ignoring the entry and continuing
124 continue;
125 }
126 entries->array[term.comp]->array[c] =
127 RingElement::make_raw(M->get_ring(), term.coeff);
128 }
129 }
130 return entries;
131 } catch (const exc::engine_error &e)
132 {
133 ERROR(e.what());
134 return nullptr;
135 }
136 return nullptr;
137}
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
int n_rows() const
Definition matrix.hpp:146
ring_elem zero() const
Definition ring.hpp:359
static RingElement * make_raw(const Ring *R, ring_elem f)
Definition relem.cpp:20
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Definition relem.hpp:67
int zero
const int ERROR
Definition m2-mem.cpp:55
#define getmemarraytype(S, len)
Definition m2-mem.h:142

References Matrix::elem(), ERROR, Matrix::get_ring(), getmemarraytype, RingElement::make_raw(), Matrix, Matrix::n_cols(), Matrix::n_rows(), Ring::zero(), and zero.