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

◆ make() [1/3]

const Matrix * Matrix::make ( const FreeModule * target,
const FreeModule * source,
M2_arrayint deg,
const engine_RawRingElementArray M )
static

Definition at line 93 of file matrix.cpp.

97{
98 const Ring *R = target->get_ring();
99 auto D = R->degree_monoid();
100 if (source->get_ring() != R)
101 {
102 ERROR("expected free modules over the same ring");
103 return nullptr;
104 }
105 if (D->n_vars() != static_cast<int>(deg->len))
106 {
107 ERROR("expected degree of matrix to have %d entries", D->n_vars());
108 return nullptr;
109 }
110
111 if (M != nullptr)
112 {
113 for (unsigned int i = 0; i < M->len; i++)
114 {
115 if (R != M->array[i]->get_ring())
116 {
117 ERROR("expected vectors in the same ring");
118 return nullptr;
119 }
120 }
121 }
122
123 monomial degshift = D->make_one();
124 D->from_expvector(deg->array, degshift);
125 MatrixConstructor mat(target, source, degshift);
126
127 if (M != nullptr)
128 {
129 unsigned int next = 0;
130 for (int r = 0; r < target->rank(); r++)
131 {
132 for (int c = 0; c < source->rank(); c++)
133 {
134 mat.set_entry(r, c, M->array[next]->get_value());
135 next++;
136 if (next >= M->len) break;
137 }
138 }
139 }
140 return mat.to_matrix();
141}
const Ring * get_ring() const
Definition freemod.hpp:102
int rank() const
Definition freemod.hpp:105
friend class MatrixConstructor
Definition matrix.hpp:76
monomial make_one() const
Definition monoid.cpp:455
const Monoid * degree_monoid() const
Definition ring.cpp:13
#define monomial
Definition gb-toric.cpp:11
const int ERROR
Definition m2-mem.cpp:55

References Ring::degree_monoid(), ERROR, FreeModule, FreeModule::get_ring(), make(), Matrix(), MatrixConstructor, monomial, FreeModule::rank(), MatrixConstructor::set_entry(), and MatrixConstructor::to_matrix().