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

◆ IM2_Matrix_concat()

const Matrix * IM2_Matrix_concat ( const engine_RawMatrixArray Ms)

Definition at line 328 of file matrix.cpp.

329{
330 try
331 {
332 unsigned int n = Ms->len;
333 if (n == 0)
334 {
335 ERROR("matrix concat: expects at least one matrix");
336 return nullptr;
337 }
338 const FreeModule *F = Ms->array[0]->rows();
339 const Ring *R = F->get_ring();
340 MatrixConstructor mat(Ms->array[0]->rows(), 0);
341 int next = 0;
342 for (unsigned int i = 0; i < n; i++)
343 {
344 const Matrix *M = Ms->array[i];
345 if (R != M->get_ring())
346 {
347 ERROR("matrix concat: different base rings");
348 return nullptr;
349 }
350 if (F->rank() != M->n_rows())
351 {
352 ERROR("matrix concat: row sizes are not equal");
353 return nullptr;
354 }
355 for (int j = 0; j < M->n_cols(); j++)
356 {
357 mat.append(R->copy_vec(M->elem(j)));
358 mat.set_column_degree(next++, M->cols()->degree(j));
359 }
360 }
361 return mat.to_matrix();
362 } catch (const exc::engine_error& e)
363 {
364 ERROR(e.what());
365 return nullptr;
366 }
367}
const Ring * get_ring() const
Definition freemod.hpp:102
const_monomial degree(int i) const
Definition freemod.hpp:104
int rank() const
Definition freemod.hpp:105
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
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
const FreeModule * cols() const
Definition matrix.hpp:145
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
vec copy_vec(const vecterm *v) const
Definition ring-vecs.cpp:91
xxx xxx xxx
Definition ring.hpp:102
#define Matrix
Definition factory.cpp:14
const int ERROR
Definition m2-mem.cpp:55

References MatrixConstructor::append(), Matrix::cols(), Ring::copy_vec(), FreeModule::degree(), Matrix::elem(), ERROR, FreeModule::get_ring(), Matrix::get_ring(), Matrix, Matrix::n_cols(), Matrix::n_rows(), FreeModule::rank(), MatrixConstructor::set_column_degree(), and MatrixConstructor::to_matrix().