14#if !defined(GPR_RGMIN_BFGS_HESSIAN) || !defined(GPR_RGMIN_SR1_HESSIAN)
16 "gpridge requires rgmin_bfgs_hessian_update and rgmin_sr1_hessian_update. The local BFGS and SR1 updates were removed."
18#if !__has_include(<rgsaddle.h>)
20 "gpridge requires rgsaddle (rgsaddle_hessian_bofill). The local Bofill update was removed."
28void packRowMajor(
const Eigen::MatrixXd& matrix, std::vector<double>& packed)
30 const Eigen::Index n = matrix.rows();
31 const auto nn =
static_cast<std::size_t
>(n);
32 packed.resize(nn * nn);
33 for (Eigen::Index col = 0; col < n; ++col) {
34 for (Eigen::Index row = 0; row < n; ++row) {
35 packed[
static_cast<std::size_t
>(row) * nn +
36 static_cast<std::size_t
>(col)] = matrix(row, col);
41bool finiteRowMajor(Eigen::MatrixXd& matrix, std::vector<double>& packed)
43 for (
double value: packed) {
44 if (!std::isfinite(value))
return false;
46 const Eigen::Index n = matrix.rows();
47 const auto nn =
static_cast<std::size_t
>(n);
48 for (Eigen::Index col = 0; col < n; ++col) {
49 for (Eigen::Index row = 0; row < n; ++row) {
50 matrix(row, col) = packed[
static_cast<std::size_t
>(row) * nn +
51 static_cast<std::size_t
>(col)];
59bool SecantHessian::updateBfgs(Eigen::MatrixXd& matrix,
60 const Eigen::VectorXd& step,
61 const Eigen::VectorXd& gradient_change)
63 std::vector<double> packed;
64 packRowMajor(matrix, packed);
65 const auto applied = rgmin_bfgs_hessian_update(
66 static_cast<std::int64_t
>(matrix.rows()), packed.data(), step.data(),
67 gradient_change.data());
71 if (applied == RGMIN_HESSIAN_UPDATE_SKIPPED)
73 if (applied != RGMIN_SUCCESS)
return false;
74 return finiteRowMajor(matrix, packed);
77bool SecantHessian::updateSr1(Eigen::MatrixXd& matrix,
78 const Eigen::VectorXd& step,
79 const Eigen::VectorXd& gradient_change)
81 std::vector<double> packed;
82 packRowMajor(matrix, packed);
83 const auto applied = rgmin_sr1_hessian_update(
84 static_cast<std::int64_t
>(matrix.rows()), packed.data(), step.data(),
85 gradient_change.data());
87 if (applied == RGMIN_HESSIAN_UPDATE_SKIPPED)
return false;
88 if (applied != RGMIN_SUCCESS)
return false;
89 return finiteRowMajor(matrix, packed);
92bool SecantHessian::updateBofill(Eigen::MatrixXd& matrix,
93 const Eigen::VectorXd& step,
94 const Eigen::VectorXd& gradient_change)
96 std::vector<double> packed;
97 packRowMajor(matrix, packed);
99 static_cast<std::int64_t
>(matrix.rows()), packed.data(), step.data(),
100 gradient_change.data());
102 if (through == 0)
return false;
103 return finiteRowMajor(matrix, packed);
std::string bofillRgsaddleAbiRefusal()
int bofillThroughLoadedRgsaddle(std::int64_t n, double *hessian_row_major, const double *step, const double *gradient_change)