Skip to content

Commit

Permalink
non-type template arguments of type double not yet supported
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Feb 16, 2024
1 parent 0234225 commit 577fa4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions include/Math/BoxOptInt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ constexpr auto bound(alloc::Arena<> *alloc, BoxTransform &box, double upper,
constexpr auto
minimizeIntSol(alloc::Arena<> *alloc, MutPtrVector<int32_t> r,
poly::math::BoxTransform &box, const auto &f,
double globalupper = std::numeric_limits<double>::infinity()) {
double globalupper = std::numeric_limits<double>::infinity())
-> double {
// goal is to shrink all bounds such that lb==ub, i.e. we have all
// integer solutions.
if (minimize(alloc, box, f) >= globalupper) return globalupper;
Expand All @@ -50,7 +51,8 @@ minimizeIntSol(alloc::Arena<> *alloc, MutPtrVector<int32_t> r,
constexpr auto
minimizeIntSol(alloc::Arena<> *alloc, MutPtrVector<int32_t> r, int32_t lb,
int32_t ub, const auto &f,
double globalupper = std::numeric_limits<double>::infinity()) {
double globalupper = std::numeric_limits<double>::infinity())
-> double {
// goal is to shrink all bounds such that lb==ub, i.e. we have all
// integer solutions.
unsigned N = r.size();
Expand Down
6 changes: 3 additions & 3 deletions include/Math/Exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,17 @@ constexpr auto sigmoid(double x) -> double { return 1.0 / (1.0 + exp(-x)); }
constexpr auto softplus(double x) -> double { return log1p(exp(x)); }
constexpr auto logit(double x) -> double { return log(x / (1.0 - x)); }

template <double l = 8.0> constexpr auto smax(auto x, auto y) {
template <int l = 8> constexpr auto smax(auto x, auto y) {
auto d = x > y ? y - x : x - y;
auto o = x > y ? decltype(d)(x) : decltype(d)(y);
return o + softplus(l * d) / l;
}

template <double l = 8.0> constexpr auto smax(auto x, auto y, auto z) {
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));
return m + log(exp(l * (x - m)) + exp(l * (y - m)) + exp(l * (z - m))) / l;
}
template <double l = 8.0> constexpr auto smin(auto x, auto y) {
template <int l = 8> constexpr auto smin(auto x, auto y) {
return smax<-l>(x, y);
}

Expand Down

0 comments on commit 577fa4e

Please sign in to comment.