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

◆ make_sparse_vecs()

bool Matrix::make_sparse_vecs ( MatrixConstructor & mat,
const FreeModule * target,
int ncols,
M2_arrayint rows,
M2_arrayint cols,
const engine_RawRingElementArray entries )
staticprivate

Definition at line 143 of file matrix.cpp.

151{
152 const Ring *R = target->get_ring();
153 for (unsigned int i = 0; i < entries->len; i++)
154 {
155 if (R != entries->array[i]->get_ring())
156 {
157 ERROR("expected vectors in the same ring");
158 return false;
159 }
160 }
161 if (rows->len != cols->len || rows->len != entries->len)
162 {
163 ERROR("sparse matrix creation: encountered different length arrays");
164 return false;
165 }
166 for (int x = 0; x < entries->len; x++)
167 {
168 int r = rows->array[x];
169 int c = cols->array[x];
170 if (r < 0 || r >= target->rank())
171 {
172 ERROR("sparse matrix creation: row index out of range");
173 return false;
174 }
175 if (c < 0 || c >= ncols)
176 {
177 ERROR("sparse matrix creation: column index out of range");
178 return false;
179 }
180 }
181
182 for (int x = 0; x < entries->len; x++)
183 {
184 int r = rows->array[x];
185 int c = cols->array[x];
186 mat.set_entry(r, c, entries->array[x]->get_value());
187 }
188 return true;
189}
const Ring * get_ring() const
Definition freemod.hpp:102
int rank() const
Definition freemod.hpp:105
void set_entry(int r, int c, ring_elem a)
const int ERROR
Definition m2-mem.cpp:55
volatile int x

References cols(), ERROR, FreeModule, FreeModule::get_ring(), make_sparse_vecs(), MatrixConstructor, FreeModule::rank(), rows(), MatrixConstructor::set_entry(), and x.

Referenced by make_sparse(), make_sparse(), make_sparse_vecs(), and MatrixConstructor.