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

◆ IM2_Matrix_direct_sum()

const Matrix * IM2_Matrix_direct_sum ( const engine_RawMatrixArray Ms)

Definition at line 369 of file matrix.cpp.

371{
372 try
373 {
374 // Check that the matrices all have the same ring, and that there is
375 // at least one matrix.
376 unsigned int n = Ms->len;
377 if (n == 0)
378 {
379 ERROR("matrix direct sum: expects at least one matrix");
380 return nullptr;
381 }
382 const Matrix *result = Ms->array[0];
383 const Ring *R = result->get_ring();
384 for (unsigned int i = 1; i < n; i++)
385 if (R != Ms->array[i]->get_ring())
386 {
387 ERROR("matrix direct sum: different base rings");
388 return nullptr;
389 }
390 for (unsigned int i = 1; i < n; i++)
391 result = result->direct_sum(Ms->array[i]);
392
393 return result;
394 } catch (const exc::engine_error& e)
395 {
396 ERROR(e.what());
397 return nullptr;
398 }
399}
xxx xxx xxx
Definition ring.hpp:102
#define Matrix
Definition factory.cpp:14
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)

References ERROR, Matrix, and result().