Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
Loading...
Searching...
No Matches
mpfr_extensions.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//mpfr_extensions.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//mpfr_extensions.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with mpfr_extensions.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) 2015 - 2021 by Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22// individual authors of this file include:
23// silviana amethyst, university of wisconsin - eau claire
24
32
33#ifndef BERTINI_MPFR_EXTENSIONS_HPP
34#define BERTINI_MPFR_EXTENSIONS_HPP
35
36
37
38#include <boost/multiprecision/mpfr.hpp>
39
40#ifdef B2_FORBID_MIXED_ARITHMETIC
41 #include "bertini2/forbid_mixed_arithmetic.hpp"
42#endif
43
44#include <boost/random.hpp>
45
46#include <boost/archive/text_oarchive.hpp>
47#include <boost/archive/text_iarchive.hpp>
48#include <boost/serialization/split_member.hpp>
49
50#include <string>
51
53
54namespace bertini{
55#ifdef BMP_EXPRESSION_TEMPLATES
56 using mpfr_float = boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, boost::multiprecision::et_on>;
57 using mpz_int = boost::multiprecision::number<boost::multiprecision::backends::gmp_int, boost::multiprecision::et_on>;
58 using mpq_rational = boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, boost::multiprecision::et_on>;
59#else
60 using mpfr_float = boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, boost::multiprecision::et_off>;
61 using mpz_int = boost::multiprecision::number<boost::multiprecision::backends::gmp_int, boost::multiprecision::et_off>;
62 using mpq_rational = boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, boost::multiprecision::et_off>;
63#endif
64
70 inline
71 auto Precision(mpfr_float const& num)
72 {
73 return num.precision();
74 }
75
81 inline void Precision(mpfr_float & num, unsigned prec)
82 {
83 num.precision(prec);
84 }
85}
86
87
88// overloads of the `max` function.
89namespace bertini{
97 template <typename T>
98 T max(T const& a, T const& b, T const& c)
99 {
100 using std::max;
101 return max(max(a,b),c);
102 }
103
112 template <typename T>
113 T max(T const& a, T const& b, T const& c, T const& d)
114 {
115 using std::max;
116 using bertini::max;
117 return max(max(a,b,c),d);
118 }
119
129 template <typename T>
130 T max(T const& a, T const& b, T const& c, T const& d, T const& e)
131 {
132 using std::max;
133 using bertini::max;
134 return max(max(a,b,c,d),e);
135 }
136}
137
138
139
140// the following code block extends serialization to the mpfr_float class from boost::multiprecision
141namespace boost { namespace serialization {
145 template <typename Archive>
146 void save(Archive& ar, ::boost::multiprecision::backends::mpfr_float_backend<0> const& r, unsigned /*version*/)
147 {
148 unsigned num_digits(r.precision());
149 ar & num_digits;
150 std::string tmp = r.str(0,std::ios::scientific);
151 ar & tmp;
152 }
153
157 template <typename Archive>
158 void load(Archive& ar, ::boost::multiprecision::backends::mpfr_float_backend<0>& r, unsigned /*version*/)
159 {
160 unsigned num_digits;
161 ar & num_digits;
162 r.precision(num_digits);
163 std::string tmp;
164 ar & tmp;
165 r = tmp.c_str();
166 }
167
168
169
173 template <typename Archive>
174 void save(Archive& ar, ::boost::multiprecision::backends::gmp_rational const& r, unsigned /*version*/)
175 {
176 std::string tmp = r.str(0,std::ios::scientific);
177 ar & tmp;
178 }
179
183 template <typename Archive>
184 void load(Archive& ar, ::boost::multiprecision::backends::gmp_rational& r, unsigned /*version*/)
185 {
186 std::string tmp;
187 ar & tmp;
188 r = tmp.c_str();
189 }
190
191
195 template <typename Archive>
196 void save(Archive& ar, ::boost::multiprecision::backends::gmp_int const& r, unsigned /*version*/)
197 {
198 std::string tmp = r.str(0,std::ios::scientific);
199 ar & tmp;
200 }
201
205 template <typename Archive>
206 void load(Archive& ar, ::boost::multiprecision::backends::gmp_int& r, unsigned /*version*/)
207 {
208 std::string tmp;
209 ar & tmp;
210 r = tmp.c_str();
211 }
212
213
214} } // re: namespaces
215
216
217
218BOOST_SERIALIZATION_SPLIT_FREE(::boost::multiprecision::backends::mpfr_float_backend<0>)
219
220BOOST_SERIALIZATION_SPLIT_FREE(::boost::multiprecision::backends::gmp_rational)
221
222BOOST_SERIALIZATION_SPLIT_FREE(::boost::multiprecision::backends::gmp_int)
223
224
225// if you wish to use et_on with Boost.Multiprecision with Eigen 3.2.x or earlier, you must apply a patch to Boost.MP related to bug 11149, and use the following non-standard lines.
226// https://svn.boost.org/trac/boost/ticket/11149
227
228#define EIGEN_DEVICE_FUNC // to make Eigen 3.3 happy... ugh, this is likely to break CUDA usage with Bertini2, if that ever happens.
229#include <Eigen/src/Core/util/Macros.h>
230
231#ifdef BMP_EXPRESSION_TEMPLATES
232 #if (!EIGEN_VERSION_AT_LEAST(3,2,92)) // version of 3.3-beta1 is 3,2,92.
233 namespace std{
234using boost::multiprecision::min; //error receiver: please see https://svn.boost.org/trac/boost/ticket/11149 for information about these using statements in std namespace.
235using boost::multiprecision::max; //3 options: ./configure --disable-expression_templates, use Boost 1.61, or patch earlier Boost versions to resolve this.
236 }
237 #endif
238#endif
239
240
241
242#endif
243
244
245
246
Provides bertini extensions to the double and complex<double> types.
unsigned Precision(Eigen::MatrixBase< Derived > const &v)
Get the precision of an Eigen object. If the object is empty, it's the precision of a default-constru...
Definition eigen_extensions.hpp:292
void load(Archive &ar, ::boost::multiprecision::backends::mpc_complex_backend< 0 > &r, unsigned)
Definition mpfr_complex.hpp:163
void save(Archive &ar, ::boost::multiprecision::backends::mpc_complex_backend< 0 > const &r, unsigned)
Definition mpfr_complex.hpp:151
T max(T const &a, T const &b, T const &c)
Three-argument form of max.
Definition mpfr_extensions.hpp:98