diff --git a/include/sleipnir/autodiff/Expression.hpp b/include/sleipnir/autodiff/Expression.hpp index b6dc1056e..cd1d475e4 100644 --- a/include/sleipnir/autodiff/Expression.hpp +++ b/include/sleipnir/autodiff/Expression.hpp @@ -12,28 +12,9 @@ #include "sleipnir/IntrusiveSharedPtr.hpp" #include "sleipnir/Pool.hpp" #include "sleipnir/SymbolExports.hpp" +#include "sleipnir/autodiff/ExpressionType.hpp" -namespace sleipnir { - -/** - * Expression type. - * - * Used for autodiff caching. - */ -enum class ExpressionType { - /// There is no expression. - kNone, - /// The expression is a constant. - kConstant, - /// The expression is composed of linear and lower-order operators. - kLinear, - /// The expression is composed of quadratic and lower-order operators. - kQuadratic, - /// The expression is composed of nonlinear and lower-order operators. - kNonlinear -}; - -namespace detail { +namespace sleipnir::detail { struct SLEIPNIR_DLLEXPORT Expression; @@ -442,7 +423,9 @@ SLEIPNIR_DLLEXPORT ExpressionPtr tan( // NOLINT */ SLEIPNIR_DLLEXPORT ExpressionPtr tanh(const ExpressionPtr& x); -} // namespace detail +} // namespace sleipnir::detail + +namespace sleipnir { // FIXME: Doxygen is confused: // diff --git a/include/sleipnir/autodiff/ExpressionType.hpp b/include/sleipnir/autodiff/ExpressionType.hpp new file mode 100644 index 000000000..1cec50619 --- /dev/null +++ b/include/sleipnir/autodiff/ExpressionType.hpp @@ -0,0 +1,35 @@ +// Copyright (c) Sleipnir contributors + +#pragma once + +#include + +namespace sleipnir { + +/** + * Expression type. + * + * Used for autodiff caching. + */ +enum class ExpressionType { + /// There is no expression. + kNone, + /// The expression is a constant. + kConstant, + /// The expression is composed of linear and lower-order operators. + kLinear, + /// The expression is composed of quadratic and lower-order operators. + kQuadratic, + /// The expression is composed of nonlinear and lower-order operators. + kNonlinear +}; + +/** + * GoogleTest value formatter for ExpressionType. + * + * @param type ExpressionType to print. + * @param os Output stream to which to print. + */ +void PrintTo(const ExpressionType& type, std::ostream* os); + +} // namespace sleipnir diff --git a/include/sleipnir/optimization/SolverExitCondition.hpp b/include/sleipnir/optimization/SolverExitCondition.hpp index 5bee4b0a3..edd7954c9 100644 --- a/include/sleipnir/optimization/SolverExitCondition.hpp +++ b/include/sleipnir/optimization/SolverExitCondition.hpp @@ -2,6 +2,8 @@ #pragma once +#include + namespace sleipnir { /** @@ -35,4 +37,12 @@ enum class SolverExitCondition { kMaxWallClockTimeExceeded = -7 }; +/** + * GoogleTest value formatter for SolverExitCondition. + * + * @param cond SolverExitCondition to print. + * @param os Output stream to which to print. + */ +void PrintTo(const SolverExitCondition& cond, std::ostream* os); + } // namespace sleipnir diff --git a/src/autodiff/Expression.cpp b/src/autodiff/Expression.cpp index a606d56b4..6f6086e0d 100644 --- a/src/autodiff/Expression.cpp +++ b/src/autodiff/Expression.cpp @@ -5,14 +5,6 @@ #include #include -namespace sleipnir { - -// Instantiate Expression pool in Expression.cpp instead to avoid ODR violation -template EXPORT_TEMPLATE_DEFINE(SLEIPNIR_DLLEXPORT) - PoolAllocator GlobalPoolAllocator(); - -} // namespace sleipnir - namespace sleipnir::detail { namespace { @@ -846,3 +838,11 @@ ExpressionPtr tanh(const ExpressionPtr& x) { } } // namespace sleipnir::detail + +namespace sleipnir { + +// Instantiate Expression pool in Expression.cpp instead to avoid ODR violation +template EXPORT_TEMPLATE_DEFINE(SLEIPNIR_DLLEXPORT) + PoolAllocator GlobalPoolAllocator(); + +} // namespace sleipnir diff --git a/src/autodiff/ExpressionType.cpp b/src/autodiff/ExpressionType.cpp new file mode 100644 index 000000000..5b3cd6b77 --- /dev/null +++ b/src/autodiff/ExpressionType.cpp @@ -0,0 +1,31 @@ +// Copyright (c) Sleipnir contributors + +#include "sleipnir/autodiff/ExpressionType.hpp" + +#include + +namespace sleipnir { + +void PrintTo(const ExpressionType& type, std::ostream* os) { + using enum sleipnir::ExpressionType; + + switch (type) { + case kNone: + *os << "ExpressionType::kNone"; + break; + case kConstant: + *os << "ExpressionType::kConstant"; + break; + case kLinear: + *os << "ExpressionType::kLinear"; + break; + case kQuadratic: + *os << "ExpressionType::kQuadratic"; + break; + case kNonlinear: + *os << "ExpressionType::kNonlinear"; + break; + } +} + +} // namespace sleipnir diff --git a/src/optimization/SolverExitCondition.cpp b/src/optimization/SolverExitCondition.cpp new file mode 100644 index 000000000..1fae89ff8 --- /dev/null +++ b/src/optimization/SolverExitCondition.cpp @@ -0,0 +1,46 @@ +// Copyright (c) Sleipnir contributors + +#include "sleipnir/optimization/SolverExitCondition.hpp" + +#include + +namespace sleipnir { + +void PrintTo(const SolverExitCondition& cond, std::ostream* os) { + using enum sleipnir::SolverExitCondition; + + switch (cond) { + case kSuccess: + *os << "SolverExitCondition::kSuccess"; + break; + case kSolvedToAcceptableTolerance: + *os << "SolverExitCondition::kSolvedToAcceptableTolerance"; + break; + case kCallbackRequestedStop: + *os << "SolverExitCondition::kCallbackRequestedStop"; + break; + case kTooFewDOFs: + *os << "SolverExitCondition::kTooFewDOFs"; + break; + case kLocallyInfeasible: + *os << "SolverExitCondition::kLocallyInfeasible"; + break; + case kBadSearchDirection: + *os << "SolverExitCondition::kBadSearchDirection"; + break; + case kMaxSearchDirectionTooSmall: + *os << "SolverExitCondition::kMaxSearchDirectionTooSmall"; + break; + case kDivergingIterates: + *os << "SolverExitCondition::kDivergingIterates"; + break; + case kMaxIterationsExceeded: + *os << "SolverExitCondition::kMaxIterationsExceeded"; + break; + case kMaxWallClockTimeExceeded: + *os << "SolverExitCondition::kMaxWallClockTimeExceeded"; + break; + } +} + +} // namespace sleipnir