Macaulay2 Engine
Loading...
Searching...
No Matches
matrix-con.cpp
Go to the documentation of this file.
1#include "matrix-con.hpp"
2#include "matrix.hpp"
3#include "debug.hpp"
4
5#include <iostream>
6
8 : R(nullptr), rows(nullptr), cols(nullptr), cols_frozen(false), deg(nullptr)
9{
10}
11
13 : R(target->get_ring()), rows(target), cols(nullptr), cols_frozen(false), deg(nullptr)
14{
15 cols = R->make_FreeModule(ncols);
16
17 entries.reserve(ncols);
18 for (int i = 0; i < ncols; i++) entries.push_back(nullptr);
19
20 deg = R->degree_monoid()->make_one();
21}
22
24 const FreeModule *source,
25 const_monomial deg0)
26 : R(target->get_ring()), rows(target), cols(source), cols_frozen(true)
27{
28 entries.reserve(source->rank());
29 for (int i = 0; i < source->rank(); i++) entries.push_back(nullptr);
30
31 deg = (deg0 == nullptr ? R->degree_monoid()->make_one()
32 : R->degree_monoid()->make_new(deg0));
33}
34
36{
37 assert(!cols_frozen);
38 monomial d = R->degree_monoid()->make_one();
39 if (v != nullptr) R->vec_multi_degree(rows, v, d);
40 append(v, d);
41 R->degree_monoid()->remove(d);
42}
44{
45 if (cols_frozen)
46 {
47 INTERNAL_ERROR("trying to append to an immutable free module.");
48 }
49 entries.push_back(v);
50 FreeModule *mutable_cols = const_cast<FreeModule *>(cols);
51 mutable_cols->append(deg0);
52}
53
55{
56 R->set_entry(entries[c], r, a);
57}
58void MatrixConstructor::set_column(int c, vec v) { entries[c] = v; }
60/* Takes into account the matrix degree */
61{
62 if (cols_frozen)
63 {
64 INTERNAL_ERROR("trying to append to an immutable free module.");
65 }
66 for (int i = 0; i < cols->rank(); i++) compute_column_degree(i);
67}
68
70{
71 if (cols_frozen)
72 {
73 INTERNAL_ERROR("trying to append to an immutable free module.");
74 }
75 FreeModule *mutable_cols = const_cast<FreeModule *>(cols);
76 mutable_cols->change_degree(i, deg0);
77}
78
80{
81 if (cols_frozen)
82 {
83 INTERNAL_ERROR("trying to append to an immutable free module.");
84 }
85 monomial d = R->degree_monoid()->make_one();
86 const vec v = entries[i];
87 if (v != nullptr) R->vec_multi_degree(rows, v, d);
88 FreeModule *mutable_cols = const_cast<FreeModule *>(cols);
89 mutable_cols->change_degree(i, d);
90 R->degree_monoid()->remove(d);
91}
92
95{
96 // if (!will_be_mutable && !cols->is_frozen)
97 // cols->freeze(hashval);
98 return new Matrix(rows, cols, deg, entries);
99}
100
102{
103 std::cout << "MatrixConstructor: ring = " << R << std::endl;
104 std::cout << "MatrixConstructor: rows = " << rows << std::endl;
105 std::cout << "MatrixConstructor: cols = " << cols << std::endl;
106 std::cout << "Matrixconstructor: #entries = " << entries.size() << std::endl;
107}
108
109// Local Variables:
110// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
111// indent-tabs-mode: nil
112// End:
void change_degree(int i, const_monomial deg)
Definition freemod.cpp:145
void append(const_monomial d)
Definition freemod.cpp:130
int rank() const
Definition freemod.hpp:105
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
const Ring * R
void compute_column_degree(int i)
const FreeModule * rows
const FreeModule * cols
Matrix * to_matrix()
void compute_column_degrees()
void set_column_degree(int i, const_monomial deg)
void append(vec v)
void set_entry(int r, int c, ring_elem a)
void debugDisplay() const
void set_matrix_degree(const_monomial deg)
void set_column(int c, vec v)
const_monomial deg
Debugger-callable d* helpers that pretty-print engine values to stderr.
void INTERNAL_ERROR(const char *s,...)
Definition error.c:36
#define Matrix
Definition factory.cpp:14
#define monomial
Definition gb-toric.cpp:11
const int * const_monomial
Definition imonorder.hpp:45
MatrixConstructor — the mutable builder that produces an immutable Matrix.
Matrix — the engine's immutable homomorphism F -> G between free modules.