Macaulay2 Engine
Loading...
Searching...
No Matches
dmat-qq-flint.hpp
Go to the documentation of this file.
1// Copyright 2013 Michael E. Stillman
2
3#ifndef _dmat_qq_flint_hpp_
4#define _dmat_qq_flint_hpp_
5
39
40#include <assert.h> // for assert
41#include <utility> // for swap
42#include "aring-qq-flint.hpp" // for ARingQQFlint
43
44// The following needs to be included before any flint files are included.
45#include <M2/gc-include.h>
46
47#pragma GCC diagnostic push
48#pragma GCC diagnostic ignored "-Wconversion"
49#include <flint/fmpq_mat.h> // for fmpq_mat_t, fmpq_mat_entry, fmpq_mat_init, fmpq_ma...
50#pragma GCC diagnostic pop
51
52template <typename ACoeffRing>
53class DMat;
54
56// Dense matrices for Flint type M2::ARingQQFlint //
58
72// Warning: objects of this class should *not* go to the front end.
73// fmpz_t's might be garbage collected out from under you...
74template <>
75class DMat<M2::ARingQQFlint>
76{
77 public:
81 // typedef ElementType elem;
82 // typedef ACoeffRing::Element Element;
83
84 DMat() : mRing(0) {}
85 DMat(const ACoeffRing& R, size_t nrows, size_t ncols) : mRing(&R)
86 {
87 fmpq_mat_init(mArray, nrows, ncols);
88 }
89
90 DMat(const DMat<ACoeffRing>& M) : mRing(&M.ring())
91 {
92 fmpq_mat_init(mArray, M.numRows(), M.numColumns());
93 fmpq_mat_set(mArray, M.mArray);
94 }
95
96 ~DMat() { fmpq_mat_clear(mArray); }
97
98 // swap the actual matrices of 'this' and 'M'.
100 {
102 std::swap(*mArray, *M.mArray);
103 }
104
105 const ACoeffRing& ring() const { return *mRing; }
106 size_t numRows() const { return fmpq_mat_nrows(mArray); }
107 size_t numColumns() const { return fmpq_mat_ncols(mArray); }
108
109 ElementType& entry(size_t row, size_t column)
110 {
111 assert(row < numRows());
112 assert(column < numColumns());
113 return *fmpq_mat_entry(mArray, row, column);
114 }
115 const ElementType& entry(size_t row, size_t column) const
116 {
117 assert(row < numRows());
118 assert(column < numColumns());
119 return *fmpq_mat_entry(mArray, row, column);
120 }
121
122 void resize(size_t new_nrows, size_t new_ncols)
123 {
124 DMat newMatrix(ring(), new_nrows, new_ncols);
125 swap(newMatrix);
126 }
127
128 // These are labelled 'unsafe', as it s possible the rows
129 // are out of order (which happens in particular if
130 // certain flint functions created this.
131 const ElementType* unsafeArray() const { return mArray->entries; }
132 ElementType*& unsafeArray() { return mArray->entries; }
133
134 public:
135 // Other routines from flint nmod_mat interface
136 const fmpq_mat_t& fmpq_mat() const { return mArray; }
137 fmpq_mat_t& fmpq_mat() { return mArray; }
138 private:
140 fmpq_mat_t mArray;
141};
142
143#endif
144
145// Local Variables:
146// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
147// indent-tabs-mode: nil
148// End:
M2::ARingQQFlint — rationals backed by FLINT's fmpq with small-value inlining.
const ElementType * unsafeArray() const
const ACoeffRing & ring() const
void resize(size_t new_nrows, size_t new_ncols)
ElementType & entry(size_t row, size_t column)
DMat(const ACoeffRing &R, size_t nrows, size_t ncols)
const ACoeffRing * mRing
const ElementType & entry(size_t row, size_t column) const
M2::ARingQQFlint ACoeffRing
ACoeffRing::ElementType ElementType
void swap(DMat< ACoeffRing > &M)
DMat(const DMat< ACoeffRing > &M)
ElementType *& unsafeArray()
const fmpq_mat_t & fmpq_mat() const
size_t numRows() const
Definition dmat.hpp:144
const ACoeffRing * mRing
Definition dmat.hpp:174
ElementType * mArray
Definition dmat.hpp:177
const ACoeffRing & ring() const
Definition dmat.hpp:143
size_t numColumns() const
Definition dmat.hpp:145
Definition dmat.hpp:62
wrapper for the flint fmpq_t integer representation
#define swap(a, b, t)
Definition monsort.hpp:127
Definition aring-CC.cpp:3
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Definition mpreal.h:3244