Macaulay2 Engine
Loading...
Searching...
No Matches
dmat-zz-flint.hpp
Go to the documentation of this file.
1// Copyright 2013 Michael E. Stillman
2
3#ifndef _dmat_zz_flint_hpp_
4#define _dmat_zz_flint_hpp_
5
38
39#include <assert.h> // for assert
40#include <utility> // for swap
41#include "aring-zz-flint.hpp" // for ARingZZ
42
43// The following needs to be included before any flint files are included.
44#include <M2/gc-include.h>
45
46#pragma GCC diagnostic push
47#pragma GCC diagnostic ignored "-Wconversion"
48#include <flint/fmpz_mat.h> // for fmpz_mat_t, fmpz_mat_entry, fmpz_mat_clear, fmpz_m...
49#pragma GCC diagnostic pop
50
51template <typename ACoeffRing>
52class DMat;
53
55// Dense matrices using Flint...
57
70template <>
71class DMat<M2::ARingZZ>
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...
74{
75 public:
79 // typedef ElementType elem;
80 // typedef ACoeffRing::Element Element;
81
82 DMat() : mRing(0) {}
83 DMat(const ACoeffRing& R, size_t nrows, size_t ncols) : mRing(&R)
84 {
85 fmpz_mat_init(mArray, nrows, ncols);
86 }
87
88 DMat(const DMat<ACoeffRing>& M) : mRing(&M.ring())
89 {
90 fmpz_mat_init_set(mArray, M.mArray);
91 }
92
93 ~DMat() { fmpz_mat_clear(mArray); }
94 // storage for these rings is row-major, which is reflected in these iterator
95 // functions
96
97 // swap the actual matrices of 'this' and 'M'.
99 {
101 fmpz_mat_swap(mArray, M.mArray);
102 }
103
104 const ACoeffRing& ring() const { return *mRing; }
105 size_t numRows() const { return fmpz_mat_nrows(mArray); }
106 size_t numColumns() const { return fmpz_mat_ncols(mArray); }
107
108 ElementType& entry(size_t row, size_t column)
109 {
110 assert(row < numRows());
111 assert(column < numColumns());
112 return *fmpz_mat_entry(mArray, row, column);
113 }
114 const ElementType& entry(size_t row, size_t column) const
115 {
116 assert(row < numRows());
117 assert(column < numColumns());
118 return *fmpz_mat_entry(mArray, row, column);
119 }
120
121 void resize(size_t new_nrows, size_t new_ncols)
122 {
123 DMat newMatrix(ring(), new_nrows, new_ncols);
124 swap(newMatrix);
125 }
126
127 // These are labelled 'unsafe', as it s possible the rows
128 // are out of order (which happens in particular if
129 // certain flint functions created this.
130 const ElementType* unsafeArray() const { return mArray->entries; }
131 ElementType*& unsafeArray() { return mArray->entries; }
132
133 public:
134 // Other routines from flint nmod_mat interface
135 const fmpz_mat_t& fmpz_mat() const { return mArray; }
136 fmpz_mat_t& fmpz_mat() { return mArray; }
137 private:
139 fmpz_mat_t mArray;
140};
141
142#endif
143
144// Local Variables:
145// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
146// indent-tabs-mode: nil
147// End:
M2::ARingZZ — FLINT-backed arbitrary-precision integers with small-value inlining.
void resize(size_t new_nrows, size_t new_ncols)
size_t numRows() const
DMat(const DMat< ACoeffRing > &M)
const ElementType * unsafeArray() const
DMat(const ACoeffRing &R, size_t nrows, size_t ncols)
const ACoeffRing * mRing
ElementType & entry(size_t row, size_t column)
ACoeffRing::ElementType ElementType
const ACoeffRing & ring() const
void swap(DMat< ACoeffRing > &M)
const ElementType & entry(size_t row, size_t column) const
ElementType *& unsafeArray()
size_t numColumns() const
fmpz_mat_t & fmpz_mat()
const fmpz_mat_t & fmpz_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 fmpz_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