diff --git a/upstream_utils/sleipnir_patches/0001-Remove-using-enum-declarations.patch b/upstream_utils/sleipnir_patches/0001-Remove-using-enum-declarations.patch deleted file mode 100644 index 2a74fa6a849..00000000000 --- a/upstream_utils/sleipnir_patches/0001-Remove-using-enum-declarations.patch +++ /dev/null @@ -1,638 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Tyler Veness -Date: Wed, 24 Apr 2024 15:56:06 -0700 -Subject: [PATCH 1/5] Remove "using enum" declarations - ---- - include/sleipnir/autodiff/Expression.hpp | 161 +++++++----------- - .../optimization/SolverExitCondition.hpp | 22 ++- - 2 files changed, 73 insertions(+), 110 deletions(-) - -diff --git a/include/sleipnir/autodiff/Expression.hpp b/include/sleipnir/autodiff/Expression.hpp -index dd53755ccae88e3975d1b5e6b13ac464bd4efcce..51070613e82cdf5e4105519f39632deb5d2bf19e 100644 ---- a/include/sleipnir/autodiff/Expression.hpp -+++ b/include/sleipnir/autodiff/Expression.hpp -@@ -203,8 +203,6 @@ struct SLEIPNIR_DLLEXPORT Expression { - */ - friend SLEIPNIR_DLLEXPORT ExpressionPtr operator*(const ExpressionPtr& lhs, - const ExpressionPtr& rhs) { -- using enum ExpressionType; -- - // Prune expression - if (lhs->IsConstant(0.0)) { - // Return zero -@@ -219,20 +217,22 @@ struct SLEIPNIR_DLLEXPORT Expression { - } - - // Evaluate constant -- if (lhs->type == kConstant && rhs->type == kConstant) { -+ if (lhs->type == ExpressionType::kConstant && -+ rhs->type == ExpressionType::kConstant) { - return MakeExpressionPtr(lhs->value * rhs->value); - } - - // Evaluate expression type - ExpressionType type; -- if (lhs->type == kConstant) { -+ if (lhs->type == ExpressionType::kConstant) { - type = rhs->type; -- } else if (rhs->type == kConstant) { -+ } else if (rhs->type == ExpressionType::kConstant) { - type = lhs->type; -- } else if (lhs->type == kLinear && rhs->type == kLinear) { -- type = kQuadratic; -+ } else if (lhs->type == ExpressionType::kLinear && -+ rhs->type == ExpressionType::kLinear) { -+ type = ExpressionType::kQuadratic; - } else { -- type = kNonlinear; -+ type = ExpressionType::kNonlinear; - } - - return MakeExpressionPtr( -@@ -258,8 +258,6 @@ struct SLEIPNIR_DLLEXPORT Expression { - */ - friend SLEIPNIR_DLLEXPORT ExpressionPtr operator/(const ExpressionPtr& lhs, - const ExpressionPtr& rhs) { -- using enum ExpressionType; -- - // Prune expression - if (lhs->IsConstant(0.0)) { - // Return zero -@@ -269,16 +267,17 @@ struct SLEIPNIR_DLLEXPORT Expression { - } - - // Evaluate constant -- if (lhs->type == kConstant && rhs->type == kConstant) { -+ if (lhs->type == ExpressionType::kConstant && -+ rhs->type == ExpressionType::kConstant) { - return MakeExpressionPtr(lhs->value / rhs->value); - } - - // Evaluate expression type - ExpressionType type; -- if (rhs->type == kConstant) { -+ if (rhs->type == ExpressionType::kConstant) { - type = lhs->type; - } else { -- type = kNonlinear; -+ type = ExpressionType::kNonlinear; - } - - return MakeExpressionPtr( -@@ -306,8 +305,6 @@ struct SLEIPNIR_DLLEXPORT Expression { - */ - friend SLEIPNIR_DLLEXPORT ExpressionPtr operator+(const ExpressionPtr& lhs, - const ExpressionPtr& rhs) { -- using enum ExpressionType; -- - // Prune expression - if (lhs == nullptr || lhs->IsConstant(0.0)) { - return rhs; -@@ -316,7 +313,8 @@ struct SLEIPNIR_DLLEXPORT Expression { - } - - // Evaluate constant -- if (lhs->type == kConstant && rhs->type == kConstant) { -+ if (lhs->type == ExpressionType::kConstant && -+ rhs->type == ExpressionType::kConstant) { - return MakeExpressionPtr(lhs->value + rhs->value); - } - -@@ -340,8 +338,6 @@ struct SLEIPNIR_DLLEXPORT Expression { - */ - friend SLEIPNIR_DLLEXPORT ExpressionPtr operator-(const ExpressionPtr& lhs, - const ExpressionPtr& rhs) { -- using enum ExpressionType; -- - // Prune expression - if (lhs->IsConstant(0.0)) { - if (rhs->IsConstant(0.0)) { -@@ -355,7 +351,8 @@ struct SLEIPNIR_DLLEXPORT Expression { - } - - // Evaluate constant -- if (lhs->type == kConstant && rhs->type == kConstant) { -+ if (lhs->type == ExpressionType::kConstant && -+ rhs->type == ExpressionType::kConstant) { - return MakeExpressionPtr(lhs->value - rhs->value); - } - -@@ -377,8 +374,6 @@ struct SLEIPNIR_DLLEXPORT Expression { - * @param lhs Operand of unary minus. - */ - friend SLEIPNIR_DLLEXPORT ExpressionPtr operator-(const ExpressionPtr& lhs) { -- using enum ExpressionType; -- - // Prune expression - if (lhs->IsConstant(0.0)) { - // Return zero -@@ -386,7 +381,7 @@ struct SLEIPNIR_DLLEXPORT Expression { - } - - // Evaluate constant -- if (lhs->type == kConstant) { -+ if (lhs->type == ExpressionType::kConstant) { - return MakeExpressionPtr(-lhs->value); - } - -@@ -469,8 +464,6 @@ inline constexpr void IntrusiveSharedPtrDecRefCount(Expression* expr) { - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - // Return zero -@@ -478,12 +471,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::abs(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::abs(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::abs(x); }, - [](double x, double, double parentAdjoint) { - if (x < 0.0) { - return -parentAdjoint; -@@ -514,20 +507,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr acos( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - return MakeExpressionPtr(std::numbers::pi / 2.0); - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::acos(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::acos(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::acos(x); }, - [](double x, double, double parentAdjoint) { - return -parentAdjoint / std::sqrt(1.0 - x * x); - }, -@@ -546,8 +537,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr acos( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - // Return zero -@@ -555,12 +544,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::asin(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::asin(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::asin(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint / std::sqrt(1.0 - x * x); - }, -@@ -579,8 +568,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - // Return zero -@@ -588,12 +575,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::atan(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::atan(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::atan(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint / (1.0 + x * x); - }, -@@ -612,8 +599,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT - const ExpressionPtr& y, const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (y->IsConstant(0.0)) { - // Return zero -@@ -623,12 +608,14 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT - } - - // Evaluate constant -- if (y->type == kConstant && x->type == kConstant) { -+ if (y->type == ExpressionType::kConstant && -+ x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::atan2(y->value, x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double y, double x) { return std::atan2(y, x); }, -+ ExpressionType::kNonlinear, -+ [](double y, double x) { return std::atan2(y, x); }, - [](double y, double x, double parentAdjoint) { - return parentAdjoint * x / (y * y + x * x); - }, -@@ -653,20 +640,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr cos( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - return MakeExpressionPtr(1.0); - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::cos(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::cos(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::cos(x); }, - [](double x, double, double parentAdjoint) { - return -parentAdjoint * std::sin(x); - }, -@@ -684,20 +669,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cos( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr cosh( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - return MakeExpressionPtr(1.0); - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::cosh(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::cosh(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::cosh(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint * std::sinh(x); - }, -@@ -715,8 +698,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cosh( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - // Return zero -@@ -724,12 +705,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::erf(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::erf(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::erf(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint * 2.0 * std::numbers::inv_sqrtpi * - std::exp(-x * x); -@@ -750,20 +731,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr exp( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - return MakeExpressionPtr(1.0); - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::exp(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::exp(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::exp(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint * std::exp(x); - }, -@@ -782,8 +761,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr exp( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT - const ExpressionPtr& x, const ExpressionPtr& y) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - return y; -@@ -792,12 +769,14 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT - } - - // Evaluate constant -- if (x->type == kConstant && y->type == kConstant) { -+ if (x->type == ExpressionType::kConstant && -+ y->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::hypot(x->value, y->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double y) { return std::hypot(x, y); }, -+ ExpressionType::kNonlinear, -+ [](double x, double y) { return std::hypot(x, y); }, - [](double x, double y, double parentAdjoint) { - return parentAdjoint * x / std::hypot(x, y); - }, -@@ -822,8 +801,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - // Return zero -@@ -831,12 +808,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::log(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::log(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::log(x); }, - [](double x, double, double parentAdjoint) { return parentAdjoint / x; }, - [](const ExpressionPtr& x, const ExpressionPtr&, - const ExpressionPtr& parentAdjoint) { return parentAdjoint / x; }, -@@ -850,8 +827,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - // Return zero -@@ -859,12 +834,13 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::log10(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::log10(x); }, -+ ExpressionType::kNonlinear, -+ [](double x, double) { return std::log10(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint / (std::numbers::ln10 * x); - }, -@@ -883,8 +859,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT - const ExpressionPtr& base, const ExpressionPtr& power) { -- using enum ExpressionType; -- - // Prune expression - if (base->IsConstant(0.0)) { - // Return zero -@@ -899,12 +873,15 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT - } - - // Evaluate constant -- if (base->type == kConstant && power->type == kConstant) { -+ if (base->type == ExpressionType::kConstant && -+ power->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::pow(base->value, power->value)); - } - - return MakeExpressionPtr( -- base->type == kLinear && power->IsConstant(2.0) ? kQuadratic : kNonlinear, -+ base->type == ExpressionType::kLinear && power->IsConstant(2.0) -+ ? ExpressionType::kQuadratic -+ : ExpressionType::kNonlinear, - [](double base, double power) { return std::pow(base, power); }, - [](double base, double power, double parentAdjoint) { - return parentAdjoint * std::pow(base, power - 1) * power; -@@ -945,10 +922,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT - * @param x The argument. - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - if (x->value < 0.0) { - return MakeExpressionPtr(-1.0); - } else if (x->value == 0.0) { -@@ -960,7 +935,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { - } - - return MakeExpressionPtr( -- kNonlinear, -+ ExpressionType::kNonlinear, - [](double x, double) { - if (x < 0.0) { - return -1.0; -@@ -985,8 +960,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - // Return zero -@@ -994,12 +967,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::sin(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::sin(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::sin(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint * std::cos(x); - }, -@@ -1016,8 +989,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT - * @param x The argument. - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - // Return zero -@@ -1025,12 +996,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::sinh(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::sinh(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::sinh(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint * std::cosh(x); - }, -@@ -1048,10 +1019,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - if (x->value == 0.0) { - // Return zero - return x; -@@ -1063,7 +1032,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::sqrt(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::sqrt(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint / (2.0 * std::sqrt(x)); - }, -@@ -1082,8 +1051,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT - const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - // Return zero -@@ -1091,12 +1058,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::tan(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::tan(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::tan(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint / (std::cos(x) * std::cos(x)); - }, -@@ -1114,8 +1081,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT - * @param x The argument. - */ - SLEIPNIR_DLLEXPORT inline ExpressionPtr tanh(const ExpressionPtr& x) { -- using enum ExpressionType; -- - // Prune expression - if (x->IsConstant(0.0)) { - // Return zero -@@ -1123,12 +1088,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tanh(const ExpressionPtr& x) { - } - - // Evaluate constant -- if (x->type == kConstant) { -+ if (x->type == ExpressionType::kConstant) { - return MakeExpressionPtr(std::tanh(x->value)); - } - - return MakeExpressionPtr( -- kNonlinear, [](double x, double) { return std::tanh(x); }, -+ ExpressionType::kNonlinear, [](double x, double) { return std::tanh(x); }, - [](double x, double, double parentAdjoint) { - return parentAdjoint / (std::cosh(x) * std::cosh(x)); - }, -diff --git a/include/sleipnir/optimization/SolverExitCondition.hpp b/include/sleipnir/optimization/SolverExitCondition.hpp -index 7d1445297e33e3c62bcdf9d03eebeaad20af9a1c..734cd3d127327e8ce01e1a42fe74ccc81fea1f90 100644 ---- a/include/sleipnir/optimization/SolverExitCondition.hpp -+++ b/include/sleipnir/optimization/SolverExitCondition.hpp -@@ -46,31 +46,29 @@ enum class SolverExitCondition : int8_t { - */ - SLEIPNIR_DLLEXPORT constexpr std::string_view ToMessage( - const SolverExitCondition& exitCondition) { -- using enum SolverExitCondition; -- - switch (exitCondition) { -- case kSuccess: -+ case SolverExitCondition::kSuccess: - return "solved to desired tolerance"; -- case kSolvedToAcceptableTolerance: -+ case SolverExitCondition::kSolvedToAcceptableTolerance: - return "solved to acceptable tolerance"; -- case kCallbackRequestedStop: -+ case SolverExitCondition::kCallbackRequestedStop: - return "callback requested stop"; -- case kTooFewDOFs: -+ case SolverExitCondition::kTooFewDOFs: - return "problem has too few degrees of freedom"; -- case kLocallyInfeasible: -+ case SolverExitCondition::kLocallyInfeasible: - return "problem is locally infeasible"; -- case kFeasibilityRestorationFailed: -+ case SolverExitCondition::kFeasibilityRestorationFailed: - return "solver failed to reach the desired tolerance, and feasibility " - "restoration failed to converge"; -- case kNonfiniteInitialCostOrConstraints: -+ case SolverExitCondition::kNonfiniteInitialCostOrConstraints: - return "solver encountered nonfinite initial cost or constraints and " - "gave up"; -- case kDivergingIterates: -+ case SolverExitCondition::kDivergingIterates: - return "solver encountered diverging primal iterates xₖ and/or sₖ and " - "gave up"; -- case kMaxIterationsExceeded: -+ case SolverExitCondition::kMaxIterationsExceeded: - return "solution returned after maximum iterations exceeded"; -- case kTimeout: -+ case SolverExitCondition::kTimeout: - return "solution returned after maximum wall clock time exceeded"; - default: - return "unknown"; diff --git a/upstream_utils/sleipnir_patches/0002-Use-fmtlib.patch b/upstream_utils/sleipnir_patches/0001-Use-fmtlib.patch similarity index 98% rename from upstream_utils/sleipnir_patches/0002-Use-fmtlib.patch rename to upstream_utils/sleipnir_patches/0001-Use-fmtlib.patch index e5779dc71f0..deaaf7b5cb7 100644 --- a/upstream_utils/sleipnir_patches/0002-Use-fmtlib.patch +++ b/upstream_utils/sleipnir_patches/0001-Use-fmtlib.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 29 May 2024 16:29:55 -0700 -Subject: [PATCH 2/5] Use fmtlib +Subject: [PATCH 1/3] Use fmtlib --- include/.styleguide | 1 + diff --git a/upstream_utils/sleipnir_patches/0004-Use-wpi-SmallVector.patch b/upstream_utils/sleipnir_patches/0002-Use-wpi-SmallVector.patch similarity index 93% rename from upstream_utils/sleipnir_patches/0004-Use-wpi-SmallVector.patch rename to upstream_utils/sleipnir_patches/0002-Use-wpi-SmallVector.patch index 550983549db..61e887791c8 100644 --- a/upstream_utils/sleipnir_patches/0004-Use-wpi-SmallVector.patch +++ b/upstream_utils/sleipnir_patches/0002-Use-wpi-SmallVector.patch @@ -1,11 +1,11 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 16 Jun 2024 12:08:49 -0700 -Subject: [PATCH 4/5] Use wpi::SmallVector +Subject: [PATCH 2/3] Use wpi::SmallVector --- include/.styleguide | 1 + - include/sleipnir/autodiff/Expression.hpp | 5 +++-- + include/sleipnir/autodiff/Expression.hpp | 13 +++++++------ include/sleipnir/autodiff/ExpressionGraph.hpp | 15 ++++++++------- include/sleipnir/autodiff/Hessian.hpp | 4 ++-- include/sleipnir/autodiff/Jacobian.hpp | 10 +++++----- @@ -19,7 +19,7 @@ Subject: [PATCH 4/5] Use wpi::SmallVector src/optimization/solver/InteriorPoint.cpp | 4 ++-- .../solver/util/FeasibilityRestoration.hpp | 10 +++++----- src/optimization/solver/util/Filter.hpp | 4 ++-- - 15 files changed, 50 insertions(+), 44 deletions(-) + 15 files changed, 54 insertions(+), 48 deletions(-) diff --git a/include/.styleguide b/include/.styleguide index 6a7f8ed28f9cb037c9746a7e0ef5e110481d9825..efa36cee1fb593ae810032340c64f1854fbbc523 100644 @@ -32,7 +32,7 @@ index 6a7f8ed28f9cb037c9746a7e0ef5e110481d9825..efa36cee1fb593ae810032340c64f185 + ^wpi/ } diff --git a/include/sleipnir/autodiff/Expression.hpp b/include/sleipnir/autodiff/Expression.hpp -index dff8e2a6ef24413e3e6356bf0ec57286e50654cf..bdbeb4730223f88cfdc0c424a8f7b852b34742f7 100644 +index dd53755ccae88e3975d1b5e6b13ac464bd4efcce..ef9a15bf69d8cae6b2196513b72ec4b359cc8752 100644 --- a/include/sleipnir/autodiff/Expression.hpp +++ b/include/sleipnir/autodiff/Expression.hpp @@ -11,11 +11,12 @@ @@ -49,7 +49,33 @@ index dff8e2a6ef24413e3e6356bf0ec57286e50654cf..bdbeb4730223f88cfdc0c424a8f7b852 namespace sleipnir::detail { -@@ -427,7 +428,7 @@ inline void IntrusiveSharedPtrDecRefCount(Expression* expr) { +@@ -29,8 +30,8 @@ inline constexpr bool kUsePoolAllocator = true; + + struct SLEIPNIR_DLLEXPORT Expression; + +-inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr); +-inline constexpr void IntrusiveSharedPtrDecRefCount(Expression* expr); ++inline void IntrusiveSharedPtrIncRefCount(Expression* expr); ++inline void IntrusiveSharedPtrDecRefCount(Expression* expr); + + /** + * Typedef for intrusive shared pointer to Expression. +@@ -418,7 +419,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt(const ExpressionPtr& x); + * + * @param expr The shared pointer's managed object. + */ +-inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr) { ++inline void IntrusiveSharedPtrIncRefCount(Expression* expr) { + ++expr->refCount; + } + +@@ -427,12 +428,12 @@ inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr) { + * + * @param expr The shared pointer's managed object. + */ +-inline constexpr void IntrusiveSharedPtrDecRefCount(Expression* expr) { ++inline void IntrusiveSharedPtrDecRefCount(Expression* expr) { + // If a deeply nested tree is being deallocated all at once, calling the // Expression destructor when expr's refcount reaches zero can cause a stack // overflow. Instead, we iterate over its children to decrement their // refcounts and deallocate them. diff --git a/upstream_utils/sleipnir_patches/0003-Remove-unsupported-constexpr.patch b/upstream_utils/sleipnir_patches/0003-Remove-unsupported-constexpr.patch deleted file mode 100644 index 853c4d29883..00000000000 --- a/upstream_utils/sleipnir_patches/0003-Remove-unsupported-constexpr.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Tyler Veness -Date: Mon, 20 May 2024 09:01:54 -0700 -Subject: [PATCH 3/5] Remove unsupported constexpr - ---- - include/sleipnir/autodiff/Expression.hpp | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/include/sleipnir/autodiff/Expression.hpp b/include/sleipnir/autodiff/Expression.hpp -index 51070613e82cdf5e4105519f39632deb5d2bf19e..dff8e2a6ef24413e3e6356bf0ec57286e50654cf 100644 ---- a/include/sleipnir/autodiff/Expression.hpp -+++ b/include/sleipnir/autodiff/Expression.hpp -@@ -29,8 +29,8 @@ inline constexpr bool kUsePoolAllocator = true; - - struct SLEIPNIR_DLLEXPORT Expression; - --inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr); --inline constexpr void IntrusiveSharedPtrDecRefCount(Expression* expr); -+inline void IntrusiveSharedPtrIncRefCount(Expression* expr); -+inline void IntrusiveSharedPtrDecRefCount(Expression* expr); - - /** - * Typedef for intrusive shared pointer to Expression. -@@ -413,7 +413,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt(const ExpressionPtr& x); - * - * @param expr The shared pointer's managed object. - */ --inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr) { -+inline void IntrusiveSharedPtrIncRefCount(Expression* expr) { - ++expr->refCount; - } - -@@ -422,7 +422,7 @@ inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr) { - * - * @param expr The shared pointer's managed object. - */ --inline constexpr void IntrusiveSharedPtrDecRefCount(Expression* expr) { -+inline void IntrusiveSharedPtrDecRefCount(Expression* expr) { - // If a deeply nested tree is being deallocated all at once, calling the - // Expression destructor when expr's refcount reaches zero can cause a stack - // overflow. Instead, we iterate over its children to decrement their diff --git a/upstream_utils/sleipnir_patches/0005-Suppress-clang-tidy-false-positives.patch b/upstream_utils/sleipnir_patches/0003-Suppress-clang-tidy-false-positives.patch similarity index 96% rename from upstream_utils/sleipnir_patches/0005-Suppress-clang-tidy-false-positives.patch rename to upstream_utils/sleipnir_patches/0003-Suppress-clang-tidy-false-positives.patch index a7f3de198e1..90ae6e261bd 100644 --- a/upstream_utils/sleipnir_patches/0005-Suppress-clang-tidy-false-positives.patch +++ b/upstream_utils/sleipnir_patches/0003-Suppress-clang-tidy-false-positives.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 26 Jun 2024 12:13:33 -0700 -Subject: [PATCH 5/5] Suppress clang-tidy false positives +Subject: [PATCH 3/3] Suppress clang-tidy false positives --- include/sleipnir/autodiff/Variable.hpp | 4 ++-- diff --git a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/Expression.hpp b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/Expression.hpp index bdbeb473022..ef9a15bf69d 100644 --- a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/Expression.hpp +++ b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/Expression.hpp @@ -204,6 +204,8 @@ struct SLEIPNIR_DLLEXPORT Expression { */ friend SLEIPNIR_DLLEXPORT ExpressionPtr operator*(const ExpressionPtr& lhs, const ExpressionPtr& rhs) { + using enum ExpressionType; + // Prune expression if (lhs->IsConstant(0.0)) { // Return zero @@ -218,22 +220,20 @@ struct SLEIPNIR_DLLEXPORT Expression { } // Evaluate constant - if (lhs->type == ExpressionType::kConstant && - rhs->type == ExpressionType::kConstant) { + if (lhs->type == kConstant && rhs->type == kConstant) { return MakeExpressionPtr(lhs->value * rhs->value); } // Evaluate expression type ExpressionType type; - if (lhs->type == ExpressionType::kConstant) { + if (lhs->type == kConstant) { type = rhs->type; - } else if (rhs->type == ExpressionType::kConstant) { + } else if (rhs->type == kConstant) { type = lhs->type; - } else if (lhs->type == ExpressionType::kLinear && - rhs->type == ExpressionType::kLinear) { - type = ExpressionType::kQuadratic; + } else if (lhs->type == kLinear && rhs->type == kLinear) { + type = kQuadratic; } else { - type = ExpressionType::kNonlinear; + type = kNonlinear; } return MakeExpressionPtr( @@ -259,6 +259,8 @@ struct SLEIPNIR_DLLEXPORT Expression { */ friend SLEIPNIR_DLLEXPORT ExpressionPtr operator/(const ExpressionPtr& lhs, const ExpressionPtr& rhs) { + using enum ExpressionType; + // Prune expression if (lhs->IsConstant(0.0)) { // Return zero @@ -268,17 +270,16 @@ struct SLEIPNIR_DLLEXPORT Expression { } // Evaluate constant - if (lhs->type == ExpressionType::kConstant && - rhs->type == ExpressionType::kConstant) { + if (lhs->type == kConstant && rhs->type == kConstant) { return MakeExpressionPtr(lhs->value / rhs->value); } // Evaluate expression type ExpressionType type; - if (rhs->type == ExpressionType::kConstant) { + if (rhs->type == kConstant) { type = lhs->type; } else { - type = ExpressionType::kNonlinear; + type = kNonlinear; } return MakeExpressionPtr( @@ -306,6 +307,8 @@ struct SLEIPNIR_DLLEXPORT Expression { */ friend SLEIPNIR_DLLEXPORT ExpressionPtr operator+(const ExpressionPtr& lhs, const ExpressionPtr& rhs) { + using enum ExpressionType; + // Prune expression if (lhs == nullptr || lhs->IsConstant(0.0)) { return rhs; @@ -314,8 +317,7 @@ struct SLEIPNIR_DLLEXPORT Expression { } // Evaluate constant - if (lhs->type == ExpressionType::kConstant && - rhs->type == ExpressionType::kConstant) { + if (lhs->type == kConstant && rhs->type == kConstant) { return MakeExpressionPtr(lhs->value + rhs->value); } @@ -339,6 +341,8 @@ struct SLEIPNIR_DLLEXPORT Expression { */ friend SLEIPNIR_DLLEXPORT ExpressionPtr operator-(const ExpressionPtr& lhs, const ExpressionPtr& rhs) { + using enum ExpressionType; + // Prune expression if (lhs->IsConstant(0.0)) { if (rhs->IsConstant(0.0)) { @@ -352,8 +356,7 @@ struct SLEIPNIR_DLLEXPORT Expression { } // Evaluate constant - if (lhs->type == ExpressionType::kConstant && - rhs->type == ExpressionType::kConstant) { + if (lhs->type == kConstant && rhs->type == kConstant) { return MakeExpressionPtr(lhs->value - rhs->value); } @@ -375,6 +378,8 @@ struct SLEIPNIR_DLLEXPORT Expression { * @param lhs Operand of unary minus. */ friend SLEIPNIR_DLLEXPORT ExpressionPtr operator-(const ExpressionPtr& lhs) { + using enum ExpressionType; + // Prune expression if (lhs->IsConstant(0.0)) { // Return zero @@ -382,7 +387,7 @@ struct SLEIPNIR_DLLEXPORT Expression { } // Evaluate constant - if (lhs->type == ExpressionType::kConstant) { + if (lhs->type == kConstant) { return MakeExpressionPtr(-lhs->value); } @@ -465,6 +470,8 @@ inline void IntrusiveSharedPtrDecRefCount(Expression* expr) { */ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { // Return zero @@ -472,12 +479,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::abs(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::abs(x); }, + kNonlinear, [](double x, double) { return std::abs(x); }, [](double x, double, double parentAdjoint) { if (x < 0.0) { return -parentAdjoint; @@ -508,18 +515,20 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr acos( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { return MakeExpressionPtr(std::numbers::pi / 2.0); } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::acos(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::acos(x); }, + kNonlinear, [](double x, double) { return std::acos(x); }, [](double x, double, double parentAdjoint) { return -parentAdjoint / std::sqrt(1.0 - x * x); }, @@ -538,6 +547,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr acos( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { // Return zero @@ -545,12 +556,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::asin(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::asin(x); }, + kNonlinear, [](double x, double) { return std::asin(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint / std::sqrt(1.0 - x * x); }, @@ -569,6 +580,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { // Return zero @@ -576,12 +589,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::atan(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::atan(x); }, + kNonlinear, [](double x, double) { return std::atan(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint / (1.0 + x * x); }, @@ -600,6 +613,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT const ExpressionPtr& y, const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (y->IsConstant(0.0)) { // Return zero @@ -609,14 +624,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT } // Evaluate constant - if (y->type == ExpressionType::kConstant && - x->type == ExpressionType::kConstant) { + if (y->type == kConstant && x->type == kConstant) { return MakeExpressionPtr(std::atan2(y->value, x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, - [](double y, double x) { return std::atan2(y, x); }, + kNonlinear, [](double y, double x) { return std::atan2(y, x); }, [](double y, double x, double parentAdjoint) { return parentAdjoint * x / (y * y + x * x); }, @@ -641,18 +654,20 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr cos( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { return MakeExpressionPtr(1.0); } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::cos(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::cos(x); }, + kNonlinear, [](double x, double) { return std::cos(x); }, [](double x, double, double parentAdjoint) { return -parentAdjoint * std::sin(x); }, @@ -670,18 +685,20 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cos( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr cosh( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { return MakeExpressionPtr(1.0); } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::cosh(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::cosh(x); }, + kNonlinear, [](double x, double) { return std::cosh(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint * std::sinh(x); }, @@ -699,6 +716,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cosh( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { // Return zero @@ -706,12 +725,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::erf(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::erf(x); }, + kNonlinear, [](double x, double) { return std::erf(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint * 2.0 * std::numbers::inv_sqrtpi * std::exp(-x * x); @@ -732,18 +751,20 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr exp( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { return MakeExpressionPtr(1.0); } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::exp(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::exp(x); }, + kNonlinear, [](double x, double) { return std::exp(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint * std::exp(x); }, @@ -762,6 +783,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr exp( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT const ExpressionPtr& x, const ExpressionPtr& y) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { return y; @@ -770,14 +793,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT } // Evaluate constant - if (x->type == ExpressionType::kConstant && - y->type == ExpressionType::kConstant) { + if (x->type == kConstant && y->type == kConstant) { return MakeExpressionPtr(std::hypot(x->value, y->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, - [](double x, double y) { return std::hypot(x, y); }, + kNonlinear, [](double x, double y) { return std::hypot(x, y); }, [](double x, double y, double parentAdjoint) { return parentAdjoint * x / std::hypot(x, y); }, @@ -802,6 +823,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { // Return zero @@ -809,12 +832,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::log(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::log(x); }, + kNonlinear, [](double x, double) { return std::log(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint / x; }, [](const ExpressionPtr& x, const ExpressionPtr&, const ExpressionPtr& parentAdjoint) { return parentAdjoint / x; }, @@ -828,6 +851,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { // Return zero @@ -835,13 +860,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::log10(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, - [](double x, double) { return std::log10(x); }, + kNonlinear, [](double x, double) { return std::log10(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint / (std::numbers::ln10 * x); }, @@ -860,6 +884,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT const ExpressionPtr& base, const ExpressionPtr& power) { + using enum ExpressionType; + // Prune expression if (base->IsConstant(0.0)) { // Return zero @@ -874,15 +900,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT } // Evaluate constant - if (base->type == ExpressionType::kConstant && - power->type == ExpressionType::kConstant) { + if (base->type == kConstant && power->type == kConstant) { return MakeExpressionPtr(std::pow(base->value, power->value)); } return MakeExpressionPtr( - base->type == ExpressionType::kLinear && power->IsConstant(2.0) - ? ExpressionType::kQuadratic - : ExpressionType::kNonlinear, + base->type == kLinear && power->IsConstant(2.0) ? kQuadratic : kNonlinear, [](double base, double power) { return std::pow(base, power); }, [](double base, double power, double parentAdjoint) { return parentAdjoint * std::pow(base, power - 1) * power; @@ -923,8 +946,10 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT * @param x The argument. */ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { + using enum ExpressionType; + // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { if (x->value < 0.0) { return MakeExpressionPtr(-1.0); } else if (x->value == 0.0) { @@ -936,7 +961,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { } return MakeExpressionPtr( - ExpressionType::kNonlinear, + kNonlinear, [](double x, double) { if (x < 0.0) { return -1.0; @@ -961,6 +986,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) { */ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { // Return zero @@ -968,12 +995,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::sin(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::sin(x); }, + kNonlinear, [](double x, double) { return std::sin(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint * std::cos(x); }, @@ -990,6 +1017,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT * @param x The argument. */ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { // Return zero @@ -997,12 +1026,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::sinh(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::sinh(x); }, + kNonlinear, [](double x, double) { return std::sinh(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint * std::cosh(x); }, @@ -1020,8 +1049,10 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) { */ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { if (x->value == 0.0) { // Return zero return x; @@ -1033,7 +1064,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::sqrt(x); }, + kNonlinear, [](double x, double) { return std::sqrt(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint / (2.0 * std::sqrt(x)); }, @@ -1052,6 +1083,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT */ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { // Return zero @@ -1059,12 +1092,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::tan(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::tan(x); }, + kNonlinear, [](double x, double) { return std::tan(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint / (std::cos(x) * std::cos(x)); }, @@ -1082,6 +1115,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT * @param x The argument. */ SLEIPNIR_DLLEXPORT inline ExpressionPtr tanh(const ExpressionPtr& x) { + using enum ExpressionType; + // Prune expression if (x->IsConstant(0.0)) { // Return zero @@ -1089,12 +1124,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tanh(const ExpressionPtr& x) { } // Evaluate constant - if (x->type == ExpressionType::kConstant) { + if (x->type == kConstant) { return MakeExpressionPtr(std::tanh(x->value)); } return MakeExpressionPtr( - ExpressionType::kNonlinear, [](double x, double) { return std::tanh(x); }, + kNonlinear, [](double x, double) { return std::tanh(x); }, [](double x, double, double parentAdjoint) { return parentAdjoint / (std::cosh(x) * std::cosh(x)); }, diff --git a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/optimization/SolverExitCondition.hpp b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/optimization/SolverExitCondition.hpp index 734cd3d1273..7d1445297e3 100644 --- a/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/optimization/SolverExitCondition.hpp +++ b/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/optimization/SolverExitCondition.hpp @@ -46,29 +46,31 @@ enum class SolverExitCondition : int8_t { */ SLEIPNIR_DLLEXPORT constexpr std::string_view ToMessage( const SolverExitCondition& exitCondition) { + using enum SolverExitCondition; + switch (exitCondition) { - case SolverExitCondition::kSuccess: + case kSuccess: return "solved to desired tolerance"; - case SolverExitCondition::kSolvedToAcceptableTolerance: + case kSolvedToAcceptableTolerance: return "solved to acceptable tolerance"; - case SolverExitCondition::kCallbackRequestedStop: + case kCallbackRequestedStop: return "callback requested stop"; - case SolverExitCondition::kTooFewDOFs: + case kTooFewDOFs: return "problem has too few degrees of freedom"; - case SolverExitCondition::kLocallyInfeasible: + case kLocallyInfeasible: return "problem is locally infeasible"; - case SolverExitCondition::kFeasibilityRestorationFailed: + case kFeasibilityRestorationFailed: return "solver failed to reach the desired tolerance, and feasibility " "restoration failed to converge"; - case SolverExitCondition::kNonfiniteInitialCostOrConstraints: + case kNonfiniteInitialCostOrConstraints: return "solver encountered nonfinite initial cost or constraints and " "gave up"; - case SolverExitCondition::kDivergingIterates: + case kDivergingIterates: return "solver encountered diverging primal iterates xₖ and/or sₖ and " "gave up"; - case SolverExitCondition::kMaxIterationsExceeded: + case kMaxIterationsExceeded: return "solution returned after maximum iterations exceeded"; - case SolverExitCondition::kTimeout: + case kTimeout: return "solution returned after maximum wall clock time exceeded"; default: return "unknown";