Macaulay2 Engine
Loading...
Searching...
No Matches
dmat-zzp-flint.hpp
Go to the documentation of this file.
1// Copyright 2013 Michael E. Stillman
2
3#ifndef _dmat_zzp_flint_hpp_
4#define _dmat_zzp_flint_hpp_
5
39
40#include <utility> // for swap
41#include "aring-zzp-flint.hpp" // for ARingZZpFlint
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/nmod_mat.h> // for nmod_mat_t, nmod_mat_clear, nmod_mat_init, nmod_m...
49#pragma GCC diagnostic pop
50
51template <typename ACoeffRing>
52class DMat;
53
55// Flint: use nmod_mat for implementation of dense matrices //
57
70template <>
71class DMat<M2::ARingZZpFlint>
72{
73 public:
78 typedef ACoeffRing::Element Element;
79
80 DMat() : mRing(0) {}
81 DMat(const ACoeffRing& R, size_t nrows, size_t ncols) : mRing(&R)
82 {
83 nmod_mat_init(mArray, nrows, ncols, R.characteristic());
84 }
85
86 DMat(const DMat<ACoeffRing>& M) : mRing(&M.ring())
87 {
88 nmod_mat_init_set(mArray, M.mArray);
89 }
90
91 ~DMat() { nmod_mat_clear(mArray); }
92
93 // swap the actual matrices of 'this' and 'M'.
94 // The rings must be the same.
96 {
99 }
100
101 const ACoeffRing& ring() const { return *mRing; }
102 size_t numRows() const { return nmod_mat_nrows(mArray); }
103 size_t numColumns() const { return nmod_mat_ncols(mArray); }
104
105 ElementType& entry(size_t row, size_t column)
106 {
107 return nmod_mat_entry(mArray, row, column);
108 }
109 const ElementType& entry(size_t row, size_t column) const
110 {
111 return nmod_mat_entry(mArray, row, column);
112 }
113
114 void resize(size_t new_nrows, size_t new_ncols)
115 {
116 DMat newMatrix(ring(), new_nrows, new_ncols);
117 swap(newMatrix);
118 }
119
120 // These are labelled 'unsafe', as it s possible the rows
121 // are out of order (which happens in particular if
122 // certain flint functions created this.
123 const ElementType* unsafeArray() const { return mArray->entries; }
124 ElementType*& unsafeArray() { return mArray->entries; }
125 public:
126 // Access routines so that the flint nmod_mat interface may be used
127 const nmod_mat_t& nmod_mat() const { return mArray; }
128 nmod_mat_t& nmod_mat() { return mArray; }
129 private:
131 nmod_mat_t mArray;
132};
133
134#endif
135
136// Local Variables:
137// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
138// indent-tabs-mode: nil
139// End:
M2::ARingZZpFlint — Z/p via FLINT's nmod_t precomputed-reciprocal reduction.
void swap(DMat< ACoeffRing > &M)
ACoeffRing::ElementType ElementType
const ElementType & entry(size_t row, size_t column) const
DMat(const DMat< ACoeffRing > &M)
ElementType & entry(size_t row, size_t column)
void resize(size_t new_nrows, size_t new_ncols)
const ACoeffRing & ring() const
ACoeffRing::Element Element
const ElementType * unsafeArray() const
M2::ARingZZpFlint ACoeffRing
DMat(const ACoeffRing &R, size_t nrows, size_t ncols)
const nmod_mat_t & nmod_mat() const
const ACoeffRing * mRing
Definition dmat.hpp:174
ElementType * mArray
Definition dmat.hpp:177
const ACoeffRing & ring() const
Definition dmat.hpp:143
Definition dmat.hpp:62
size_t characteristic() const
aring-style adapter for Z/p with p a word-size prime, backed by FLINT's nmod_* routines.
#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