Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
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) 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
29
30#pragma once
31
33
34
35namespace bertini{ namespace tracking { namespace adaptive{
36
43inline
44void SetPrecision(SampCont<complex_mp> & samples, unsigned prec)
45{
46 for (auto& s : samples)
47 for (unsigned ii=0; ii<s.size(); ii++)
48 s(ii).precision(prec);
49}
50
57inline
58void SetPrecision(TimeCont<complex_mp> & times, unsigned prec)
59{
60 for (auto& t : times)
61 t.precision(prec);
62}
63
72inline
73unsigned MaxPrecision(SampCont<complex_mp> const& samples)
74{
75 unsigned max_precision = 0;
76 for (const auto& s : samples)
77 if(Precision(s(0)) > max_precision)
78 max_precision = Precision(s(0));
79 return max_precision;
80}
81
88inline
89unsigned MaxPrecision(TimeCont<complex_mp> const& times)
90{
91 unsigned max_precision = 0;
92 for (const auto& t : times)
93 if(Precision(t) > max_precision)
94 max_precision = Precision(t);
95 return max_precision;
96}
97
98
106inline
108{
109 return DoublePrecision();
110}
111
112
121inline
123{
124 auto def_prec = ThreadPrecision();
125 if (std::any_of(begin(times),end(times),[=](auto const& p){return Precision(p)!=def_prec;})
126 ||
127 std::any_of(begin(samples),end(samples),[=](auto const& p){return Precision(p)!=def_prec;}))
128 {
129 auto max_precision = max(MaxPrecision(samples), MaxPrecision(times));
130
131 SetThreadPrecision(max_precision);
132 SetPrecision(times, max_precision);
133 SetPrecision(samples, max_precision);
134 return max_precision;
135 }
136 return def_prec;
137
138}
139
140
152inline
154{
155 auto def_prec = ThreadPrecision();
156 if (std::any_of(begin(samples),end(samples),[=](auto const& p){return Precision(p)!=def_prec;})
157 ||
158 std::any_of(begin(derivatives),end(derivatives),[=](auto const& p){return Precision(p)!=def_prec;}))
159 {
160 auto max_precision = max(MaxPrecision(samples),MaxPrecision(times),MaxPrecision(derivatives));
161
162 SetThreadPrecision(max_precision);
163
164 SetPrecision(times, max_precision);
165 SetPrecision(samples, max_precision);
166 SetPrecision(derivatives, max_precision);
167 return max_precision;
168 }
169 return def_prec;
170}
171
172
173
174}}} // re: namespaces
Definition adaptive_precision_utilities.hpp:35
void SetPrecision(SampCont< complex_mp > &samples, unsigned prec)
Sets the precision of each space sample to be of input precision.
Definition adaptive_precision_utilities.hpp:44
unsigned MaxPrecision(SampCont< complex_mp > const &samples)
Get the maximum precision among an input set of space samples.
Definition adaptive_precision_utilities.hpp:73
unsigned EnsureAtUniformPrecision(TimeCont< complex_dbl > &, SampCont< complex_dbl > &)
Does not a thing, because cannot.
Definition adaptive_precision_utilities.hpp:107
Definition adaptive_precision_utilities.hpp:35
T max(T const &a, T const &b, T const &c)
Three-argument form of max.
Definition mpfr_extensions.hpp:96
Definition algorithm_builder.hpp:36
constexpr unsigned DoublePrecision()
The number of digits considered "double precision" (16).
Definition num_traits.hpp:152
std::deque< Vec< T > > SampCont
Definition config.hpp:33
void SetThreadPrecision(unsigned prec)
Set the precision (digits) for the current thread only (does not touch the global default).
Definition mpfr_complex.hpp:176
std::deque< T > TimeCont
Definition config.hpp:34
unsigned ThreadPrecision()
Get the current thread's precision (digits).
Definition mpfr_complex.hpp:183
unsigned Precision(Eigen::MatrixBase< Derived > const &v)
Get the precision of an Eigen object.
Definition eigen_extensions.hpp:339
Configs and settings for tracking.