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

◆ reshape()

Matrix * Matrix::reshape ( const FreeModule * G,
const FreeModule * H ) const

Definition at line 516 of file matrix.cpp.

520{
521 if (F->get_ring() != get_ring() || G->get_ring() != get_ring())
522 {
523 ERROR("reshape: expected same ring");
524 return nullptr;
525 }
526 if (n_rows() * n_cols() != F->rank() * G->rank())
527 {
528 ERROR("reshape: ranks of the free modules are incorrect");
529 return nullptr;
530 }
531
532 // EFFICIENCY: might be better to sort columns at end?
534 for (int c = 0; c < n_cols(); c++)
535 for (vecterm *p = elem(c); p != nullptr; p = p->next)
536 {
537 // Determine new component
538 int loc = c * n_rows() + p->comp;
539 int result_col = loc / F->rank();
540 int result_row = loc % F->rank();
541
542 mat.set_entry(result_row, result_col, p->coeff);
543 }
544 return mat.to_matrix();
545}
const_monomial degree_shift() const
Definition matrix.hpp:149
const Ring * get_ring() const
Definition matrix.hpp:134
ring_elem elem(int i, int j) const
Definition matrix.cpp:307
friend class MatrixConstructor
Definition matrix.hpp:76
int n_cols() const
Definition matrix.hpp:147
int n_rows() const
Definition matrix.hpp:146
int p
const int ERROR
Definition m2-mem.cpp:55
tbb::flow::graph G

References degree_shift(), elem(), ERROR, FreeModule, G, get_ring(), Matrix(), MatrixConstructor, n_cols(), n_rows(), p, reshape(), MatrixConstructor::set_entry(), and MatrixConstructor::to_matrix().

Referenced by IM2_Matrix_reshape(), and reshape().