Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
Loading...
Searching...
No Matches
adaptive_precision_utilities.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//include/bertini2/trackers/adaptive_precision_utilities.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//include/bertini2/trackers/adaptive_precision_utilities.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 include/bertini2/trackers/adaptive_precision_utilities.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// Tim Hodges, Colorado State University
25
33
34#pragma once
35
37
38
39namespace bertini{ namespace tracking { namespace adaptive{
40
47inline
48void SetPrecision(SampCont<mpfr_complex> & samples, unsigned prec)
49{
50 for (auto& s : samples)
51 for (unsigned ii=0; ii<s.size(); ii++)
52 s(ii).precision(prec);
53}
54
61inline
62void SetPrecision(TimeCont<mpfr_complex> & times, unsigned prec)
63{
64 for (auto& t : times)
65 t.precision(prec);
66}
67
76inline
77unsigned MaxPrecision(SampCont<mpfr_complex> const& samples)
78{
79 unsigned max_precision = 0;
80 for (const auto& s : samples)
81 if(Precision(s(0)) > max_precision)
82 max_precision = Precision(s(0));
83 return max_precision;
84}
85
92inline
93unsigned MaxPrecision(TimeCont<mpfr_complex> const& times)
94{
95 unsigned max_precision = 0;
96 for (const auto& t : times)
97 if(Precision(t) > max_precision)
98 max_precision = Precision(t);
99 return max_precision;
100}
101
102
113inline
114unsigned EnsureAtUniformPrecision(TimeCont<dbl> & times, SampCont<dbl> & samples)
115{
116 return DoublePrecision();
117}
118
119
128inline
129unsigned EnsureAtUniformPrecision(TimeCont<mpfr_complex> & times, SampCont<mpfr_complex> & samples)
130{
131 auto def_prec = DefaultPrecision();
132 if (std::any_of(begin(times),end(times),[=](auto const& p){return Precision(p)!=def_prec;})
133 ||
134 std::any_of(begin(samples),end(samples),[=](auto const& p){return Precision(p)!=def_prec;}))
135 {
136 auto max_precision = max(MaxPrecision(samples), MaxPrecision(times));
137
138 DefaultPrecision(max_precision);
139 SetPrecision(times, max_precision);
140 SetPrecision(samples, max_precision);
141 return max_precision;
142 }
143 return def_prec;
144
145}
146
147
159inline
160unsigned EnsureAtUniformPrecision(TimeCont<mpfr_complex> & times, SampCont<mpfr_complex> & samples, SampCont<mpfr_complex> & derivatives)
161{
162 auto def_prec = DefaultPrecision();
163 if (std::any_of(begin(samples),end(samples),[=](auto const& p){return Precision(p)!=def_prec;})
164 ||
165 std::any_of(begin(derivatives),end(derivatives),[=](auto const& p){return Precision(p)!=def_prec;}))
166 {
167 auto max_precision = max(MaxPrecision(samples),MaxPrecision(times),MaxPrecision(derivatives));
168
169 DefaultPrecision(max_precision);
170
171 SetPrecision(times, max_precision);
172 SetPrecision(samples, max_precision);
173 SetPrecision(derivatives, max_precision);
174 return max_precision;
175 }
176 return def_prec;
177}
178
179
180
181}}} // re: namespaces
unsigned MaxPrecision(SampCont< mpfr_complex > const &samples)
Get the maximum precision among an input set of space samples.
Definition adaptive_precision_utilities.hpp:77
void SetPrecision(SampCont< mpfr_complex > &samples, unsigned prec)
Sets the precision of each space sample to be of input precision.
Definition adaptive_precision_utilities.hpp:48
unsigned EnsureAtUniformPrecision(TimeCont< dbl > &times, SampCont< dbl > &samples)
Does not a thing, because cannot.
Definition adaptive_precision_utilities.hpp:114
T max(T const &a, T const &b, T const &c)
Three-argument form of max.
Definition mpfr_extensions.hpp:98
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
Configs and settings for tracking.