-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from pariterre/master
Added the smooth if_else in casadi
- Loading branch information
Showing
13 changed files
with
215 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#ifndef BIORBD_UTILS_CASADI_EXPAND_H | ||
#define BIORBD_UTILS_CASADI_EXPAND_H | ||
|
||
#include <map> | ||
#include "biorbdConfig.h" | ||
|
||
#include "casadi.hpp" | ||
|
||
namespace BIORBD_NAMESPACE | ||
{ | ||
namespace utils | ||
{ | ||
#ifdef USE_SMOOTH_IF_ELSE | ||
/// | ||
/// \brief Lesser than that works with the if_else of CasadiExpand | ||
/// \param x First element | ||
/// \param y Second element | ||
/// \return The lesser than element | ||
/// | ||
casadi::MX lt( | ||
const casadi::MX& x, | ||
const casadi::MX& y); | ||
|
||
/// | ||
/// \brief Lesser or equal than that works with the if_else of CasadiExpand. | ||
/// This is strictly similar to lt | ||
/// \param x First element | ||
/// \param y Second element | ||
/// \return The lesser than element | ||
/// | ||
casadi::MX le( | ||
const casadi::MX& x, | ||
const casadi::MX& y); | ||
|
||
/// | ||
/// \brief Greater than that works with the if_else of CasadiExpand | ||
/// \param x First element | ||
/// \param y Second element | ||
/// \return The greater than element | ||
/// | ||
casadi::MX gt( | ||
const casadi::MX& x, | ||
const casadi::MX& y); | ||
|
||
/// | ||
/// \brief Greater or equal than that works with the if_else of CasadiExpand. | ||
/// This is strictly similar to lt | ||
/// \param x First element | ||
/// \param y Second element | ||
/// \return The greater than element | ||
/// | ||
casadi::MX ge( | ||
const casadi::MX& x, | ||
const casadi::MX& y); | ||
|
||
/// | ||
/// \brief A non-branching and continuous if_else based on tanh. This is not | ||
/// strictly equal to if_else when the values are near each other. The b parameter | ||
/// can be adjusted to increase the rate of change | ||
/// \param cond The condition (lt/le/gt/ge) | ||
/// \param if_true The value to return if true | ||
/// \param if_false The value to return if false | ||
/// \param b The slope parameter | ||
/// \return The value of the if_else function | ||
/// | ||
casadi::MX if_else( | ||
const casadi::MX& cond, | ||
const casadi::MX& if_true, | ||
const casadi::MX& if_false, | ||
double b = 10000); | ||
|
||
/// | ||
/// \brief A non-branching and continuous if_else_zero based on tanh. This is not | ||
/// strictly equal to if_else_zero when the values are near each other. The b parameter | ||
/// can be adjusted to increase the rate of change | ||
/// \param cond The condition (lt/le/gt/ge) | ||
/// \param if_true The value to return if true | ||
/// \param if_false The value to return if false | ||
/// \param b The slope parameter | ||
/// \return The value of the if_else function | ||
/// | ||
casadi::MX if_else_zero( | ||
const casadi::MX& cond, | ||
const casadi::MX& if_true, | ||
double b = 10000); | ||
#endif | ||
|
||
} | ||
} | ||
|
||
#endif // BIORBD_UTILS_CASADI_EXPAND_H | ||
|
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
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
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
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,45 @@ | ||
#define BIORBD_API_EXPORTS | ||
#include "Utils/CasadiExpand.h" | ||
|
||
using namespace BIORBD_NAMESPACE; | ||
|
||
#ifdef USE_SMOOTH_IF_ELSE | ||
casadi::MX utils::lt( | ||
const casadi::MX& x, | ||
const casadi::MX& y){ | ||
return x - y; | ||
} | ||
|
||
casadi::MX utils::le( | ||
const casadi::MX& x, | ||
const casadi::MX& y){ | ||
return utils::lt(x, y); | ||
} | ||
|
||
casadi::MX utils::gt( | ||
const casadi::MX& x, | ||
const casadi::MX& y){ | ||
return utils::lt(y, x); | ||
} | ||
|
||
casadi::MX utils::ge( | ||
const casadi::MX& x, | ||
const casadi::MX& y){ | ||
return utils::le(y, x); | ||
} | ||
|
||
casadi::MX utils::if_else( | ||
const casadi::MX& cond, | ||
const casadi::MX& if_true, | ||
const casadi::MX& if_false, | ||
double b){ | ||
return if_true + (if_false - if_true) * (0.5 + 0.5 * casadi::MX::tanh(b * cond)); | ||
} | ||
|
||
casadi::MX utils::if_else_zero( | ||
const casadi::MX& cond, | ||
const casadi::MX& if_true, | ||
double b){ | ||
return utils::if_else(cond, if_true, 0, b); | ||
} | ||
#endif |
Oops, something went wrong.