Skip to content

Commit

Permalink
try moving smax to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Feb 16, 2024
1 parent 5f94615 commit faa6dab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 0 additions & 5 deletions include/Math/Exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,6 @@ template <int l = 8> constexpr auto smax(auto x, auto y) {
return o + softplus(l * d) / l;
}

template <int l = 8> constexpr auto smax(auto x, auto y, auto z) {
double m = std::max(std::max(value(x), value(y)), value(z));
constexpr double f = l, i = 1 / f;
return m + log(exp(f * (x - m)) + exp(f * (y - m)) + exp(f * (z - m))) * i;
}
template <int l = 8> constexpr auto smin(auto x, auto y) {
return smax<-l>(x, y);
}
Expand Down
12 changes: 12 additions & 0 deletions include/Math/ExpDual.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include "Math/Dual.hpp"
#include "Math/Exp.hpp"
namespace poly::math {

template <int l = 8> constexpr auto smax(auto x, auto y, auto z) {
double m = std::max(std::max(value(x), value(y)), value(z));
constexpr double f = l, i = 1 / f;
return m + log(exp(f * (x - m)) + exp(f * (y - m)) + exp(f * (z - m))) * i;
}

} // namespace poly::math

0 comments on commit faa6dab

Please sign in to comment.