-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GoogleTest value printers for ExpressionType and SolverExitCondition
- Loading branch information
Showing
6 changed files
with
140 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Sleipnir contributors | ||
|
||
#pragma once | ||
|
||
#include <iosfwd> | ||
|
||
#include "sleipnir/SymbolExports.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 | ||
}; | ||
|
||
/** | ||
* GoogleTest value formatter for ExpressionType. | ||
* | ||
* @param type ExpressionType to print. | ||
* @param os Output stream to which to print. | ||
*/ | ||
SLEIPNIR_DLLEXPORT void PrintTo(const ExpressionType& type, std::ostream* os); | ||
|
||
} // namespace sleipnir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Sleipnir contributors | ||
|
||
#include "sleipnir/autodiff/ExpressionType.hpp" | ||
|
||
#include <ostream> | ||
|
||
namespace sleipnir { | ||
|
||
void PrintTo(const ExpressionType& type, std::ostream* os) { | ||
using enum sleipnir::ExpressionType; | ||
|
||
switch (type) { | ||
case kNone: | ||
*os << "kNone"; | ||
break; | ||
case kConstant: | ||
*os << "kConstant"; | ||
break; | ||
case kLinear: | ||
*os << "kLinear"; | ||
break; | ||
case kQuadratic: | ||
*os << "kQuadratic"; | ||
break; | ||
case kNonlinear: | ||
*os << "kNonlinear"; | ||
break; | ||
} | ||
} | ||
|
||
} // namespace sleipnir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Sleipnir contributors | ||
|
||
#include "sleipnir/optimization/SolverExitCondition.hpp" | ||
|
||
#include <ostream> | ||
|
||
namespace sleipnir { | ||
|
||
void PrintTo(const SolverExitCondition& cond, std::ostream* os) { | ||
using enum sleipnir::SolverExitCondition; | ||
|
||
switch (cond) { | ||
case kSuccess: | ||
*os << "kSuccess"; | ||
break; | ||
case kSolvedToAcceptableTolerance: | ||
*os << "kSolvedToAcceptableTolerance"; | ||
break; | ||
case kCallbackRequestedStop: | ||
*os << "kCallbackRequestedStop"; | ||
break; | ||
case kTooFewDOFs: | ||
*os << "kTooFewDOFs"; | ||
break; | ||
case kLocallyInfeasible: | ||
*os << "kLocallyInfeasible"; | ||
break; | ||
case kBadSearchDirection: | ||
*os << "kBadSearchDirection"; | ||
break; | ||
case kMaxSearchDirectionTooSmall: | ||
*os << "kMaxSearchDirectionTooSmall"; | ||
break; | ||
case kDivergingIterates: | ||
*os << "kDivergingIterates"; | ||
break; | ||
case kMaxIterationsExceeded: | ||
*os << "kMaxIterationsExceeded"; | ||
break; | ||
case kMaxWallClockTimeExceeded: | ||
*os << "kMaxWallClockTimeExceeded"; | ||
break; | ||
} | ||
} | ||
|
||
} // namespace sleipnir |