Skip to content

Commit

Permalink
[DLG] Added the smooth_antipulse function
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolodares committed Feb 24, 2024
1 parent 6db38f5 commit 7c5a5c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lion/foundation/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ constexpr T smooth_step(const T &x, S eps);
template<bool ActuallySmooth = true, typename T, typename T1, typename T2, typename S>
constexpr T smooth_deadzone(const T &x, const T1 &lo, const T2 &hi, S eps2);

template<bool ActuallySmooth = true, typename T, typename T1, typename T2, typename S>
constexpr T smooth_antipulse(const T &x, const T1 &lo, const T2 &hi, S eps);


template <typename T>
constexpr std::vector<T> linspace(T lo, T hi, std::size_t num_points);
Expand Down
24 changes: 19 additions & 5 deletions lion/foundation/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ constexpr T smooth_sign(const T &x, S eps)

if constexpr (ActuallySmooth) {
if constexpr (UseSmoothAbsFormula) {

return x / smooth_abs(x, eps * eps);
}
else {
Expand Down Expand Up @@ -431,17 +430,32 @@ template<bool ActuallySmooth, typename T, typename T1, typename T2, typename S>
constexpr T smooth_deadzone(const T &x, const T1 &lo, const T2 &hi, S eps2)
{
//
// Implements the "smooth deadzone" function, in which the output
// is zero for x in "[lo, hi]", equal to "x - lo" if x < lo, and
// equal to "x - hi" if x > hi. When template parameter "ActuallySmooth"
// is true, the deadzone's sharpness is smoothed out with parameter
// Implements the "smooth deadzone" function, whose output is zero
// for x in "[lo, hi]", equal to "x - lo" if x < lo, and equal to
// "x - hi" if x > hi. When template parameter "ActuallySmooth" is
// true, the deadzone's sharpness is smoothed out with parameter
// "eps2", else, it is the strict deadzone function.
//

return smooth_pos<ActuallySmooth>(x - hi, eps2) + smooth_neg<ActuallySmooth>(x - lo, eps2);
}


template<bool ActuallySmooth, typename T, typename T1, typename T2, typename S>
constexpr T smooth_antipulse(const T &x, const T1 &lo, const T2 &hi, S eps)
{
//
// Implements the "smooth antipulse" function, whose output is zero
// for x in "[lo, hi]", and equal to 1 otherwise. When template
// parameter "ActuallySmooth" is true, the pulse's sharpness is
// smoothed out with parameter "eps", else, it is the strict
// antipulse function.
//

return smooth_step<ActuallySmooth>(x - hi, eps) + smooth_step<ActuallySmooth>(lo - x, eps);
}


template <typename T>
constexpr std::vector<T> linspace(T lo, T hi, std::size_t num_points)
{
Expand Down

0 comments on commit 7c5a5c8

Please sign in to comment.