Macaulay2 Engine
Loading...
Searching...
No Matches
dmat-qq-interface-flint.hpp
Go to the documentation of this file.
1// Copyright 2014 Michael E. Stillman
2
3#ifndef _flintqq_mat_hpp_
4#define _flintqq_mat_hpp_
5
33
34// This class is designed to use DMat<M2::ARingQQ>, which stores elements as gmp
35// ints
36// This sets up flint fmpq_mat matrices, and provides translation. This is
37// significantly faster than doing the operations in a naive manner.
38// This will become un-needed once DMat<ARingQQ> starts using flint
39// integers/rationals.
40
57{
58 public:
60 {
61 fmpz_mat_init(mMatrix, mat.numRows(), mat.numColumns());
62 to_fmpz_mat(mat, mMatrix);
63 }
64 FlintZZMat(long numrows, long numcolumns)
65 {
66 fmpz_mat_init(mMatrix, numrows, numcolumns);
67 }
68
69 ~FlintZZMat() { fmpz_mat_clear(mMatrix); }
70 fmpz_mat_struct* value() { return mMatrix; }
72 {
73 result.resize(fmpz_mat_nrows(mMatrix), fmpz_mat_ncols(mMatrix));
75 }
76
77 long numRows() const { return fmpz_mat_nrows(mMatrix); }
78 long numColumns() const { return fmpz_mat_ncols(mMatrix); }
79 private:
80 fmpz_mat_t mMatrix;
81
82 static void to_fmpz_mat(const DMatZZGMP& mat1, fmpz_mat_t result_mat)
83 {
84 DMatZZGMP& mat = const_cast<DMatZZGMP&>(mat1);
85 for (long r = 0; r < mat.numRows(); r++)
86 for (long c = 0; c < mat.numColumns(); c++)
87 {
88 fmpz_set_mpz(fmpz_mat_entry(result_mat, r, c), & mat1.entry(r,c));
89 }
90 }
91
92 static void from_fmpz_mat(fmpz_mat_t mat, DMatZZGMP& result_mat)
93 {
94 for (long r = 0; r < result_mat.numRows(); r++)
95 for (long c = 0; c < result_mat.numColumns(); c++)
96 {
97 fmpz_get_mpz(& result_mat.entry(r,c), fmpz_mat_entry(mat, r, c));
98 }
99 }
100};
101
115{
116 private:
117 fmpq_mat_t mMatrix;
118 public:
120
121 FlintQQMat(const DMatQQ& mat)
122 {
123 fmpq_mat_init(mMatrix, mat.numRows(), mat.numColumns());
124 to_fmpq_mat(mat, mMatrix);
125 }
126 FlintQQMat(long numrows, long numcolumns)
127 {
128 fmpq_mat_init(mMatrix, numrows, numcolumns);
129 }
130
131 ~FlintQQMat() { fmpq_mat_clear(mMatrix); }
132 fmpq_mat_struct* value() { return mMatrix; }
134 {
135 result.resize(fmpq_mat_nrows(mMatrix), fmpq_mat_ncols(mMatrix));
137 }
138
139 long numRows() const { return fmpq_mat_nrows(mMatrix); }
140 long numColumns() const { return fmpq_mat_ncols(mMatrix); }
141 void set_from_fmpz(long r, long c, fmpz_t val)
142 {
143 fmpz_set(fmpq_numref(fmpq_mat_entry(mMatrix, r, c)), val);
144 fmpz_set_ui(fmpq_denref(fmpq_mat_entry(mMatrix, r, c)), 1);
145 }
146
147private:
148 static void to_fmpq_mat(const DMatQQ& mat1, fmpq_mat_t result_mat)
149 {
150 DMatQQ& mat = const_cast<DMatQQ&>(mat1);
151 for (long r = 0; r < mat.numRows(); r++)
152 for (long c = 0; c < mat.numColumns(); c++)
153 {
154 fmpq_set_mpq(fmpq_mat_entry(result_mat, r, c), & mat1.entry(r,c));
155 }
156 }
157
158 static void from_fmpq_mat(fmpq_mat_t mat, DMatQQ& result_mat)
159 {
160 for (long r = 0; r < result_mat.numRows(); r++)
161 for (long c = 0; c < result_mat.numColumns(); c++)
162 {
163 fmpq_get_mpq(& result_mat.entry(r,c), fmpq_mat_entry(mat, r, c));
164 }
165 }
166};
167
168#endif
169
170// Local Variables:
171// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
172// indent-tabs-mode: nil
173// End:
size_t numRows() const
Definition dmat.hpp:144
ElementType & entry(size_t row, size_t column)
Definition dmat.hpp:148
size_t numColumns() const
Definition dmat.hpp:145
Definition dmat.hpp:62
void set_from_fmpz(long r, long c, fmpz_t val)
static void from_fmpq_mat(fmpq_mat_t mat, DMatQQ &result_mat)
fmpq_mat_struct * value()
void toDMat(DMatQQ &result)
FlintQQMat(const DMatQQ &mat)
FlintQQMat(long numrows, long numcolumns)
DMat< M2::ARingQQ > DMatQQ
static void to_fmpq_mat(const DMatQQ &mat1, fmpq_mat_t result_mat)
FlintZZMat(const DMatZZGMP &mat)
void toDMat(DMatZZGMP &result)
FlintZZMat(long numrows, long numcolumns)
static void to_fmpz_mat(const DMatZZGMP &mat1, fmpz_mat_t result_mat)
static void from_fmpz_mat(fmpz_mat_t mat, DMatZZGMP &result_mat)
fmpz_mat_struct * value()
VALGRIND_MAKE_MEM_DEFINED & result(result)
DMat< M2::ARingZZGMP > DMatZZGMP