[upstream_utils] Upgrade Sleipnir to fix unused parameter warnings (#6803)

This commit is contained in:
Tyler Veness
2024-07-07 06:43:44 -07:00
committed by GitHub
parent 32ed9c5f0b
commit 6478ba6e3f
20 changed files with 342 additions and 212 deletions

View File

@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Wed, 24 Apr 2024 15:56:06 -0700
Subject: [PATCH 1/4] Remove "using enum" declarations
Subject: [PATCH 1/5] Remove "using enum" declarations
---
include/sleipnir/autodiff/Expression.hpp | 161 +++++++-----------
@@ -9,7 +9,7 @@ Subject: [PATCH 1/4] Remove "using enum" declarations
2 files changed, 73 insertions(+), 110 deletions(-)
diff --git a/include/sleipnir/autodiff/Expression.hpp b/include/sleipnir/autodiff/Expression.hpp
index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d943a09f910 100644
index 6c4ae6269f13b7d1b5c9b0281de1a4b0dc890baf..065b28e790db32234042bcc94d9a1dac597dee86 100644
--- a/include/sleipnir/autodiff/Expression.hpp
+++ b/include/sleipnir/autodiff/Expression.hpp
@@ -191,8 +191,6 @@ struct SLEIPNIR_DLLEXPORT Expression {
@@ -99,7 +99,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
return MakeExpressionPtr(lhs->value + rhs->value);
}
@@ -332,8 +330,6 @@ struct SLEIPNIR_DLLEXPORT Expression {
@@ -328,8 +326,6 @@ struct SLEIPNIR_DLLEXPORT Expression {
*/
friend SLEIPNIR_DLLEXPORT ExpressionPtr operator-(const ExpressionPtr& lhs,
const ExpressionPtr& rhs) {
@@ -108,7 +108,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (lhs->IsConstant(0.0)) {
if (rhs->IsConstant(0.0)) {
@@ -347,7 +343,8 @@ struct SLEIPNIR_DLLEXPORT Expression {
@@ -343,7 +339,8 @@ struct SLEIPNIR_DLLEXPORT Expression {
}
// Evaluate constant
@@ -118,7 +118,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
return MakeExpressionPtr(lhs->value - rhs->value);
}
@@ -373,8 +370,6 @@ struct SLEIPNIR_DLLEXPORT Expression {
@@ -365,8 +362,6 @@ struct SLEIPNIR_DLLEXPORT Expression {
* @param lhs Operand of unary minus.
*/
friend SLEIPNIR_DLLEXPORT ExpressionPtr operator-(const ExpressionPtr& lhs) {
@@ -127,7 +127,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (lhs->IsConstant(0.0)) {
// Return zero
@@ -382,7 +377,7 @@ struct SLEIPNIR_DLLEXPORT Expression {
@@ -374,7 +369,7 @@ struct SLEIPNIR_DLLEXPORT Expression {
}
// Evaluate constant
@@ -136,7 +136,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
return MakeExpressionPtr(-lhs->value);
}
@@ -463,8 +458,6 @@ inline constexpr void IntrusiveSharedPtrDecRefCount(Expression* expr) {
@@ -455,8 +450,6 @@ inline constexpr void IntrusiveSharedPtrDecRefCount(Expression* expr) {
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT
const ExpressionPtr& x) {
@@ -145,7 +145,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
// Return zero
@@ -472,12 +465,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT
@@ -464,12 +457,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT
}
// Evaluate constant
@@ -160,7 +160,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
if (x < 0.0) {
return -parentAdjoint;
@@ -508,20 +501,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT
@@ -500,20 +493,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr abs( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr acos( // NOLINT
const ExpressionPtr& x) {
@@ -183,7 +183,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return -parentAdjoint / std::sqrt(1.0 - x * x);
},
@@ -540,8 +531,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr acos( // NOLINT
@@ -532,8 +523,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr acos( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT
const ExpressionPtr& x) {
@@ -192,7 +192,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
// Return zero
@@ -549,12 +538,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT
@@ -541,12 +530,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT
}
// Evaluate constant
@@ -207,7 +207,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return parentAdjoint / std::sqrt(1.0 - x * x);
},
@@ -573,8 +562,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT
@@ -565,8 +554,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr asin( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT
const ExpressionPtr& x) {
@@ -216,7 +216,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
// Return zero
@@ -582,12 +569,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT
@@ -574,12 +561,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT
}
// Evaluate constant
@@ -231,7 +231,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return parentAdjoint / (1.0 + x * x);
},
@@ -606,8 +593,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT
@@ -598,8 +585,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT
const ExpressionPtr& y, const ExpressionPtr& x) {
@@ -240,7 +240,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (y->IsConstant(0.0)) {
// Return zero
@@ -617,12 +602,14 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT
@@ -609,12 +594,14 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT
}
// Evaluate constant
@@ -257,7 +257,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double y, double x, double parentAdjoint) {
return parentAdjoint * x / (y * y + x * x);
},
@@ -647,20 +634,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT
@@ -639,20 +626,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr atan2( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr cos( // NOLINT
const ExpressionPtr& x) {
@@ -280,7 +280,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return -parentAdjoint * std::sin(x);
},
@@ -678,20 +663,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cos( // NOLINT
@@ -670,20 +655,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cos( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr cosh( // NOLINT
const ExpressionPtr& x) {
@@ -303,7 +303,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return parentAdjoint * std::sinh(x);
},
@@ -709,8 +692,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cosh( // NOLINT
@@ -701,8 +684,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr cosh( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT
const ExpressionPtr& x) {
@@ -312,7 +312,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
// Return zero
@@ -718,12 +699,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT
@@ -710,12 +691,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT
}
// Evaluate constant
@@ -327,7 +327,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return parentAdjoint * 2.0 * std::numbers::inv_sqrtpi *
std::exp(-x * x);
@@ -744,20 +725,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT
@@ -736,20 +717,18 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr erf( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr exp( // NOLINT
const ExpressionPtr& x) {
@@ -350,7 +350,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return parentAdjoint * std::exp(x);
},
@@ -776,8 +755,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr exp( // NOLINT
@@ -768,8 +747,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr exp( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT
const ExpressionPtr& x, const ExpressionPtr& y) {
@@ -359,7 +359,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
return y;
@@ -786,12 +763,14 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT
@@ -778,12 +755,14 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT
}
// Evaluate constant
@@ -376,7 +376,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double y, double parentAdjoint) {
return parentAdjoint * x / std::hypot(x, y);
},
@@ -816,8 +795,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT
@@ -808,8 +787,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr hypot( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT
const ExpressionPtr& x) {
@@ -385,7 +385,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
// Return zero
@@ -825,12 +802,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT
@@ -817,12 +794,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT
}
// Evaluate constant
@@ -400,7 +400,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) { return parentAdjoint / x; },
[](const ExpressionPtr& x, const ExpressionPtr&,
const ExpressionPtr& parentAdjoint) { return parentAdjoint / x; },
@@ -844,8 +821,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT
@@ -836,8 +813,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT
const ExpressionPtr& x) {
@@ -409,7 +409,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
// Return zero
@@ -853,12 +828,13 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT
@@ -845,12 +820,13 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT
}
// Evaluate constant
@@ -425,7 +425,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return parentAdjoint / (std::numbers::ln10 * x);
},
@@ -877,8 +853,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT
@@ -869,8 +845,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr log10( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT
const ExpressionPtr& base, const ExpressionPtr& power) {
@@ -434,7 +434,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (base->IsConstant(0.0)) {
// Return zero
@@ -893,12 +867,15 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT
@@ -885,12 +859,15 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT
}
// Evaluate constant
@@ -452,7 +452,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double base, double power) { return std::pow(base, power); },
[](double base, double power, double parentAdjoint) {
return parentAdjoint * std::pow(base, power - 1) * power;
@@ -939,10 +916,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT
@@ -931,10 +908,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr pow( // NOLINT
* @param x The argument.
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) {
@@ -464,7 +464,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
if (x->value < 0.0) {
return MakeExpressionPtr(-1.0);
} else if (x->value == 0.0) {
@@ -954,7 +929,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) {
@@ -946,7 +921,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) {
}
return MakeExpressionPtr(
@@ -473,7 +473,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double) {
if (x < 0.0) {
return -1.0;
@@ -980,8 +955,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) {
@@ -971,8 +946,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) {
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT
const ExpressionPtr& x) {
@@ -482,7 +482,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
// Return zero
@@ -989,12 +962,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT
@@ -980,12 +953,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT
}
// Evaluate constant
@@ -497,7 +497,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return parentAdjoint * std::cos(x);
},
@@ -1011,8 +984,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT
@@ -1002,8 +975,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sin( // NOLINT
* @param x The argument.
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) {
@@ -506,7 +506,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
// Return zero
@@ -1020,12 +991,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) {
@@ -1011,12 +982,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) {
}
// Evaluate constant
@@ -521,7 +521,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return parentAdjoint * std::cosh(x);
},
@@ -1043,10 +1014,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) {
@@ -1034,10 +1005,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sinh(const ExpressionPtr& x) {
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT
const ExpressionPtr& x) {
@@ -533,7 +533,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
if (x->value == 0.0) {
// Return zero
return x;
@@ -1058,7 +1027,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT
@@ -1049,7 +1018,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT
}
return MakeExpressionPtr(
@@ -542,7 +542,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return parentAdjoint / (2.0 * std::sqrt(x));
},
@@ -1077,8 +1046,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT
@@ -1068,8 +1037,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt( // NOLINT
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT
const ExpressionPtr& x) {
@@ -551,7 +551,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
// Return zero
@@ -1086,12 +1053,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT
@@ -1077,12 +1044,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT
}
// Evaluate constant
@@ -566,7 +566,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
[](double x, double, double parentAdjoint) {
return parentAdjoint / (std::cos(x) * std::cos(x));
},
@@ -1109,8 +1076,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT
@@ -1100,8 +1067,6 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tan( // NOLINT
* @param x The argument.
*/
SLEIPNIR_DLLEXPORT inline ExpressionPtr tanh(const ExpressionPtr& x) {
@@ -575,7 +575,7 @@ index 99997da577f5d4de81dc0c6de3cc7225676f5aa3..0f306e3b2dccbe63367be7856d051d94
// Prune expression
if (x->IsConstant(0.0)) {
// Return zero
@@ -1118,12 +1083,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tanh(const ExpressionPtr& x) {
@@ -1109,12 +1074,12 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr tanh(const ExpressionPtr& x) {
}
// Evaluate constant

View File

@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Wed, 29 May 2024 16:29:55 -0700
Subject: [PATCH 2/4] Use fmtlib
Subject: [PATCH 2/5] Use fmtlib
---
include/.styleguide | 1 +

View File

@@ -1,14 +1,14 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Mon, 20 May 2024 09:01:54 -0700
Subject: [PATCH 3/4] Remove unsupported constexpr
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 0f306e3b2dccbe63367be7856d051d943a09f910..758433270a1cbe1b33f8b41d3e971b58de711e18 100644
index 065b28e790db32234042bcc94d9a1dac597dee86..e65b689559d01324fc4218c26144521832719025 100644
--- a/include/sleipnir/autodiff/Expression.hpp
+++ b/include/sleipnir/autodiff/Expression.hpp
@@ -21,8 +21,8 @@ namespace sleipnir::detail {
@@ -22,7 +22,7 @@ index 0f306e3b2dccbe63367be7856d051d943a09f910..758433270a1cbe1b33f8b41d3e971b58
/**
* Typedef for intrusive shared pointer to Expression.
@@ -409,7 +409,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt(const ExpressionPtr& x);
@@ -401,7 +401,7 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sqrt(const ExpressionPtr& x);
*
* @param expr The shared pointer's managed object.
*/
@@ -31,7 +31,7 @@ index 0f306e3b2dccbe63367be7856d051d943a09f910..758433270a1cbe1b33f8b41d3e971b58
++expr->refCount;
}
@@ -418,7 +418,7 @@ inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr) {
@@ -410,7 +410,7 @@ inline constexpr void IntrusiveSharedPtrIncRefCount(Expression* expr) {
*
* @param expr The shared pointer's managed object.
*/

View File

@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Sun, 16 Jun 2024 12:08:49 -0700
Subject: [PATCH 4/4] Use wpi::SmallVector
Subject: [PATCH 4/5] Use wpi::SmallVector
---
include/.styleguide | 1 +
@@ -32,7 +32,7 @@ index 6a7f8ed28f9cb037c9746a7e0ef5e110481d9825..efa36cee1fb593ae810032340c64f185
+ ^wpi/
}
diff --git a/include/sleipnir/autodiff/Expression.hpp b/include/sleipnir/autodiff/Expression.hpp
index 758433270a1cbe1b33f8b41d3e971b58de711e18..f9be904cf289ad5f5538d9c91b7f2e96ea7d3ab2 100644
index e65b689559d01324fc4218c26144521832719025..2be666e7c87731d2633576d4a066efba4906502d 100644
--- a/include/sleipnir/autodiff/Expression.hpp
+++ b/include/sleipnir/autodiff/Expression.hpp
@@ -11,11 +11,12 @@
@@ -49,7 +49,7 @@ index 758433270a1cbe1b33f8b41d3e971b58de711e18..f9be904cf289ad5f5538d9c91b7f2e96
namespace sleipnir::detail {
@@ -423,7 +424,7 @@ inline void IntrusiveSharedPtrDecRefCount(Expression* expr) {
@@ -415,7 +416,7 @@ inline void IntrusiveSharedPtrDecRefCount(Expression* expr) {
// 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.
@@ -59,7 +59,7 @@ index 758433270a1cbe1b33f8b41d3e971b58de711e18..f9be904cf289ad5f5538d9c91b7f2e96
while (!stack.empty()) {
diff --git a/include/sleipnir/autodiff/ExpressionGraph.hpp b/include/sleipnir/autodiff/ExpressionGraph.hpp
index 56fe6bd5734ce2eec43f3c4c3e70c2ed41b32a21..4683089037271df7bcf0894f5a158c6c4607fe87 100644
index c614195d82ad022dfd0c3f6f8240b042c0056c2f..714bcbb82907e754138347334c7fca8a7ccf055d 100644
--- a/include/sleipnir/autodiff/ExpressionGraph.hpp
+++ b/include/sleipnir/autodiff/ExpressionGraph.hpp
@@ -4,10 +4,11 @@
@@ -197,7 +197,7 @@ index ac00c11ef8c947cbe95c58081bdbfb42bf901051..0c660156c80f94539383b8f0d01d7853
Profiler m_profiler;
};
diff --git a/include/sleipnir/autodiff/VariableMatrix.hpp b/include/sleipnir/autodiff/VariableMatrix.hpp
index f080a877a482d8a45a56ff38a0b969ef81b5809d..e691e209afed43d9384c2828243972d41e59ed59 100644
index a7e89e5d7a24fb1295eb3ff04d8f22824c0884f1..bac9fe4f5ecf08bb4c0e3dfa8822125bcf854803 100644
--- a/include/sleipnir/autodiff/VariableMatrix.hpp
+++ b/include/sleipnir/autodiff/VariableMatrix.hpp
@@ -11,13 +11,13 @@
@@ -225,12 +225,12 @@ index f080a877a482d8a45a56ff38a0b969ef81b5809d..e691e209afed43d9384c2828243972d4
int m_cols = 0;
};
diff --git a/include/sleipnir/optimization/Constraints.hpp b/include/sleipnir/optimization/Constraints.hpp
index 3b7315a851eff59dabc9a11334d09ef0b7337881..a33039b8996ded92014fa96dfacc9c80fd612c79 100644
index 80da66bfef55bfc54cfdcd0478432658f60f7610..b940fcc4deb76c282b27564332db5e5935fbfbc6 100644
--- a/include/sleipnir/optimization/Constraints.hpp
+++ b/include/sleipnir/optimization/Constraints.hpp
@@ -6,11 +6,12 @@
#include <concepts>
@@ -8,11 +8,12 @@
#include <type_traits>
#include <vector>
+#include <wpi/SmallVector.h>
+
@@ -242,7 +242,7 @@ index 3b7315a851eff59dabc9a11334d09ef0b7337881..a33039b8996ded92014fa96dfacc9c80
namespace sleipnir {
@@ -30,8 +31,8 @@ template <typename LHS, typename RHS>
@@ -32,8 +33,8 @@ template <typename LHS, typename RHS>
(ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) &&
(!std::same_as<std::decay_t<LHS>, double> ||
!std::same_as<std::decay_t<RHS>, double>)
@@ -253,7 +253,7 @@ index 3b7315a851eff59dabc9a11334d09ef0b7337881..a33039b8996ded92014fa96dfacc9c80
if constexpr (ScalarLike<std::decay_t<LHS>> &&
ScalarLike<std::decay_t<RHS>>) {
@@ -119,7 +120,7 @@ small_vector<Variable> MakeConstraints(LHS&& lhs, RHS&& rhs) {
@@ -121,7 +122,7 @@ small_vector<Variable> MakeConstraints(LHS&& lhs, RHS&& rhs) {
*/
struct SLEIPNIR_DLLEXPORT EqualityConstraints {
/// A vector of scalar equality constraints.
@@ -261,8 +261,8 @@ index 3b7315a851eff59dabc9a11334d09ef0b7337881..a33039b8996ded92014fa96dfacc9c80
+ wpi::SmallVector<Variable> constraints;
/**
* Constructs an equality constraint from a left and right side.
@@ -153,7 +154,7 @@ struct SLEIPNIR_DLLEXPORT EqualityConstraints {
* Concatenates multiple equality constraints.
@@ -183,7 +184,7 @@ struct SLEIPNIR_DLLEXPORT EqualityConstraints {
*/
struct SLEIPNIR_DLLEXPORT InequalityConstraints {
/// A vector of scalar inequality constraints.
@@ -270,9 +270,9 @@ index 3b7315a851eff59dabc9a11334d09ef0b7337881..a33039b8996ded92014fa96dfacc9c80
+ wpi::SmallVector<Variable> constraints;
/**
* Constructs an inequality constraint from a left and right side.
* Concatenates multiple inequality constraints.
diff --git a/include/sleipnir/optimization/Multistart.hpp b/include/sleipnir/optimization/Multistart.hpp
index d905cafd5fce57dc53665caf50997ada00db4ebe..6935590a75db6eb3f1ecbd35c805cb7849bc3d9c 100644
index 8055713a2492a9c8473f047a2fb9fe7ca57753c3..09b1b2f3bf33c35ae0aeddb9b5d47c0d80c68cec 100644
--- a/include/sleipnir/optimization/Multistart.hpp
+++ b/include/sleipnir/optimization/Multistart.hpp
@@ -6,9 +6,10 @@
@@ -287,8 +287,8 @@ index d905cafd5fce57dc53665caf50997ada00db4ebe..6935590a75db6eb3f1ecbd35c805cb78
namespace sleipnir {
@@ -43,14 +44,14 @@ MultistartResult<DecisionVariables> Multistart(
function_ref<MultistartResult<DecisionVariables>(const DecisionVariables&)>
@@ -44,14 +45,14 @@ MultistartResult<DecisionVariables> Multistart(
const DecisionVariables& initialGuess)>
solve,
std::span<const DecisionVariables> initialGuesses) {
- small_vector<std::future<MultistartResult<DecisionVariables>>> futures;
@@ -305,10 +305,10 @@ index d905cafd5fce57dc53665caf50997ada00db4ebe..6935590a75db6eb3f1ecbd35c805cb78
for (auto& future : futures) {
diff --git a/include/sleipnir/optimization/OptimizationProblem.hpp b/include/sleipnir/optimization/OptimizationProblem.hpp
index 32ef0bf6fb0cbcba84c82031644e935a44815ed2..7dc4c50b035b1848b9b0177d10a4445a021a744e 100644
index 7d387e02af386a3cbfaf0294d5be78e73fb05628..b78b3761898088235cf335bf5cc111f4cafbe29a 100644
--- a/include/sleipnir/optimization/OptimizationProblem.hpp
+++ b/include/sleipnir/optimization/OptimizationProblem.hpp
@@ -12,6 +12,7 @@
@@ -11,6 +11,7 @@
#include <utility>
#include <Eigen/Core>
@@ -316,7 +316,7 @@ index 32ef0bf6fb0cbcba84c82031644e935a44815ed2..7dc4c50b035b1848b9b0177d10a4445a
#include "sleipnir/autodiff/Variable.hpp"
#include "sleipnir/autodiff/VariableMatrix.hpp"
@@ -23,7 +24,6 @@
@@ -22,7 +23,6 @@
#include "sleipnir/optimization/solver/InteriorPoint.hpp"
#include "sleipnir/util/Print.hpp"
#include "sleipnir/util/SymbolExports.hpp"
@@ -324,7 +324,7 @@ index 32ef0bf6fb0cbcba84c82031644e935a44815ed2..7dc4c50b035b1848b9b0177d10a4445a
namespace sleipnir {
@@ -360,16 +360,16 @@ class SLEIPNIR_DLLEXPORT OptimizationProblem {
@@ -359,16 +359,16 @@ class SLEIPNIR_DLLEXPORT OptimizationProblem {
private:
// The list of decision variables, which are the root of the problem's
// expression tree
@@ -343,9 +343,9 @@ index 32ef0bf6fb0cbcba84c82031644e935a44815ed2..7dc4c50b035b1848b9b0177d10a4445a
+ wpi::SmallVector<Variable> m_inequalityConstraints;
// The user callback
std::function<bool(const SolverIterationInfo&)> m_callback =
std::function<bool(const SolverIterationInfo& info)> m_callback =
diff --git a/include/sleipnir/util/Pool.hpp b/include/sleipnir/util/Pool.hpp
index 02d8e190178973a1e2edc94225754fb6e2199bf4..95b4d2e97e05b5983720e4abd87f1dbb973dd7f4 100644
index 441fa701d4972bc14973c6269d56d4a124deaee5..1951bd1ee8f3bee8d4a3c044c99354b0fd10031d 100644
--- a/include/sleipnir/util/Pool.hpp
+++ b/include/sleipnir/util/Pool.hpp
@@ -5,8 +5,9 @@
@@ -359,7 +359,7 @@ index 02d8e190178973a1e2edc94225754fb6e2199bf4..95b4d2e97e05b5983720e4abd87f1dbb
namespace sleipnir {
@@ -76,8 +77,8 @@ class SLEIPNIR_DLLEXPORT PoolResource {
@@ -78,8 +79,8 @@ class SLEIPNIR_DLLEXPORT PoolResource {
}
private:
@@ -405,7 +405,7 @@ index f3b2f0cf9e60b3a86b9654ff2b381f9c48734ff6..ad739cea6dce6f6cb586f538d1d30b92
+ ^wpi/
}
diff --git a/src/optimization/solver/InteriorPoint.cpp b/src/optimization/solver/InteriorPoint.cpp
index 0d3c8fa23b113a8ae42ae17dc3a8daa5b017cfb2..06187b7260182f02860b1419727b2ca71ff48c9a 100644
index 817e3d1dcb808c36192ea5b483eee1a08dbb5e2f..1470eb235bfdac363557c207ac0eaedb6c73d295 100644
--- a/src/optimization/solver/InteriorPoint.cpp
+++ b/src/optimization/solver/InteriorPoint.cpp
@@ -9,6 +9,7 @@
@@ -434,7 +434,7 @@ index 0d3c8fa23b113a8ae42ae17dc3a8daa5b017cfb2..06187b7260182f02860b1419727b2ca7
RegularizedLDLT solver;
diff --git a/src/optimization/solver/util/FeasibilityRestoration.hpp b/src/optimization/solver/util/FeasibilityRestoration.hpp
index 37adf64ea483b1acd4a4d5db8697e1b2fc701e72..76af452517d75ae67e0511584c89f99c552989af 100644
index c324ef093cc7dc8ce93af2cba337042a65b28475..0f13676aea0e80549ef1ef43e4972d5498acaa18 100644
--- a/src/optimization/solver/util/FeasibilityRestoration.hpp
+++ b/src/optimization/solver/util/FeasibilityRestoration.hpp
@@ -8,6 +8,7 @@
@@ -453,7 +453,7 @@ index 37adf64ea483b1acd4a4d5db8697e1b2fc701e72..76af452517d75ae67e0511584c89f99c
namespace sleipnir {
@@ -66,7 +66,7 @@ inline void FeasibilityRestoration(
@@ -65,7 +65,7 @@ inline void FeasibilityRestoration(
constexpr double ρ = 1000.0;
@@ -462,7 +462,7 @@ index 37adf64ea483b1acd4a4d5db8697e1b2fc701e72..76af452517d75ae67e0511584c89f99c
fr_decisionVariables.reserve(decisionVariables.size() +
2 * equalityConstraints.size() +
2 * inequalityConstraints.size());
@@ -82,7 +82,7 @@ inline void FeasibilityRestoration(
@@ -81,7 +81,7 @@ inline void FeasibilityRestoration(
fr_decisionVariables.emplace_back();
}
@@ -471,7 +471,7 @@ index 37adf64ea483b1acd4a4d5db8697e1b2fc701e72..76af452517d75ae67e0511584c89f99c
VariableMatrix xAD{std::span{it, it + decisionVariables.size()}};
it += decisionVariables.size();
@@ -158,7 +158,7 @@ inline void FeasibilityRestoration(
@@ -157,7 +157,7 @@ inline void FeasibilityRestoration(
}
// cₑ(x) - pₑ + nₑ = 0
@@ -480,7 +480,7 @@ index 37adf64ea483b1acd4a4d5db8697e1b2fc701e72..76af452517d75ae67e0511584c89f99c
fr_equalityConstraints.assign(equalityConstraints.begin(),
equalityConstraints.end());
for (size_t row = 0; row < fr_equalityConstraints.size(); ++row) {
@@ -167,7 +167,7 @@ inline void FeasibilityRestoration(
@@ -166,7 +166,7 @@ inline void FeasibilityRestoration(
}
// cᵢ(x) - s - pᵢ + nᵢ = 0

View File

@@ -0,0 +1,31 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Wed, 26 Jun 2024 12:13:33 -0700
Subject: [PATCH 5/5] Suppress clang-tidy false positives
---
include/sleipnir/optimization/Constraints.hpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/sleipnir/optimization/Constraints.hpp b/include/sleipnir/optimization/Constraints.hpp
index b940fcc4deb76c282b27564332db5e5935fbfbc6..f3eb8a276ded38cd3918c18810ddaa61590625c9 100644
--- a/include/sleipnir/optimization/Constraints.hpp
+++ b/include/sleipnir/optimization/Constraints.hpp
@@ -129,7 +129,7 @@ struct SLEIPNIR_DLLEXPORT EqualityConstraints {
*
* @param equalityConstraints The list of EqualityConstraints to concatenate.
*/
- EqualityConstraints(
+ EqualityConstraints( // NOLINT
std::initializer_list<EqualityConstraints> equalityConstraints) {
for (const auto& elem : equalityConstraints) {
constraints.insert(constraints.end(), elem.constraints.begin(),
@@ -192,7 +192,7 @@ struct SLEIPNIR_DLLEXPORT InequalityConstraints {
* @param inequalityConstraints The list of InequalityConstraints to
* concatenate.
*/
- InequalityConstraints(
+ InequalityConstraints( // NOLINT
std::initializer_list<InequalityConstraints> inequalityConstraints) {
for (const auto& elem : inequalityConstraints) {
constraints.insert(constraints.end(), elem.constraints.begin(),

View File

@@ -15,8 +15,8 @@ from upstream_utils import (
def main():
upstream_root = clone_repo(
"https://github.com/SleipnirGroup/Sleipnir",
# main on 2024-06-19
"d5bf25acc8a28f10d7f9e85ef89b31eb0e916f6b",
# main on 2024-07-05
"b90f89d343379dd8dc88f22e0462eb7b59006b2c",
shallow=False,
)
wpilib_root = get_repo_root()
@@ -29,6 +29,7 @@ def main():
"0002-Use-fmtlib.patch",
"0003-Remove-unsupported-constexpr.patch",
"0004-Use-wpi-SmallVector.patch",
"0005-Suppress-clang-tidy-false-positives.patch",
]:
git_am(os.path.join(wpilib_root, "upstream_utils/sleipnir_patches", f))

View File

@@ -226,15 +226,15 @@ struct SLEIPNIR_DLLEXPORT Expression {
return MakeExpressionPtr(
type, [](double lhs, double rhs) { return lhs * rhs; },
[](double lhs, double rhs, double parentAdjoint) {
[](double, double rhs, double parentAdjoint) {
return parentAdjoint * rhs;
},
[](double lhs, double rhs, double parentAdjoint) {
[](double lhs, double, double parentAdjoint) {
return parentAdjoint * lhs;
},
[](const ExpressionPtr& lhs, const ExpressionPtr& rhs,
[](const ExpressionPtr&, const ExpressionPtr& rhs,
const ExpressionPtr& parentAdjoint) { return parentAdjoint * rhs; },
[](const ExpressionPtr& lhs, const ExpressionPtr& rhs,
[](const ExpressionPtr& lhs, const ExpressionPtr&,
const ExpressionPtr& parentAdjoint) { return parentAdjoint * lhs; },
lhs, rhs);
}
@@ -271,13 +271,13 @@ struct SLEIPNIR_DLLEXPORT Expression {
return MakeExpressionPtr(
type, [](double lhs, double rhs) { return lhs / rhs; },
[](double lhs, double rhs, double parentAdjoint) {
[](double, double rhs, double parentAdjoint) {
return parentAdjoint / rhs;
},
[](double lhs, double rhs, double parentAdjoint) {
return parentAdjoint * -lhs / (rhs * rhs);
},
[](const ExpressionPtr& lhs, const ExpressionPtr& rhs,
[](const ExpressionPtr&, const ExpressionPtr& rhs,
const ExpressionPtr& parentAdjoint) { return parentAdjoint / rhs; },
[](const ExpressionPtr& lhs, const ExpressionPtr& rhs,
const ExpressionPtr& parentAdjoint) {
@@ -310,15 +310,11 @@ struct SLEIPNIR_DLLEXPORT Expression {
return MakeExpressionPtr(
std::max(lhs->type, rhs->type),
[](double lhs, double rhs) { return lhs + rhs; },
[](double lhs, double rhs, double parentAdjoint) {
return parentAdjoint;
},
[](double lhs, double rhs, double parentAdjoint) {
return parentAdjoint;
},
[](const ExpressionPtr& lhs, const ExpressionPtr& rhs,
[](double, double, double parentAdjoint) { return parentAdjoint; },
[](double, double, double parentAdjoint) { return parentAdjoint; },
[](const ExpressionPtr&, const ExpressionPtr&,
const ExpressionPtr& parentAdjoint) { return parentAdjoint; },
[](const ExpressionPtr& lhs, const ExpressionPtr& rhs,
[](const ExpressionPtr&, const ExpressionPtr&,
const ExpressionPtr& parentAdjoint) { return parentAdjoint; },
lhs, rhs);
}
@@ -352,15 +348,11 @@ struct SLEIPNIR_DLLEXPORT Expression {
return MakeExpressionPtr(
std::max(lhs->type, rhs->type),
[](double lhs, double rhs) { return lhs - rhs; },
[](double lhs, double rhs, double parentAdjoint) {
return parentAdjoint;
},
[](double lhs, double rhs, double parentAdjoint) {
return -parentAdjoint;
},
[](const ExpressionPtr& lhs, const ExpressionPtr& rhs,
[](double, double, double parentAdjoint) { return parentAdjoint; },
[](double, double, double parentAdjoint) { return -parentAdjoint; },
[](const ExpressionPtr&, const ExpressionPtr&,
const ExpressionPtr& parentAdjoint) { return parentAdjoint; },
[](const ExpressionPtr& lhs, const ExpressionPtr& rhs,
[](const ExpressionPtr&, const ExpressionPtr&,
const ExpressionPtr& parentAdjoint) { return -parentAdjoint; },
lhs, rhs);
}
@@ -384,8 +376,8 @@ struct SLEIPNIR_DLLEXPORT Expression {
return MakeExpressionPtr(
lhs->type, [](double lhs, double) { return -lhs; },
[](double lhs, double, double parentAdjoint) { return -parentAdjoint; },
[](const ExpressionPtr& lhs, const ExpressionPtr& rhs,
[](double, double, double parentAdjoint) { return -parentAdjoint; },
[](const ExpressionPtr&, const ExpressionPtr&,
const ExpressionPtr& parentAdjoint) { return -parentAdjoint; },
lhs);
}
@@ -940,9 +932,8 @@ SLEIPNIR_DLLEXPORT inline ExpressionPtr sign(const ExpressionPtr& x) {
return 1.0;
}
},
[](double x, double, double parentAdjoint) { return 0.0; },
[](const ExpressionPtr& x, const ExpressionPtr&,
const ExpressionPtr& parentAdjoint) {
[](double, double, double) { return 0.0; },
[](const ExpressionPtr&, const ExpressionPtr&, const ExpressionPtr&) {
// Return zero
return MakeExpressionPtr();
},

View File

@@ -193,7 +193,7 @@ class SLEIPNIR_DLLEXPORT ExpressionGraph {
* @param func A function that takes two arguments: an int for the gradient
* row, and a double for the adjoint (gradient value).
*/
void ComputeAdjoints(function_ref<void(int, double)> func) {
void ComputeAdjoints(function_ref<void(int row, double adjoint)> func) {
// Zero adjoints. The root node's adjoint is 1.0 as df/df is always 1.
m_adjointList[0]->adjoint = 1.0;
for (auto it = m_adjointList.begin() + 1; it != m_adjointList.end(); ++it) {

View File

@@ -32,13 +32,6 @@ class SLEIPNIR_DLLEXPORT Variable {
*/
Variable(double value) : expr{detail::MakeExpressionPtr(value)} {} // NOLINT
/**
* Constructs a Variable from an int.
*
* @param value The value of the Variable.
*/
Variable(int value) : expr{detail::MakeExpressionPtr(value)} {} // NOLINT
/**
* Constructs a Variable pointing to the specified expression.
*
@@ -64,23 +57,12 @@ class SLEIPNIR_DLLEXPORT Variable {
return *this;
}
/**
* Assignment operator for int.
*
* @param value The value of the Variable.
*/
Variable& operator=(int value) {
expr = detail::MakeExpressionPtr(value);
return *this;
}
/**
* Sets Variable's internal value.
*
* @param value The value of the Variable.
*/
Variable& SetValue(double value) {
void SetValue(double value) {
if (expr->IsConstant(0.0)) {
expr = detail::MakeExpressionPtr(value);
} else {
@@ -94,29 +76,6 @@ class SLEIPNIR_DLLEXPORT Variable {
}
expr->value = value;
}
return *this;
}
/**
* Sets Variable's internal value.
*
* @param value The value of the Variable.
*/
Variable& SetValue(int value) {
if (expr->IsConstant(0.0)) {
expr = detail::MakeExpressionPtr(value);
} else {
// We only need to check the first argument since unary and binary
// operators both use it
if (expr->args[0] != nullptr && !expr->args[0]->IsConstant(0.0)) {
sleipnir::println(
stderr,
"WARNING: {}:{}: Modified the value of a dependent variable",
__FILE__, __LINE__);
}
expr->value = value;
}
return *this;
}
/**

View File

@@ -131,12 +131,10 @@ class VariableBlock {
*
* @param value Value to assign.
*/
VariableBlock<Mat>& SetValue(double value) {
void SetValue(double value) {
Assert(Rows() == 1 && Cols() == 1);
(*this)(0, 0).SetValue(value);
return *this;
}
/**
@@ -165,7 +163,7 @@ class VariableBlock {
*/
template <typename Derived>
requires std::same_as<typename Derived::Scalar, double>
VariableBlock<Mat>& SetValue(const Eigen::MatrixBase<Derived>& values) {
void SetValue(const Eigen::MatrixBase<Derived>& values) {
Assert(Rows() == values.rows());
Assert(Cols() == values.cols());
@@ -174,8 +172,6 @@ class VariableBlock {
(*this)(row, col).SetValue(values(row, col));
}
}
return *this;
}
/**

View File

@@ -89,7 +89,7 @@ class SLEIPNIR_DLLEXPORT VariableMatrix {
*
* @param list The nested list of Variables.
*/
VariableMatrix(std::vector<std::vector<double>> list) { // NOLINT
VariableMatrix(const std::vector<std::vector<double>>& list) { // NOLINT
// Get row and column counts for destination matrix
m_rows = list.size();
m_cols = 0;
@@ -116,7 +116,7 @@ class SLEIPNIR_DLLEXPORT VariableMatrix {
*
* @param list The nested list of Variables.
*/
VariableMatrix(std::vector<std::vector<Variable>> list) { // NOLINT
VariableMatrix(const std::vector<std::vector<Variable>>& list) { // NOLINT
// Get row and column counts for destination matrix
m_rows = list.size();
m_cols = 0;
@@ -200,7 +200,7 @@ class SLEIPNIR_DLLEXPORT VariableMatrix {
*/
template <typename Derived>
requires std::same_as<typename Derived::Scalar, double>
VariableMatrix& SetValue(const Eigen::MatrixBase<Derived>& values) {
void SetValue(const Eigen::MatrixBase<Derived>& values) {
Assert(Rows() == values.rows());
Assert(Cols() == values.cols());
@@ -209,8 +209,6 @@ class SLEIPNIR_DLLEXPORT VariableMatrix {
(*this)(row, col).SetValue(values(row, col));
}
}
return *this;
}
/**
@@ -979,7 +977,7 @@ SLEIPNIR_DLLEXPORT inline VariableMatrix Block(
* @param list The nested list of blocks.
*/
SLEIPNIR_DLLEXPORT inline VariableMatrix Block(
std::vector<std::vector<VariableMatrix>> list) {
const std::vector<std::vector<VariableMatrix>>& list) {
// Get row and column counts for destination matrix
int rows = 0;
int cols = -1;

View File

@@ -16,18 +16,6 @@
namespace sleipnir {
/**
* Function representing an explicit or implicit ODE, or a discrete state
* transition function.
*
* - Explicit: dx/dt = f(t, x, u, *)
* - Implicit: f(t, [x dx/dt]', u, *) = 0
* - State transition: xₖ₊₁ = f(t, xₖ, uₖ, dt)
*/
using DynamicsFunction =
function_ref<VariableMatrix(const Variable&, const VariableMatrix&,
const VariableMatrix&, const Variable&)>;
/**
* Performs 4th order Runge-Kutta integration of dx/dt = f(t, x, u) for dt.
*
@@ -122,15 +110,61 @@ class SLEIPNIR_DLLEXPORT OCPSolver : public OptimizationProblem {
* @param numInputs The number of system inputs.
* @param dt The timestep for fixed-step integration.
* @param numSteps The number of control points.
* @param dynamics The system evolution function, either an explicit ODE or a
* discrete state transition function.
* @param dynamics Function representing an explicit or implicit ODE, or a
* discrete state transition function.
* - Explicit: dx/dt = f(x, u, *)
* - Implicit: f([x dx/dt]', u, *) = 0
* - State transition: xₖ₊₁ = f(xₖ, uₖ)
* @param dynamicsType The type of system evolution function.
* @param timestepMethod The timestep method.
* @param method The transcription method.
*/
OCPSolver(
int numStates, int numInputs, std::chrono::duration<double> dt,
int numSteps, DynamicsFunction dynamics,
int numSteps,
function_ref<VariableMatrix(const VariableMatrix& x,
const VariableMatrix& u)>
dynamics,
DynamicsType dynamicsType = DynamicsType::kExplicitODE,
TimestepMethod timestepMethod = TimestepMethod::kFixed,
TranscriptionMethod method = TranscriptionMethod::kDirectTranscription)
: OCPSolver{numStates,
numInputs,
dt,
numSteps,
[=]([[maybe_unused]] const VariableMatrix& t,
const VariableMatrix& x, const VariableMatrix& u,
[[maybe_unused]]
const VariableMatrix& dt) -> VariableMatrix {
return dynamics(x, u);
},
dynamicsType,
timestepMethod,
method} {}
/**
* Build an optimization problem using a system evolution function (explicit
* ODE or discrete state transition function).
*
* @param numStates The number of system states.
* @param numInputs The number of system inputs.
* @param dt The timestep for fixed-step integration.
* @param numSteps The number of control points.
* @param dynamics Function representing an explicit or implicit ODE, or a
* discrete state transition function.
* - Explicit: dx/dt = f(t, x, u, *)
* - Implicit: f(t, [x dx/dt]', u, *) = 0
* - State transition: xₖ₊₁ = f(t, xₖ, uₖ, dt)
* @param dynamicsType The type of system evolution function.
* @param timestepMethod The timestep method.
* @param method The transcription method.
*/
OCPSolver(
int numStates, int numInputs, std::chrono::duration<double> dt,
int numSteps,
function_ref<VariableMatrix(const Variable& t, const VariableMatrix& x,
const VariableMatrix& u, const Variable& dt)>
dynamics,
DynamicsType dynamicsType = DynamicsType::kExplicitODE,
TimestepMethod timestepMethod = TimestepMethod::kFixed,
TranscriptionMethod method = TranscriptionMethod::kDirectTranscription)
@@ -203,6 +237,24 @@ class SLEIPNIR_DLLEXPORT OCPSolver : public OptimizationProblem {
SubjectTo(FinalState() == finalState);
}
/**
* Set the constraint evaluation function. This function is called
* `numSteps+1` times, with the corresponding state and input
* VariableMatrices.
*
* @param callback The callback f(x, u) where x is the state and u is the
* input vector.
*/
void ForEachStep(
const function_ref<void(const VariableMatrix& x, const VariableMatrix& u)>
callback) {
for (int i = 0; i < m_numSteps + 1; ++i) {
auto x = X().Col(i);
auto u = U().Col(i);
callback(x, u);
}
}
/**
* Set the constraint evaluation function. This function is called
* `numSteps+1` times, with the corresponding state and input
@@ -212,8 +264,8 @@ class SLEIPNIR_DLLEXPORT OCPSolver : public OptimizationProblem {
* vector, u is the input vector, and dt is the timestep duration.
*/
void ForEachStep(
const function_ref<void(const Variable&, const VariableMatrix&,
const VariableMatrix&, const Variable&)>
const function_ref<void(const Variable& t, const VariableMatrix& x,
const VariableMatrix& u, const Variable& dt)>
callback) {
Variable time = 0.0;
@@ -365,9 +417,9 @@ class SLEIPNIR_DLLEXPORT OCPSolver : public OptimizationProblem {
Variable dt = DT()(0, i);
if (m_dynamicsType == DynamicsType::kExplicitODE) {
SubjectTo(x_end ==
RK4<const DynamicsFunction&, VariableMatrix, VariableMatrix,
Variable>(m_dynamicsFunction, x_begin, u, time, dt));
SubjectTo(x_end == RK4<const decltype(m_dynamicsFunction)&,
VariableMatrix, VariableMatrix, Variable>(
m_dynamicsFunction, x_begin, u, time, dt));
} else if (m_dynamicsType == DynamicsType::kDiscrete) {
SubjectTo(x_end == m_dynamicsFunction(time, x_begin, u, dt));
}
@@ -386,8 +438,9 @@ class SLEIPNIR_DLLEXPORT OCPSolver : public OptimizationProblem {
Variable dt = DT()(0, i);
if (m_dynamicsType == DynamicsType::kExplicitODE) {
x_end = RK4<const DynamicsFunction&, VariableMatrix, VariableMatrix,
Variable>(m_dynamicsFunction, x_begin, u, time, dt);
x_end = RK4<const decltype(m_dynamicsFunction)&, VariableMatrix,
VariableMatrix, Variable>(m_dynamicsFunction, x_begin, u,
time, dt);
} else if (m_dynamicsType == DynamicsType::kDiscrete) {
x_end = m_dynamicsFunction(time, x_begin, u, dt);
}
@@ -403,7 +456,10 @@ class SLEIPNIR_DLLEXPORT OCPSolver : public OptimizationProblem {
TranscriptionMethod m_transcriptionMethod;
DynamicsType m_dynamicsType;
DynamicsFunction m_dynamicsFunction;
function_ref<VariableMatrix(const Variable& t, const VariableMatrix& x,
const VariableMatrix& u, const Variable& dt)>
m_dynamicsFunction;
TimestepMethod m_timestepMethod;

View File

@@ -4,7 +4,9 @@
#include <algorithm>
#include <concepts>
#include <initializer_list>
#include <type_traits>
#include <vector>
#include <wpi/SmallVector.h>
@@ -122,6 +124,34 @@ struct SLEIPNIR_DLLEXPORT EqualityConstraints {
/// A vector of scalar equality constraints.
wpi::SmallVector<Variable> constraints;
/**
* Concatenates multiple equality constraints.
*
* @param equalityConstraints The list of EqualityConstraints to concatenate.
*/
EqualityConstraints( // NOLINT
std::initializer_list<EqualityConstraints> equalityConstraints) {
for (const auto& elem : equalityConstraints) {
constraints.insert(constraints.end(), elem.constraints.begin(),
elem.constraints.end());
}
}
/**
* Concatenates multiple equality constraints.
*
* This overload is for Python bindings only.
*
* @param equalityConstraints The list of EqualityConstraints to concatenate.
*/
explicit EqualityConstraints(
const std::vector<EqualityConstraints>& equalityConstraints) {
for (const auto& elem : equalityConstraints) {
constraints.insert(constraints.end(), elem.constraints.begin(),
elem.constraints.end());
}
}
/**
* Constructs an equality constraint from a left and right side.
*
@@ -156,6 +186,36 @@ struct SLEIPNIR_DLLEXPORT InequalityConstraints {
/// A vector of scalar inequality constraints.
wpi::SmallVector<Variable> constraints;
/**
* Concatenates multiple inequality constraints.
*
* @param inequalityConstraints The list of InequalityConstraints to
* concatenate.
*/
InequalityConstraints( // NOLINT
std::initializer_list<InequalityConstraints> inequalityConstraints) {
for (const auto& elem : inequalityConstraints) {
constraints.insert(constraints.end(), elem.constraints.begin(),
elem.constraints.end());
}
}
/**
* Concatenates multiple inequality constraints.
*
* This overload is for Python bindings only.
*
* @param inequalityConstraints The list of InequalityConstraints to
* concatenate.
*/
explicit InequalityConstraints(
const std::vector<InequalityConstraints>& inequalityConstraints) {
for (const auto& elem : inequalityConstraints) {
constraints.insert(constraints.end(), elem.constraints.begin(),
elem.constraints.end());
}
}
/**
* Constructs an inequality constraint from a left and right side.
*

View File

@@ -41,7 +41,8 @@ struct MultistartResult {
*/
template <typename DecisionVariables>
MultistartResult<DecisionVariables> Multistart(
function_ref<MultistartResult<DecisionVariables>(const DecisionVariables&)>
function_ref<MultistartResult<DecisionVariables>(
const DecisionVariables& initialGuess)>
solve,
std::span<const DecisionVariables> initialGuesses) {
wpi::SmallVector<std::future<MultistartResult<DecisionVariables>>> futures;

View File

@@ -8,7 +8,6 @@
#include <functional>
#include <iterator>
#include <optional>
#include <type_traits>
#include <utility>
#include <Eigen/Core>
@@ -330,9 +329,9 @@ class SLEIPNIR_DLLEXPORT OptimizationProblem {
* @param callback The callback.
*/
template <typename F>
requires std::invocable<F, const SolverIterationInfo&> &&
std::same_as<std::invoke_result_t<F, const SolverIterationInfo&>,
void>
requires requires(F callback, const SolverIterationInfo& info) {
{ callback(info) } -> std::same_as<void>;
}
void Callback(F&& callback) {
m_callback = [=, callback = std::forward<F>(callback)](
const SolverIterationInfo& info) {
@@ -350,9 +349,9 @@ class SLEIPNIR_DLLEXPORT OptimizationProblem {
* solver to exit early with the solution it has so far.
*/
template <typename F>
requires std::invocable<F, const SolverIterationInfo&> &&
std::same_as<std::invoke_result_t<F, const SolverIterationInfo&>,
bool>
requires requires(F callback, const SolverIterationInfo& info) {
{ callback(info) } -> std::same_as<bool>;
}
void Callback(F&& callback) {
m_callback = std::forward<F>(callback);
}
@@ -372,7 +371,7 @@ class SLEIPNIR_DLLEXPORT OptimizationProblem {
wpi::SmallVector<Variable> m_inequalityConstraints;
// The user callback
std::function<bool(const SolverIterationInfo&)> m_callback =
std::function<bool(const SolverIterationInfo& info)> m_callback =
[](const SolverIterationInfo&) { return false; };
// The solver status

View File

@@ -48,7 +48,7 @@ SLEIPNIR_DLLEXPORT void InteriorPoint(
std::span<Variable> decisionVariables,
std::span<Variable> equalityConstraints,
std::span<Variable> inequalityConstraints, Variable& f,
function_ref<bool(const SolverIterationInfo&)> callback,
function_ref<bool(const SolverIterationInfo& info)> callback,
const SolverConfig& config, bool feasibilityRestoration, Eigen::VectorXd& x,
Eigen::VectorXd& s, SolverStatus* status);

View File

@@ -40,7 +40,8 @@ class SLEIPNIR_DLLEXPORT PoolResource {
* @param alignment Alignment of the block (unused).
*/
[[nodiscard]]
void* allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) {
void* allocate(size_t bytes, [[maybe_unused]] size_t alignment =
alignof(std::max_align_t)) {
if (m_freeList.empty()) {
AddChunk(bytes);
}
@@ -57,8 +58,9 @@ class SLEIPNIR_DLLEXPORT PoolResource {
* @param bytes Number of bytes in the block (unused).
* @param alignment Alignment of the block (unused).
*/
void deallocate(void* p, size_t bytes,
size_t alignment = alignof(std::max_align_t)) {
void deallocate(
void* p, [[maybe_unused]] size_t bytes,
[[maybe_unused]] size_t alignment = alignof(std::max_align_t)) {
m_freeList.emplace_back(p);
}

View File

@@ -34,35 +34,72 @@ VariableMatrix Solve(const VariableMatrix& A, const VariableMatrix& B) {
// m x n * n x p = m x p
Assert(A.Rows() == B.Rows());
if (A.Rows() == 2 && A.Cols() == 2) {
if (A.Rows() == 1 && A.Cols() == 1) {
// Compute optimal inverse instead of using Eigen's general solver
sleipnir::VariableMatrix Ainv{2, 2};
Ainv(0, 0) = A(1, 1);
Ainv(0, 1) = -A(0, 1);
Ainv(1, 0) = -A(1, 0);
Ainv(1, 1) = A(0, 0);
auto detA = A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0);
return B(0, 0) / A(0, 0);
} else if (A.Rows() == 2 && A.Cols() == 2) {
// Compute optimal inverse instead of using Eigen's general solver
//
// [a b]⁻¹ ___1___ [ d b]
// [c d] = ad bc [c a]
const auto& a = A(0, 0);
const auto& b = A(0, 1);
const auto& c = A(1, 0);
const auto& d = A(1, 1);
sleipnir::VariableMatrix Ainv{{d, -b}, {-c, a}};
auto detA = a * d - b * c;
Ainv /= detA;
return Ainv * B;
} else if (A.Rows() == 3 && A.Cols() == 3) {
// Compute optimal inverse instead of using Eigen's general solver
//
// [a b c]⁻¹
// [d e f]
// [g h i]
// 1 [ei fh ch bi bf ce]
// = --------------------------------- [fg di ai cg cd af]
// aei afh bdi + bfg + cdh ceg [dh eg bg ah ae bd]
const auto& a = A(0, 0);
const auto& b = A(0, 1);
const auto& c = A(0, 2);
const auto& d = A(1, 0);
const auto& e = A(1, 1);
const auto& f = A(1, 2);
const auto& g = A(2, 0);
const auto& h = A(2, 1);
const auto& i = A(2, 2);
sleipnir::VariableMatrix Ainv{
{e * i - f * h, c * h - b * i, b * f - c * e},
{f * g - d * i, a * i - c * g, c * d - a * f},
{d * h - e * g, b * g - a * h, a * e - b * d}};
auto detA =
a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
Ainv /= detA;
return Ainv * B;
} else {
using MatrixXvar = Eigen::Matrix<Variable, Eigen::Dynamic, Eigen::Dynamic>;
using MatrixXv = Eigen::Matrix<Variable, Eigen::Dynamic, Eigen::Dynamic>;
MatrixXvar eigenA{A.Rows(), A.Cols()};
MatrixXv eigenA{A.Rows(), A.Cols()};
for (int row = 0; row < A.Rows(); ++row) {
for (int col = 0; col < A.Cols(); ++col) {
eigenA(row, col) = A(row, col);
}
}
MatrixXvar eigenB{B.Rows(), B.Cols()};
MatrixXv eigenB{B.Rows(), B.Cols()};
for (int row = 0; row < B.Rows(); ++row) {
for (int col = 0; col < B.Cols(); ++col) {
eigenB(row, col) = B(row, col);
}
}
MatrixXvar eigenX = eigenA.householderQr().solve(eigenB);
MatrixXv eigenX = eigenA.householderQr().solve(eigenB);
VariableMatrix X{A.Cols(), B.Cols()};
for (int row = 0; row < X.Rows(); ++row) {

View File

@@ -37,7 +37,7 @@ namespace sleipnir {
void InteriorPoint(std::span<Variable> decisionVariables,
std::span<Variable> equalityConstraints,
std::span<Variable> inequalityConstraints, Variable& f,
function_ref<bool(const SolverIterationInfo&)> callback,
function_ref<bool(const SolverIterationInfo& info)> callback,
const SolverConfig& config, bool feasibilityRestoration,
Eigen::VectorXd& x, Eigen::VectorXd& s,
SolverStatus* status) {
@@ -354,7 +354,7 @@ void InteriorPoint(std::span<Variable> decisionVariables,
decisionVariables.size() + equalityConstraints.size(),
decisionVariables.size() + equalityConstraints.size());
lhs.setFromSortedTriplets(triplets.begin(), triplets.end(),
[](const auto& a, const auto& b) { return b; });
[](const auto&, const auto& b) { return b; });
const Eigen::VectorXd e = Eigen::VectorXd::Ones(s.rows());
@@ -582,7 +582,7 @@ void InteriorPoint(std::span<Variable> decisionVariables,
Eigen::VectorXd fr_s = s;
SolverStatus fr_status;
FeasibilityRestoration(
decisionVariables, equalityConstraints, inequalityConstraints, f, μ,
decisionVariables, equalityConstraints, inequalityConstraints, μ,
[&](const SolverIterationInfo& info) {
Eigen::VectorXd trial_x =
info.x.segment(0, decisionVariables.size());
@@ -656,7 +656,7 @@ void InteriorPoint(std::span<Variable> decisionVariables,
A_e.cols() + s.rows()};
Ahat.setFromSortedTriplets(
triplets.begin(), triplets.end(),
[](const auto& a, const auto& b) { return b; });
[](const auto&, const auto& b) { return b; });
// lhs = ÂÂᵀ
Eigen::SparseMatrix<double> lhs = Ahat * Ahat.transpose();

View File

@@ -28,7 +28,6 @@ namespace sleipnir {
* @param[in] decisionVariables The list of decision variables.
* @param[in] equalityConstraints The list of equality constraints.
* @param[in] inequalityConstraints The list of inequality constraints.
* @param[in] f The cost function.
* @param[in] μ Barrier parameter.
* @param[in] callback The user callback.
* @param[in] config Configuration options for the solver.
@@ -40,8 +39,8 @@ namespace sleipnir {
inline void FeasibilityRestoration(
std::span<Variable> decisionVariables,
std::span<Variable> equalityConstraints,
std::span<Variable> inequalityConstraints, Variable& f, double μ,
function_ref<bool(const SolverIterationInfo&)> callback,
std::span<Variable> inequalityConstraints, double μ,
function_ref<bool(const SolverIterationInfo& info)> callback,
const SolverConfig& config, Eigen::VectorXd& x, Eigen::VectorXd& s,
SolverStatus* status) {
// Feasibility restoration