Macaulay2 Engine
Loading...
Searching...
No Matches
aring-zzp-ffpack.hpp
Go to the documentation of this file.
1// Copyright 2011 Michael E. Stillman
2
3#ifndef _aring_ffpack_hpp_
4#define _aring_ffpack_hpp_
5
38
39#include "aring.hpp"
40#include "buffer.hpp"
41#include "ringelem.hpp"
42
43#include <type_traits> // define bool_constant to fix issue #2347
44#include <utility>
45#include <ratio> //fix compilation errors on some macs
46
47#pragma GCC diagnostic push
48#pragma GCC diagnostic ignored "-Wconversion"
49#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
50#define bool_constant givaro_bool_constant
51#include <fflas-ffpack/ffpack/ffpack.h>
52#undef bool_constant
53#pragma GCC diagnostic pop
54
55namespace M2 {
56
62
63class ARingZZpFFPACK : public SimpleARing<ARingZZpFFPACK>
64{
65 public:
67 // Questions: why names are UTT, STT?
68 // Also: whatever we call them, we want all aring classes to use them.
69 // problem: givaro isn't necessarily defined here
71
72 // typedef FFPACK::ModularBalanced<double> FieldType;
73 typedef Givaro::Modular<double> FieldType;
74
75 typedef FieldType::Element ElementType;
77 typedef std::vector<elem> ElementContainerType;
78
79 typedef uint32_t
81
82 // see http://en.cppreference.com/w/cpp/types !
83 typedef std::make_signed<UTT>::type STT;
84
85 // if no givaro, use this:
86 // typedef int32_t STT; /// attention: depends on UTT; currently manual
87 // update
88
89 // @todo problem, wenn typ von cHarakteristif
90 ARingZZpFFPACK(UTT charac);
91
92 public:
93 // ring informational
94 UTT characteristic() const { return mCharac; }
95 UTT cardinality() const { return mCharac; }
97 {
98 if (not mGeneratorComputed)
99 {
101 mGeneratorComputed = true;
102 }
103 return mGenerator;
104 }
105
106 const FieldType field() const { return mFfpackField; }
108
109 unsigned int computeHashValue(const elem &a) const
110 {
111 return static_cast<unsigned int>(a);
112 }
113
117 void text_out(buffer &o) const
118 {
119 o << "ZZpFPACK(" << mCharac << "," << mDimension << ")";
120 }
121
122 void elem_text_out(buffer &o,
123 const ElementType a,
124 bool p_one = true,
125 bool p_plus = false,
126 bool p_parens = false) const;
128
132
133 bool is_unit(const ElementType f) const;
134 bool is_zero(const ElementType f) const;
135
137
140
141 long coerceToLongInteger(const elem &f) const
142 {
143 long result = static_cast<long>(f);
144 if (result > characteristic() / 2) result -= characteristic();
145 return result;
146 }
147
149 {
150 // Note that the max modulus is small enough (about 70 million in 2013)
151 // so that the coercion to an int will be correct.
152 result = ring_elem(static_cast<int>(a));
153 }
154
156 {
157 result = a.get_int();
158 }
159
161 {
162 return a.get_int();
163 }
164
166
169
170 bool is_equal(const ElementType f, const ElementType g) const;
171 int compare_elems(const ElementType f, const ElementType g) const;
173
176
178 void set(ElementType &result, ElementType a) const { result = a; }
179 void init(ElementType &result) const;
180
181 static void clear(ElementType &result) { (void) result; };
182
183 void set_zero(ElementType &result) const;
184
185 void copy(ElementType &result, const ElementType a) const;
186
187 void set_from_long(ElementType &result, long a) const;
188
189 void set_from_mpz(ElementType &result, mpz_srcptr a) const;
190
191 bool set_from_mpq(ElementType &result, mpq_srcptr a) const;
192
194 {
195 (void) result;
196 (void) a;
197 return false;
198 }
199
200 ElementType computeGenerator() const;
201
202 void set_var(ElementType &result, int v) const
203 {
204 (void) v;
206 }
207
209
212 void negate(ElementType &result, const ElementType a) const;
213
214 void invert(ElementType &result, const ElementType a) const;
215
216 void unsafeInvert(ElementType &result, const ElementType a) const;
217
218 void add(ElementType &result, const ElementType a, const ElementType b) const;
219
220 void subtract(ElementType &result,
221 const ElementType a,
222 const ElementType b) const;
223
224 void subtract_multiple(ElementType &result,
225 const ElementType a,
226 const ElementType b) const;
227
228 void mult(ElementType &result,
229 const ElementType a,
230 const ElementType b) const;
231
233 void divide(ElementType &result,
234 const ElementType a,
235 const ElementType b) const;
236
237 void power(ElementType &result, const ElementType a, const STT n) const;
238
239 void power_mpz(ElementType &result,
240 const ElementType a,
241 mpz_srcptr n) const;
242
243 void syzygy(const ElementType a,
244 const ElementType b,
245 ElementType &x,
246 ElementType &y) const;
248
251 void swap(ElementType &a, ElementType &b) const;
252
253 void random(ElementType &result) const;
254
255 // TODO: Mike. If possible, move promote, lift, eval to
256 // their own classes, or templated functions
257 bool promote(const Ring *Rf, const ring_elem f, ElementType &result) const;
258
259 bool lift(const Ring *Rg, const ElementType f, ring_elem &result) const;
260
261 // map : this --> target(map)
262 // primelem --> map->elem(first_var)
263 // evaluate map(f)
264 void eval(const RingMap *map,
265 const ElementType f,
266 int first_var,
267 ring_elem &result) const;
268
269 static inline double getMaxModulus()
270 {
271#if 1
272 return 0x7fff; // I have no idea what value would be correct here
273#else
274 if (std::is_same<Givaro::Modular<double>, FieldType>::value)
275 {
276 return FieldType::getMaxModulus() / 2;
277 }
278 return FieldType::getMaxModulus();
279#endif
280 }
281
282
283 private:
285 mutable FieldType::RandIter mFfpackRandomIterator;
286
289
293
294 mutable bool mGeneratorComputed;
295};
296};
297
298#endif
299
300// Local Variables:
301// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
302// indent-tabs-mode: nil
303// End:
Shared base of the aring framework (namespace M2) that unifies the engine's coefficient rings.
Append-only GC-backed byte buffer used throughout the engine for text output.
bool set_from_mpq(ElementType &result, mpq_srcptr a) const
std::vector< elem > ElementContainerType
void divide(ElementType &result, const ElementType a, const ElementType b) const
test doc
void subtract_multiple(ElementType &result, const ElementType a, const ElementType b) const
void add(ElementType &result, const ElementType a, const ElementType b) const
void invert(ElementType &result, const ElementType a) const
void set_var(ElementType &result, int v) const
void set_from_mpz(ElementType &result, mpz_srcptr a) const
void power(ElementType &result, const ElementType a, const STT n) const
void set_from_long(ElementType &result, long a) const
long coerceToLongInteger(const elem &f) const
ElementType computeGenerator() const
void init_set(ElementType &result, ElementType a) const
bool lift(const Ring *Rg, const ElementType f, ring_elem &result) const
void elem_text_out(buffer &o, const ElementType a, bool p_one=true, bool p_plus=false, bool p_parens=false) const
FieldType::RandIter mFfpackRandomIterator
void subtract(ElementType &result, const ElementType a, const ElementType b) const
const FieldType mFfpackField
std::make_signed< UTT >::type STT
int compare_elems(const ElementType f, const ElementType g) const
static void clear(ElementType &result)
bool is_equal(const ElementType f, const ElementType g) const
void eval(const RingMap *map, const ElementType f, int first_var, ring_elem &result) const
void power_mpz(ElementType &result, const ElementType a, mpz_srcptr n) const
void random(ElementType &result) const
ElementType from_ring_elem_const(const ring_elem &a) const
const FieldType field() const
void init(ElementType &result) const
Givaro::Modular< double > FieldType
void set_zero(ElementType &result) const
const ElementType & getGenerator() const
static const RingID ringID
bool is_unit(const ElementType f) const
void negate(ElementType &result, const ElementType a) const
UTT mDimension
same as extensionDegree
unsigned int computeHashValue(const elem &a) const
void syzygy(const ElementType a, const ElementType b, ElementType &x, ElementType &y) const
returns x,y s.y. x*a + y*b == 0. if possible, x is set to 1. no need to consider the case a==0 or b==...
void mult(ElementType &result, const ElementType a, const ElementType b) const
void text_out(buffer &o) const
void copy(ElementType &result, const ElementType a) const
static double getMaxModulus()
void unsafeInvert(ElementType &result, const ElementType a) const
FieldType::Element ElementType
void to_ring_elem(ring_elem &result, const ElementType &a) const
bool set_from_BigReal(ElementType &result, gmp_RR a) const
void set(ElementType &result, ElementType a) const
void from_ring_elem(ElementType &result, const ring_elem &a) const
bool promote(const Ring *Rf, const ring_elem f, ElementType &result) const
bool is_zero(const ElementType f) const
A base class for simple ARings.
Definition aring.hpp:147
xxx xxx xxx
Definition ring.hpp:102
Engine-side ring homomorphism: stores, for each source-ring variable, the target-ring element it maps...
Definition ringmap.hpp:60
RingID
Definition aring.hpp:75
@ ring_ZZpFfpack
Definition aring.hpp:82
VALGRIND_MAKE_MEM_DEFINED & result(result)
mpfr_srcptr gmp_RR
Definition m2-types.h:148
#define swap(a, b, t)
Definition monsort.hpp:127
Definition aring-CC.cpp:3
volatile int x
ring_elem — the universal value type carried by every Ring* in the engine.
int get_int() const
Definition ringelem.hpp:124