79 : num_vars_(num_vars), coefficients_highest_precision_(std::move(coefficients)),
82 assert(
static_cast<size_t>(coefficients_highest_precision_.cols()) == num_vars_ + 1 &&
83 "a linear-forms coefficient matrix must have num_vars+1 columns");
99 : num_vars_(num_vars), coefficients_highest_precision_(std::move(coefficients)),
102 homogeneous_ = homogenized;
103 if (
static_cast<size_t>(coefficients_highest_precision_.cols()) != num_vars_ + (homogenized ? 0 : 1))
104 throw std::invalid_argument(
"LinearFormsBlock: the coefficient matrix has "
105 + std::to_string(coefficients_highest_precision_.cols()) +
" columns, but a block on "
106 + std::to_string(num_vars_) +
" variables that " + (homogenized ?
"is" :
"is not")
107 +
" homogenized needs " + std::to_string(num_vars_ + (homogenized ? 0 : 1)));
112 size_t NumFunctions()
const {
return static_cast<size_t>(coefficients_highest_precision_.rows()); }
134 throw std::runtime_error(
"LinearFormsBlock::Homogenize: block is already homogenized "
135 "(multiple affine variable groups are not yet supported for linear-forms blocks)");
136 const auto& M = coefficients_highest_precision_;
138 Mh.col(0) = M.col(
static_cast<Eigen::Index
>(num_vars_));
139 Mh.rightCols(
static_cast<Eigen::Index
>(num_vars_)) =
140 M.leftCols(
static_cast<Eigen::Index
>(num_vars_));
141 coefficients_highest_precision_ = Mh;
163 auto const& M = coefficients_highest_precision_;
164 const Eigen::Index n = M.rows();
168 const Eigen::Index shown = (verbose || n <= cap) ? n : cap;
171 for (Eigen::Index r = 0; r < shown; ++r)
173 out <<
" f_" << row++ <<
" = c.";
181 for (Eigen::Index r = 0; r < shown; ++r)
184 for (Eigen::Index c = 0; c < M.cols(); ++c)
194 row +=
static_cast<size_t>(n - shown);
195 out <<
" ... (" << (n - shown) <<
" more form" << (n - shown == 1 ?
"" :
"s")
196 <<
"; describe(verbose=True) for all)\n";
218 if (precision_==new_precision)
222 auto& wm = std::get<Mat<complex_mp>>(coefficients_working_);
223 for (Eigen::Index r = 0; r < wm.rows(); ++r)
224 for (Eigen::Index c = 0; c < wm.cols(); ++c)
226 wm(r, c).precision(new_precision);
227 if (new_precision > precision_)
228 wm(r, c) = coefficients_highest_precision_(r, c);
231 precision_ = new_precision;
242 template <
typename T>
250 result.noalias() = Working<T>() * vars;
252 result.noalias() = Working<T>() * Augment<T>(vars);
266 template <
typename T>
274 J = Working<T>().leftCols(
static_cast<Eigen::Index
>(num_vars_));
281 template <
typename T>
293 template <
typename T>
294 void SyncPrecision(
Vec<T> const& vars)
const
296 if constexpr (!std::is_same<T, complex_dbl>::value)
307 template <
typename T>
308 const Mat<T>& Working()
const
310 return std::get<Mat<T>>(coefficients_working_);
313 template <
typename T>
316 Vec<T> aug(
static_cast<Eigen::Index
>(num_vars_ + 1));
317 aug.head(
static_cast<Eigen::Index
>(num_vars_)) = vars;
319 if constexpr (!std::is_same<T, complex_dbl>::value)
320 one.precision(precision_);
321 aug(
static_cast<Eigen::Index
>(num_vars_)) = one;
325 void BuildWorking()
const
327 const auto& M = coefficients_highest_precision_;
328 auto& wd = std::get<Mat<complex_dbl>>(coefficients_working_);
329 auto& wm = std::get<Mat<complex_mp>>(coefficients_working_);
330 wd.resize(M.rows(), M.cols());
331 wm.resize(M.rows(), M.cols());
332 for (Eigen::Index r = 0; r < M.rows(); ++r)
333 for (Eigen::Index c = 0; c < M.cols(); ++c)
341 bool homogeneous_ =
false;
343 mutable std::tuple<Mat<complex_dbl>,
Mat<complex_mp>> coefficients_working_;
344 mutable unsigned precision_;
348 template <
typename Archive>
349 void serialize(Archive& ar,
const unsigned )
354 ar & coefficients_highest_precision_;
355 ar & std::get<0>(coefficients_working_);
356 ar & std::get<1>(coefficients_working_);
Small shared helpers for the per-block Describe methods – the human-facing printing of a block-compos...
Bertini extensions of the Eigen linear algebra library.
void PrintCoeff(std::ostream &out, complex_mp const &c, int sig=0)
Print one (complex_mp) coefficient compactly: a real prints as its real part, a pure imaginary as b*i...
Definition describe.hpp:56
void PrintAugmentedVars(std::ostream &out, VariableGroup const &vars, size_t num_vars, bool homogeneous)
The augmenting variable list [x, y, 1] (affine) or [h, x, y] (homogeneous: no trailing 1).
Definition describe.hpp:79
int CoeffSig(bool verbose)
The significant-digit count for coefficient printing: 4 for terse (short and legible),...
Definition describe.hpp:68
constexpr size_t kTerseRowCap
How many function rows a block lists in terse (non-verbose) describe before truncating with a ....
Definition describe.hpp:43
Definition blend_block.hpp:75
Definition algorithm_builder.hpp:36
constexpr unsigned DoublePrecision()
The number of digits considered "double precision" (16).
Definition num_traits.hpp:152
std::complex< double > complex_dbl
The double-precision complex number type.
Definition double_extensions.hpp:47
Eigen::Matrix< NumT, Eigen::Dynamic, 1 > Vec
A dynamically-sized column vector of NumT.
Definition eigen_extensions.hpp:296
std::vector< std::shared_ptr< node::Variable > > VariableGroup
An ordered group of variables (the unit of homogenization / variable grouping).
Definition node.hpp:69
Eigen::Matrix< NumT, Eigen::Dynamic, Eigen::Dynamic > Mat
A dynamically-sized matrix of NumT.
Definition eigen_extensions.hpp:298
auto DefaultPrecision()
Get the global default precision (digits) for multiprecision numbers.
Definition mpfr_complex.hpp:135
unsigned Precision(Eigen::MatrixBase< Derived > const &v)
Get the precision of an Eigen object.
Definition eigen_extensions.hpp:339
Provides an Eigen-like NumTraits struct for querying traits of a number type.