Initial import of libdpf.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ryan Henry 2026-09-24 14:08:32 -06:00
commit e4e666f459
4563 changed files with 1690372 additions and 0 deletions

View file

@ -0,0 +1,654 @@
/// @file grotto/constant_lut.hpp
/// @brief Exact piecewise-constant lookup tables for the degree-0 gadgets
/// in Appendix D of Storrier, Vadapalli, Lyons, and Henry (ePrint 2023/108).
/// @details Each gadget is a template specialization of `exact_lut`. The
/// specialization holds one canonical program (sign pattern, exponent
/// class, or the shared powers-of-ten table) and projects it onto any
/// signed word width and fractional precision. Piece values are exact
/// integers, including at 0.
#ifndef LIBDPF_INCLUDE_GROTTO_CONSTANT_LUT_HPP__
#define LIBDPF_INCLUDE_GROTTO_CONSTANT_LUT_HPP__
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
namespace grotto
{
/// Appendix D gadgets whose polynomial degree is 0 and whose max error is 0.
enum class exact_constant
{
signum,
positive,
negative,
nonneg,
nonpos,
zero,
nonzero,
ilogb,
/// `ceil(log2(|x|))`. Exact powers of two agree with `ilogb`; every other
/// positive magnitude is one larger. Zero uses the same `-64` sentinel.
ceil_ilogb,
ilog10,
clz,
clrsb
};
template <typename Raw>
struct constant_lut
{
static_assert(std::is_integral_v<Raw> && std::is_signed_v<Raw>);
using raw_type = Raw;
/// Signed piece starts. `bounds.front()` is `numeric_limits<Raw>::min()`,
/// and the starts are strictly increasing.
std::vector<Raw> bounds;
/// `values[i]` is the function on `[bounds[i], next)`, where `next` is
/// `bounds[i + 1]` or one past `numeric_limits<Raw>::max()` for the last piece.
std::vector<std::int64_t> values;
std::size_t linear_parts() const noexcept { return values.size(); }
/// Pieces after joining the first and last when they carry the same value.
/// Those two meet across the signed wrap, which is how the paper counts
/// parts for `zero` and `nonzero` (2, not 3).
std::size_t wrapped_parts() const noexcept
{
if (values.size() >= 2 && values.front() == values.back())
return values.size() - 1;
return values.size();
}
std::int64_t operator()(Raw x) const noexcept
{
const auto it = std::upper_bound(bounds.begin(), bounds.end(), x);
const auto index = static_cast<std::size_t>(it - bounds.begin());
return values[index - 1];
}
};
template <exact_constant Which>
struct exact_lut;
namespace detail
{
using u128 = unsigned __int128;
template <typename Raw>
constexpr u128 magnitude(Raw raw) noexcept
{
if (raw >= 0)
return static_cast<u128>(raw);
if (raw == std::numeric_limits<Raw>::min())
return u128{1} << std::numeric_limits<Raw>::digits;
return static_cast<u128>(-static_cast<__int128>(raw));
}
constexpr int floor_log2(u128 mag) noexcept
{
if (mag <= std::uint64_t(-1))
return 63 - __builtin_clzll(static_cast<std::uint64_t>(mag));
return 127 - __builtin_clzll(static_cast<std::uint64_t>(mag >> 64));
}
constexpr bool shift_fits(u128 value, unsigned shift) noexcept
{
return shift < 128 && value <= (~u128{0} >> shift);
}
/// 10^0 .. 10^19. Every ilog10 projection reads this one table.
inline constexpr std::uint64_t pow10[] = {
1ull,
10ull,
100ull,
1000ull,
10000ull,
100000ull,
1000000ull,
10000000ull,
100000000ull,
1000000000ull,
10000000000ull,
100000000000ull,
1000000000000ull,
10000000000000ull,
100000000000000ull,
1000000000000000ull,
10000000000000000ull,
100000000000000000ull,
1000000000000000000ull,
10000000000000000000ull,
};
inline bool magnitude_ge_pow10(u128 mag, int k, unsigned fractional_bits) noexcept
{
if (mag == 0 || fractional_bits >= 128)
return false;
if (k >= 0)
{
if (k >= 20 || !shift_fits(pow10[k], fractional_bits))
return false;
return mag >= (u128{pow10[k]} << fractional_bits);
}
const int exponent = -k;
if (exponent >= 20)
return true;
const u128 scale = pow10[exponent];
if (mag > (~u128{0}) / scale)
return true;
return mag * scale >= (u128{1} << fractional_bits);
}
/// Smallest positive magnitude whose base-10 log is at least `k`.
inline u128 first_magnitude_at_least_pow10(int k, unsigned fractional_bits) noexcept
{
if (fractional_bits >= 128)
return 0;
if (k >= 0)
{
if (k >= 20 || !shift_fits(pow10[k], fractional_bits))
return 0;
return u128{pow10[k]} << fractional_bits;
}
const int exponent = -k;
if (exponent >= 20)
return 1;
const u128 scale = pow10[exponent];
const u128 thresh = u128{1} << fractional_bits;
return (thresh + scale - 1) / scale;
}
template <typename Raw>
void push_negative_magnitude(u128 mag, std::vector<Raw> & cuts)
{
using lim = std::numeric_limits<Raw>;
constexpr unsigned digits = lim::digits;
if (mag == 0)
return;
if (mag < (u128{1} << digits))
cuts.push_back(static_cast<Raw>(-static_cast<__int128>(mag)));
else
cuts.push_back(lim::min());
}
template <typename Raw>
void push_both_signs(u128 mag, std::vector<Raw> & cuts)
{
using lim = std::numeric_limits<Raw>;
constexpr unsigned digits = lim::digits;
if (mag == 0)
{
cuts.push_back(Raw{0});
return;
}
if (mag <= static_cast<u128>(lim::max()))
cuts.push_back(static_cast<Raw>(mag));
if (mag < (u128{1} << digits))
{
const __int128 neg = -static_cast<__int128>(mag);
cuts.push_back(static_cast<Raw>(neg));
if (neg < static_cast<__int128>(lim::max()))
cuts.push_back(static_cast<Raw>(neg + 1));
}
else
{
cuts.push_back(lim::min());
cuts.push_back(static_cast<Raw>(static_cast<__int128>(lim::min()) + 1));
}
}
template <typename Raw, typename Fn>
constant_lut<Raw> assemble(std::vector<Raw> cuts, Fn && fn)
{
using lim = std::numeric_limits<Raw>;
cuts.push_back(lim::min());
std::sort(cuts.begin(), cuts.end());
cuts.erase(std::unique(cuts.begin(), cuts.end()), cuts.end());
constant_lut<Raw> lut;
for (std::size_t i = 0; i < cuts.size(); ++i)
{
const Raw start = cuts[i];
const Raw last = (i + 1 < cuts.size())
? static_cast<Raw>(cuts[i + 1] - 1)
: lim::max();
const std::int64_t at_start = fn(start);
const std::int64_t at_last = fn(last);
if (at_start != at_last)
throw std::logic_error(
"constant lut endpoints differ start=" + std::to_string(static_cast<long long>(start))
+ " last=" + std::to_string(static_cast<long long>(last))
+ " " + std::to_string(at_start) + " vs " + std::to_string(at_last));
const __int128 width = static_cast<__int128>(last) - static_cast<__int128>(start);
if (width > 2)
{
const Raw mid = static_cast<Raw>(static_cast<__int128>(start) + width / 2);
if (fn(mid) != at_start)
throw std::logic_error(
"constant lut midpoint differs start=" + std::to_string(static_cast<long long>(start))
+ " mid=" + std::to_string(static_cast<long long>(mid)));
}
if (!lut.values.empty() && lut.values.back() == at_start)
continue;
lut.bounds.push_back(start);
lut.values.push_back(at_start);
}
return lut;
}
template <std::int64_t Neg, std::int64_t Zero, std::int64_t Pos>
struct sign_program
{
static constexpr std::int64_t canonical[] = { Neg, Zero, Pos };
template <typename Raw>
static std::int64_t eval(Raw raw, unsigned) noexcept
{
if (raw < 0)
return canonical[0];
if (raw > 0)
return canonical[2];
return canonical[1];
}
template <typename Raw>
static constant_lut<Raw> project(unsigned)
{
using lim = std::numeric_limits<Raw>;
return assemble<Raw>({ lim::min(), Raw{0}, Raw{1} },
[](Raw raw) { return eval<Raw>(raw, 0); });
}
};
} // namespace detail
template <>
struct exact_lut<exact_constant::signum> : detail::sign_program<-1, 0, 1> {};
template <>
struct exact_lut<exact_constant::positive> : detail::sign_program<0, 0, 1> {};
template <>
struct exact_lut<exact_constant::negative> : detail::sign_program<1, 0, 0> {};
template <>
struct exact_lut<exact_constant::nonneg> : detail::sign_program<0, 1, 1> {};
template <>
struct exact_lut<exact_constant::nonpos> : detail::sign_program<1, 1, 0> {};
template <>
struct exact_lut<exact_constant::zero> : detail::sign_program<0, 1, 0> {};
template <>
struct exact_lut<exact_constant::nonzero> : detail::sign_program<1, 0, 1> {};
template <typename Raw>
void push_pow2_cuts(std::vector<Raw> & cuts)
{
using lim = std::numeric_limits<Raw>;
cuts.push_back(lim::min());
cuts.push_back(Raw{0});
for (unsigned k = 0; k <= static_cast<unsigned>(lim::digits); ++k)
detail::push_both_signs<Raw>(detail::u128{1} << k, cuts);
}
/// floor(log2(|raw|)) - F, with -64 on the |x| <= 2^{-64} class (including 0).
/// One exponent program; fractional precision only shifts the stored exponent.
template <>
struct exact_lut<exact_constant::ilogb>
{
template <typename Raw>
static std::int64_t eval(Raw raw, unsigned fractional_bits) noexcept
{
const detail::u128 mag = detail::magnitude(raw);
if (mag == 0)
return -64;
if (fractional_bits >= 64)
{
const unsigned shift = fractional_bits - 64;
if (shift >= 128 || mag <= (detail::u128{1} << shift))
return -64;
}
return static_cast<std::int64_t>(detail::floor_log2(mag))
- static_cast<std::int64_t>(fractional_bits);
}
template <typename Raw>
static constant_lut<Raw> project(unsigned fractional_bits)
{
std::vector<Raw> cuts;
push_pow2_cuts(cuts);
return detail::assemble<Raw>(std::move(cuts),
[=](Raw raw) { return eval<Raw>(raw, fractional_bits); });
}
};
/// ceil(log2(|x|)). Same powers-of-two cuts as `ilogb`; exact powers keep the
/// floor exponent and every other magnitude steps up by one.
template <>
struct exact_lut<exact_constant::ceil_ilogb>
{
template <typename Raw>
static std::int64_t eval(Raw raw, unsigned fractional_bits) noexcept
{
const detail::u128 mag = detail::magnitude(raw);
const bool sentinel = mag == 0
|| (fractional_bits >= 64
&& mag <= (detail::u128{1} << (fractional_bits - 64)));
if (sentinel)
return -64;
const std::int64_t floor_exp = static_cast<std::int64_t>(detail::floor_log2(mag))
- static_cast<std::int64_t>(fractional_bits);
const bool power = (mag & (mag - 1)) == 0;
return power ? floor_exp : floor_exp + 1;
}
template <typename Raw>
static constant_lut<Raw> project(unsigned fractional_bits)
{
using lim = std::numeric_limits<Raw>;
std::vector<Raw> cuts;
push_pow2_cuts(cuts);
// Exact powers are singletons; the following raw already has ceil + 1.
for (unsigned k = 0; k < static_cast<unsigned>(lim::digits); ++k)
{
const detail::u128 mag = detail::u128{1} << k;
if (mag >= static_cast<detail::u128>(lim::max()))
break;
cuts.push_back(static_cast<Raw>(mag + 1));
}
return detail::assemble<Raw>(std::move(cuts),
[=](Raw raw) { return eval<Raw>(raw, fractional_bits); });
}
};
/// floor(log10(|x|)), with -19 on |x| <= 10^{-19}. Thresholds come from `pow10`.
template <>
struct exact_lut<exact_constant::ilog10>
{
template <typename Raw>
static std::int64_t eval(Raw raw, unsigned fractional_bits) noexcept
{
const detail::u128 mag = detail::magnitude(raw);
if (!detail::magnitude_ge_pow10(mag, -19, fractional_bits))
return -19;
int lo = -19;
int hi = 18;
while (lo < hi)
{
const int mid = lo + (hi - lo + 1) / 2;
if (detail::magnitude_ge_pow10(mag, mid, fractional_bits))
lo = mid;
else
hi = mid - 1;
}
return lo;
}
template <typename Raw>
static constant_lut<Raw> project(unsigned fractional_bits)
{
using lim = std::numeric_limits<Raw>;
std::vector<Raw> cuts{ lim::min(), Raw{0} };
for (int k = -19; k <= 18; ++k)
detail::push_both_signs<Raw>(
detail::first_magnitude_at_least_pow10(k, fractional_bits), cuts);
return detail::assemble<Raw>(std::move(cuts),
[=](Raw raw) { return eval<Raw>(raw, fractional_bits); });
}
};
/// 64-bit leading-zero count of trunc(x). Negatives are 0; a zero integer part is 64.
/// Exponent k of the integer part maps to 63-k after a shift of `fractional_bits`.
template <>
struct exact_lut<exact_constant::clz>
{
template <typename Raw>
static std::int64_t eval(Raw raw, unsigned fractional_bits) noexcept
{
if (raw < 0)
return 0;
const detail::u128 mag = detail::magnitude(raw);
if (fractional_bits >= 128 || mag < (detail::u128{1} << fractional_bits))
return 64;
return __builtin_clzll(static_cast<std::uint64_t>(mag >> fractional_bits));
}
template <typename Raw>
static constant_lut<Raw> project(unsigned fractional_bits)
{
using lim = std::numeric_limits<Raw>;
std::vector<Raw> cuts{ lim::min(), Raw{0} };
for (unsigned k = 0; k < 63; ++k)
{
const detail::u128 exponent = detail::u128{1} << k;
if (!detail::shift_fits(exponent, fractional_bits))
break;
const detail::u128 mag = exponent << fractional_bits;
if (mag > static_cast<detail::u128>(lim::max()))
break;
cuts.push_back(static_cast<Raw>(mag));
}
return detail::assemble<Raw>(std::move(cuts),
[=](Raw raw) { return eval<Raw>(raw, fractional_bits); });
}
};
/// 64-bit redundant sign bits of trunc(x) toward zero.
/// Positive q uses 62-floor(log2(q)); negative q uses 62-floor(log2(q-1)).
template <>
struct exact_lut<exact_constant::clrsb>
{
template <typename Raw>
static std::int64_t eval(Raw raw, unsigned fractional_bits) noexcept
{
const detail::u128 mag = detail::magnitude(raw);
const detail::u128 quotient = mag >> fractional_bits;
if (raw >= 0)
{
if (quotient == 0)
return 63;
return 62 - detail::floor_log2(quotient);
}
if (quotient > static_cast<detail::u128>(std::numeric_limits<std::int64_t>::max()))
return 0;
if (quotient <= 1)
return 63;
return 62 - detail::floor_log2(quotient - 1);
}
template <typename Raw>
static constant_lut<Raw> project(unsigned fractional_bits)
{
using lim = std::numeric_limits<Raw>;
std::vector<Raw> cuts{ lim::min(), Raw{0} };
cuts.push_back(static_cast<Raw>(static_cast<__int128>(lim::min()) + 1));
for (unsigned k = 0; k < 63; ++k)
{
const detail::u128 exponent = detail::u128{1} << k;
if (!detail::shift_fits(exponent, fractional_bits))
break;
const detail::u128 positive = exponent << fractional_bits;
if (positive <= static_cast<detail::u128>(lim::max()))
cuts.push_back(static_cast<Raw>(positive));
// Negative class q in [2^k+1, 2^{k+1}], most-negative raw first.
const detail::u128 q_hi = exponent << 1;
if (detail::shift_fits(q_hi + 1, fractional_bits))
{
const detail::u128 mag_hi = ((q_hi + 1) << fractional_bits) - 1;
detail::push_negative_magnitude<Raw>(mag_hi, cuts);
}
else
{
cuts.push_back(lim::min());
}
}
if (detail::shift_fits(detail::u128{2}, fractional_bits))
detail::push_negative_magnitude<Raw>((detail::u128{2} << fractional_bits) - 1, cuts);
return detail::assemble<Raw>(std::move(cuts),
[=](Raw raw) { return eval<Raw>(raw, fractional_bits); });
}
};
template <exact_constant Which, typename Raw>
std::int64_t evaluate_exact(Raw raw, unsigned fractional_bits)
{
constexpr unsigned bits = static_cast<unsigned>(std::numeric_limits<Raw>::digits + 1);
if (fractional_bits > bits)
throw std::invalid_argument("fractional bits exceed the raw width");
return exact_lut<Which>::template eval<Raw>(raw, fractional_bits);
}
template <typename Raw>
constant_lut<Raw> make_exact_constant_lut(exact_constant which, unsigned fractional_bits)
{
constexpr unsigned bits = static_cast<unsigned>(std::numeric_limits<Raw>::digits + 1);
if (fractional_bits > bits)
throw std::invalid_argument("fractional bits exceed the raw width");
switch (which)
{
case exact_constant::signum:
return exact_lut<exact_constant::signum>::template project<Raw>(fractional_bits);
case exact_constant::positive:
return exact_lut<exact_constant::positive>::template project<Raw>(fractional_bits);
case exact_constant::negative:
return exact_lut<exact_constant::negative>::template project<Raw>(fractional_bits);
case exact_constant::nonneg:
return exact_lut<exact_constant::nonneg>::template project<Raw>(fractional_bits);
case exact_constant::nonpos:
return exact_lut<exact_constant::nonpos>::template project<Raw>(fractional_bits);
case exact_constant::zero:
return exact_lut<exact_constant::zero>::template project<Raw>(fractional_bits);
case exact_constant::nonzero:
return exact_lut<exact_constant::nonzero>::template project<Raw>(fractional_bits);
case exact_constant::ilogb:
return exact_lut<exact_constant::ilogb>::template project<Raw>(fractional_bits);
case exact_constant::ceil_ilogb:
return exact_lut<exact_constant::ceil_ilogb>::template project<Raw>(fractional_bits);
case exact_constant::ilog10:
return exact_lut<exact_constant::ilog10>::template project<Raw>(fractional_bits);
case exact_constant::clz:
return exact_lut<exact_constant::clz>::template project<Raw>(fractional_bits);
case exact_constant::clrsb:
return exact_lut<exact_constant::clrsb>::template project<Raw>(fractional_bits);
}
throw std::invalid_argument("unknown exact constant");
}
/// Comparison against a public threshold. Two pieces; the cut sits on `bound`
/// (`lt` / `geq`) or just after it (`leq` / `gt`).
enum class threshold_cmp
{
lt,
leq,
gt,
geq
};
template <typename Raw>
std::int64_t evaluate_threshold(Raw raw, Raw bound, threshold_cmp kind) noexcept
{
switch (kind)
{
case threshold_cmp::lt: return raw < bound;
case threshold_cmp::leq: return raw <= bound;
case threshold_cmp::gt: return raw > bound;
case threshold_cmp::geq: return raw >= bound;
}
return 0;
}
template <typename Raw>
constant_lut<Raw> make_threshold_lut(Raw bound, threshold_cmp kind)
{
using lim = std::numeric_limits<Raw>;
std::vector<Raw> cuts{ lim::min(), bound };
if (bound < lim::max()
&& (kind == threshold_cmp::leq || kind == threshold_cmp::gt))
cuts.push_back(static_cast<Raw>(static_cast<__int128>(bound) + 1));
return detail::assemble<Raw>(std::move(cuts),
[=](Raw raw) { return evaluate_threshold(raw, bound, kind); });
}
/// `1` on the inclusive clip window `[low, high]`, `0` outside it.
template <typename Raw>
constant_lut<Raw> make_interval_lut(Raw low, Raw high)
{
if (low > high)
throw std::invalid_argument("interval lut: low > high");
using lim = std::numeric_limits<Raw>;
std::vector<Raw> cuts{ lim::min(), low };
if (high < lim::max())
cuts.push_back(static_cast<Raw>(static_cast<__int128>(high) + 1));
return detail::assemble<Raw>(std::move(cuts),
[=](Raw raw) { return raw >= low && raw <= high ? std::int64_t{1} : std::int64_t{0}; });
}
/// `floor(min(max(raw, low), high) / modulus)`, division toward -infinity.
///
/// `modulus`, `low`, and `high` are in the same raw units as the domain, so
/// one program covers every fractional precision: a mathematical step `M`
/// with `F` fractional bits is the raw modulus `M << F`. The paper's
/// `quot(M, T1, T2)` is this function. Piece count is about `(high-low)/modulus`;
/// the build rejects windows that would need more than 2^16 pieces.
template <typename Raw>
std::int64_t evaluate_clipped_quotient(Raw raw, Raw modulus, Raw low, Raw high)
{
if (modulus <= 0)
throw std::invalid_argument("clipped quotient: modulus must be positive");
if (low > high)
throw std::invalid_argument("clipped quotient: low > high");
const Raw clipped = raw < low ? low : (raw > high ? high : raw);
const __int128 n = clipped;
const __int128 d = modulus;
if (n >= 0)
return static_cast<std::int64_t>(n / d);
const __int128 neg = -n;
return static_cast<std::int64_t>(-((neg + d - 1) / d));
}
template <typename Raw>
constant_lut<Raw> make_clipped_quotient_lut(Raw modulus, Raw low, Raw high)
{
if (modulus <= 0)
throw std::invalid_argument("clipped quotient: modulus must be positive");
if (low > high)
throw std::invalid_argument("clipped quotient: low > high");
const __int128 span = static_cast<__int128>(high) - static_cast<__int128>(low);
if (span / modulus > (1 << 16))
throw std::invalid_argument("clipped quotient: modulus is too small for the window");
using lim = std::numeric_limits<Raw>;
std::vector<Raw> cuts{ lim::min(), low };
const __int128 d = modulus;
__int128 q = low >= 0
? static_cast<__int128>(low) / d
: -((-static_cast<__int128>(low) + d - 1) / d);
// First multiple of `modulus` strictly above `low`, through `high`.
for (__int128 boundary = (q + 1) * d; boundary <= high; boundary += d)
{
if (boundary > static_cast<__int128>(lim::max()))
break;
if (boundary >= static_cast<__int128>(lim::min()))
cuts.push_back(static_cast<Raw>(boundary));
}
return detail::assemble<Raw>(std::move(cuts),
[=](Raw raw) { return evaluate_clipped_quotient(raw, modulus, low, high); });
}
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_CONSTANT_LUT_HPP__

343
include/grotto/easy_lut.hpp Normal file
View file

@ -0,0 +1,343 @@
/// @file grotto/easy_lut.hpp
/// @brief Exact few-piece polynomials whose knots are obvious integers.
/// @details One program per function. A fractional width only slides knots
/// that sit on an integer (`k` becomes raw `k << F`) and scales
/// constant terms that are themselves integers. Slopes of `0`, `±1`,
/// and `1/2^s` stay exact; `hardsigmoid` / `hardswish` divide by 6
/// and round the final raw encoding to nearest, ties away from zero.
#ifndef LIBDPF_INCLUDE_GROTTO_EASY_LUT_HPP__
#define LIBDPF_INCLUDE_GROTTO_EASY_LUT_HPP__
#include <algorithm>
#include <cstdint>
#include <limits>
#include <optional>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <vector>
namespace grotto
{
/// Piece `y_raw = round((c0 + c1·raw + c2·raw²) / den)`.
template <typename Raw>
struct easy_lut
{
static_assert(std::is_integral_v<Raw> && std::is_signed_v<Raw>);
using raw_type = Raw;
std::vector<Raw> bounds;
std::vector<std::int64_t> c0;
std::vector<std::int64_t> c1;
std::vector<std::int64_t> c2;
std::vector<std::int64_t> den;
std::size_t parts() const noexcept { return c0.size(); }
std::int64_t operator()(Raw x) const
{
const auto it = std::upper_bound(bounds.begin(), bounds.end(), x);
const auto i = static_cast<std::size_t>(it - bounds.begin()) - 1;
const __int128 raw = x;
const __int128 acc = __int128(c0[i]) + __int128(c1[i]) * raw
+ __int128(c2[i]) * raw * raw;
return detail_round_div(acc, den[i]);
}
private:
static std::int64_t detail_round_div(__int128 num, std::int64_t den)
{
if (den <= 0)
throw std::invalid_argument("easy lut: denominator must be positive");
if (den == 1)
{
if (num > std::numeric_limits<std::int64_t>::max()
|| num < std::numeric_limits<std::int64_t>::min())
throw std::overflow_error("easy lut: value does not fit int64");
return static_cast<std::int64_t>(num);
}
const bool neg = num < 0;
const __int128 mag = neg ? -num : num;
const __int128 d = den;
const __int128 q = (mag + d / 2) / d;
const __int128 signed_q = neg ? -q : q;
if (signed_q > std::numeric_limits<std::int64_t>::max()
|| signed_q < std::numeric_limits<std::int64_t>::min())
throw std::overflow_error("easy lut: value does not fit int64");
return static_cast<std::int64_t>(signed_q);
}
};
namespace detail
{
struct easy_poly
{
std::int64_t c0 = 0;
std::int64_t c1 = 0;
std::int64_t c2 = 0;
std::int64_t den = 1;
};
inline bool operator==(easy_poly a, easy_poly b) noexcept
{
return a.c0 == b.c0 && a.c1 == b.c1 && a.c2 == b.c2 && a.den == b.den;
}
inline constexpr easy_poly kIdentity{0, 1, 0, 1};
inline constexpr easy_poly kZero{0, 0, 0, 1};
template <typename Raw>
std::optional<std::int64_t> scaled_integer(std::int64_t units, unsigned fractional_bits)
{
using lim = std::numeric_limits<Raw>;
if (fractional_bits >= 63)
return std::nullopt;
const __int128 v = static_cast<__int128>(units) << fractional_bits;
if (v < static_cast<__int128>(lim::min()) || v > static_cast<__int128>(lim::max()))
return std::nullopt;
return static_cast<std::int64_t>(v);
}
template <typename Raw, typename PolyAt>
easy_lut<Raw> assemble_easy(std::vector<std::int64_t> cuts, PolyAt && poly_at)
{
using lim = std::numeric_limits<Raw>;
cuts.push_back(static_cast<std::int64_t>(lim::min()));
std::sort(cuts.begin(), cuts.end());
cuts.erase(std::unique(cuts.begin(), cuts.end()), cuts.end());
const std::int64_t maxv = static_cast<std::int64_t>(lim::max());
cuts.erase(std::remove_if(cuts.begin(), cuts.end(),
[&](std::int64_t c) { return c > maxv; }), cuts.end());
easy_lut<Raw> lut;
for (std::size_t i = 0; i < cuts.size(); ++i)
{
const std::int64_t start = cuts[i];
const std::int64_t last = (i + 1 < cuts.size()) ? cuts[i + 1] - 1 : maxv;
const easy_poly poly = poly_at(start);
if (poly.den <= 0)
throw std::invalid_argument("easy lut: denominator must be positive");
if (!(poly == poly_at(last)))
throw std::logic_error("easy lut span is not one polynomial");
const __int128 width = static_cast<__int128>(last) - static_cast<__int128>(start);
if (width > 2)
{
const std::int64_t mid = static_cast<std::int64_t>(
static_cast<__int128>(start) + width / 2);
if (!(poly == poly_at(mid)))
throw std::logic_error("easy lut span is not one polynomial");
}
if (!lut.c0.empty() && poly == easy_poly{lut.c0.back(), lut.c1.back(), lut.c2.back(), lut.den.back()})
continue;
lut.bounds.push_back(static_cast<Raw>(start));
lut.c0.push_back(poly.c0);
lut.c1.push_back(poly.c1);
lut.c2.push_back(poly.c2);
lut.den.push_back(poly.den);
}
return lut;
}
inline std::int64_t denom_shift(unsigned shift)
{
if (shift >= 63)
throw std::invalid_argument("easy lut: dyadic slope is too small");
return std::int64_t{1} << shift;
}
} // namespace detail
template <typename Raw>
easy_lut<Raw> make_abs_lut(unsigned fractional_bits = 0)
{
(void)fractional_bits;
return detail::assemble_easy<Raw>({0}, [](std::int64_t raw) {
detail::easy_poly p = detail::kIdentity;
if (raw < 0)
p.c1 = -1;
return p;
});
}
template <typename Raw>
easy_lut<Raw> make_relu_lut(unsigned fractional_bits = 0)
{
(void)fractional_bits;
return detail::assemble_easy<Raw>({0}, [](std::int64_t raw) {
return raw < 0 ? detail::kZero : detail::kIdentity;
});
}
/// Negative side is `x / 2^shift`, rounded to nearest, ties away from zero.
/// `shift == 0` is the identity. The slope does not depend on fractional width.
template <typename Raw>
easy_lut<Raw> make_leaky_relu_lut(unsigned shift)
{
const std::int64_t den = detail::denom_shift(shift);
return detail::assemble_easy<Raw>({0}, [=](std::int64_t raw) {
if (raw >= 0)
return detail::kIdentity;
return detail::easy_poly{0, 1, 0, den};
});
}
template <typename Raw>
easy_lut<Raw> make_squared_relu_lut(unsigned fractional_bits)
{
const std::int64_t den = detail::denom_shift(fractional_bits);
return detail::assemble_easy<Raw>({0}, [=](std::int64_t raw) {
if (raw < 0)
return detail::kZero;
return detail::easy_poly{0, 0, 1, den};
});
}
namespace detail
{
template <typename Raw>
easy_lut<Raw> clip_to(unsigned fractional_bits, std::int64_t low_units, std::int64_t high_units)
{
if (low_units > high_units)
throw std::invalid_argument("clip lut: low > high");
const auto low = scaled_integer<Raw>(low_units, fractional_bits);
const auto high = scaled_integer<Raw>(high_units, fractional_bits);
std::vector<std::int64_t> cuts{0};
if (low)
cuts.push_back(*low);
if (high && *high < std::numeric_limits<Raw>::max())
cuts.push_back(*high + 1);
const std::int64_t low_raw = low ? *low : std::numeric_limits<std::int64_t>::min();
const std::int64_t high_raw = high ? *high : std::numeric_limits<std::int64_t>::max();
const std::int64_t low_level = low ? *low : 0;
const std::int64_t high_level = high ? *high : 0;
return assemble_easy<Raw>(std::move(cuts), [=](std::int64_t raw) {
if (low && raw < low_raw)
return easy_poly{low_level, 0, 0, 1};
if (high && raw > high_raw)
return easy_poly{high_level, 0, 0, 1};
return kIdentity;
});
}
} // namespace detail
template <typename Raw>
easy_lut<Raw> make_clip_lut(unsigned fractional_bits, std::int64_t low_units, std::int64_t high_units)
{
return detail::clip_to<Raw>(fractional_bits, low_units, high_units);
}
template <typename Raw>
easy_lut<Raw> make_relu6_lut(unsigned fractional_bits)
{
return make_clip_lut<Raw>(fractional_bits, 0, 6);
}
template <typename Raw>
easy_lut<Raw> make_hardtanh_lut(unsigned fractional_bits)
{
return make_clip_lut<Raw>(fractional_bits, -1, 1);
}
/// `0` on `[-1, 1]`, `x - 1` above, `x + 1` below.
template <typename Raw>
easy_lut<Raw> make_softshrink_lut(unsigned fractional_bits)
{
const auto knot = detail::scaled_integer<Raw>(1, fractional_bits);
std::vector<std::int64_t> cuts{0};
if (knot)
{
cuts.push_back(-*knot);
if (*knot < std::numeric_limits<Raw>::max())
cuts.push_back(*knot + 1);
}
const std::int64_t k = knot ? *knot : 0;
return detail::assemble_easy<Raw>(std::move(cuts), [=](std::int64_t raw) {
if (!knot || (raw >= -k && raw <= k))
return detail::kZero;
if (raw > k)
return detail::easy_poly{-k, 1, 0, 1};
return detail::easy_poly{k, 1, 0, 1};
});
}
/// `0` on `[-1, 1]`, identity outside. Lambda is the integer 1.
template <typename Raw>
easy_lut<Raw> make_hardshrink_lut(unsigned fractional_bits)
{
const auto knot = detail::scaled_integer<Raw>(1, fractional_bits);
std::vector<std::int64_t> cuts{0};
if (knot)
{
cuts.push_back(-*knot);
if (*knot < std::numeric_limits<Raw>::max())
cuts.push_back(*knot + 1);
}
const std::int64_t k = knot ? *knot : 0;
return detail::assemble_easy<Raw>(std::move(cuts), [=](std::int64_t raw) {
if (!knot || (raw >= -k && raw <= k))
return detail::kZero;
return detail::kIdentity;
});
}
/// `0` left of `-3`, `1` right of `3`, `(x + 3) / 6` between, rounded.
template <typename Raw>
easy_lut<Raw> make_hardsigmoid_lut(unsigned fractional_bits)
{
if (fractional_bits >= 62)
throw std::invalid_argument("hardsigmoid: fractional width does not fit");
const std::int64_t three = std::int64_t{3} << fractional_bits;
const std::int64_t one = std::int64_t{1} << fractional_bits;
const auto knot = detail::scaled_integer<Raw>(3, fractional_bits);
std::vector<std::int64_t> cuts;
if (knot)
{
cuts.push_back(-*knot);
if (*knot < std::numeric_limits<Raw>::max())
cuts.push_back(*knot + 1);
}
const std::int64_t k = knot ? *knot : three;
return detail::assemble_easy<Raw>(std::move(cuts), [=](std::int64_t raw) {
if (knot && raw < -k)
return detail::kZero;
if (knot && raw > k)
return detail::easy_poly{one, 0, 0, 1};
return detail::easy_poly{three, 1, 0, 6};
});
}
/// `0` left of `-3`, `x` right of `3`, `x(x + 3) / 6` between, rounded.
template <typename Raw>
easy_lut<Raw> make_hardswish_lut(unsigned fractional_bits)
{
if (fractional_bits >= 61)
throw std::invalid_argument("hardswish: fractional width does not fit the denominator");
const std::int64_t three = std::int64_t{3} << fractional_bits;
const std::int64_t den = 6 * (std::int64_t{1} << fractional_bits);
const auto knot = detail::scaled_integer<Raw>(3, fractional_bits);
std::vector<std::int64_t> cuts;
if (knot)
{
cuts.push_back(-*knot);
if (*knot < std::numeric_limits<Raw>::max())
cuts.push_back(*knot + 1);
}
const std::int64_t k = knot ? *knot : three;
return detail::assemble_easy<Raw>(std::move(cuts), [=](std::int64_t raw) {
if (knot && raw < -k)
return detail::kZero;
if (knot && raw > k)
return detail::kIdentity;
return detail::easy_poly{0, three, 1, den};
});
}
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_EASY_LUT_HPP__

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,392 @@
/// @file grotto/fixedpoint_mul.hpp
/// @brief Fixed-point product with a caller-chosen integer and fraction width.
/// @details The plaintext operation an ABY2.0 / Beaver multiplier reproduces.
/// Included from grotto/fixedpoint.hpp.
#ifndef LIBDPF_INCLUDE_GROTTO_FIXEDPOINT_MUL_HPP__
#define LIBDPF_INCLUDE_GROTTO_FIXEDPOINT_MUL_HPP__
#ifndef LIBDPF_INCLUDE_DPF_FIXEDPOINT_HPP__
#include "grotto/fixedpoint.hpp"
#endif
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <type_traits>
namespace grotto
{
/// @brief Shape of `fixed_mul`: the ring width and the public shift.
///
/// The product of the raw integers is taken modulo `2^multiply_bits`, which is
/// the narrowest ring whose low bits contain the requested window. Bits of
/// that product at and above `align_shift` are the output; bits below it are
/// the discarded fraction, and bits above the window are the discarded
/// integer part. Both discards are the low or high residue modulo a power of
/// two, so a negative value is floored onto the output ulp.
///
/// A Beaver triple replaces only the multiply in `Z/2^multiply_bits Z`.
/// Reducing each operand into that ring is local when it is a truncation or a
/// zero-extend. Sign-extending a narrower signed operand, and replicating the
/// product sign when `modulus_bits > multiply_bits`, are plaintext steps the
/// MPC protocol has to reproduce (they are not local on additive shares).
template <unsigned IntegerBits,
unsigned FractionalBits,
unsigned LhsFractionalBits,
typename LhsIntegral,
unsigned RhsFractionalBits,
typename RhsIntegral>
struct fixed_mul_plan
{
static constexpr unsigned integer_bits = IntegerBits;
static constexpr unsigned fractional_bits = FractionalBits;
static constexpr unsigned out_bits = IntegerBits + FractionalBits;
static constexpr unsigned lhs_width = dpf::utils::bitlength_of_v<LhsIntegral>;
static constexpr unsigned rhs_width = dpf::utils::bitlength_of_v<RhsIntegral>;
static constexpr bool lhs_signed = std::is_signed_v<LhsIntegral>;
static constexpr bool rhs_signed = std::is_signed_v<RhsIntegral>;
static constexpr bool operands_signed = lhs_signed || rhs_signed;
/// Right shift applied to the raw product. Negative means a left shift.
static constexpr int align_shift = static_cast<int>(LhsFractionalBits)
+ static_cast<int>(RhsFractionalBits)
- static_cast<int>(FractionalBits);
/// Bits of the product that the shift reads. Zero when a left shift
/// moves every product bit out of the output.
static constexpr int modulus_bits_signed = align_shift >= 0
? align_shift + static_cast<int>(out_bits)
: static_cast<int>(out_bits) + align_shift;
static constexpr unsigned modulus_bits = modulus_bits_signed > 0
? static_cast<unsigned>(modulus_bits_signed) : 0u;
/// Full two's-complement product fits in this many bits.
static constexpr unsigned product_bits = lhs_width + rhs_width;
static constexpr unsigned multiply_bits = modulus_bits < product_bits
? modulus_bits : product_bits;
static constexpr unsigned limbs = multiply_bits == 0u
? 0u : (multiply_bits + 63u) / 64u;
/// Signed storage exists through 128 bits. A wider window is the same
/// residue held in an unsigned fixed-point.
static constexpr bool result_is_signed = operands_signed && out_bits <= 128u;
static_assert(out_bits >= 1u && out_bits <= 256u,
"fixed-point product window must be between 1 and 256 bits");
static_assert(modulus_bits <= 768u,
"fixed-point product window exceeds 768 bits");
static_assert(limbs <= 8u, "fixed-point multiply uses at most 8 limbs");
private:
template <unsigned Bits, bool Signed>
struct storage
{
static constexpr unsigned width = Bits <= 8u ? 8u
: Bits <= 16u ? 16u
: Bits <= 32u ? 32u
: Bits <= 64u ? 64u
: Bits <= 128u ? 128u : 256u;
using type = std::conditional_t<Signed,
std::conditional_t<width <= 8u, std::int8_t,
std::conditional_t<width <= 16u, std::int16_t,
std::conditional_t<width <= 32u, std::int32_t,
std::conditional_t<width <= 64u, std::int64_t, simde_int128>>>>,
dpf::utils::integral_type_from_bitlength_t<width>>;
};
public:
using integral_type = typename storage<out_bits, result_is_signed>::type;
using result_type = fixedpoint<FractionalBits, integral_type>;
};
namespace detail
{
inline constexpr std::size_t fixed_mul_buf_limbs = 12;
constexpr void mask_to_bits(std::uint64_t * limbs, std::size_t nlimbs, unsigned bits) noexcept
{
if (bits >= nlimbs * 64u)
{
return;
}
const unsigned limb = bits / 64u;
const unsigned rem = bits % 64u;
if (rem == 0u)
{
for (std::size_t i = limb; i < nlimbs; ++i)
{
limbs[i] = 0;
}
return;
}
limbs[limb] &= (std::uint64_t{1} << rem) - 1u;
for (std::size_t i = limb + 1; i < nlimbs; ++i)
{
limbs[i] = 0;
}
}
constexpr bool test_bit(const std::uint64_t * limbs, unsigned bit) noexcept
{
return ((limbs[bit / 64u] >> (bit % 64u)) & 1u) != 0u;
}
constexpr void fill_ones(std::uint64_t * limbs, unsigned from, unsigned to) noexcept
{
for (unsigned bit = from; bit < to; )
{
const unsigned limb = bit / 64u;
const unsigned rem = bit % 64u;
const unsigned count = std::min(64u - rem, to - bit);
const std::uint64_t ones = count == 64u
? ~std::uint64_t{0}
: (std::uint64_t{1} << count) - 1u;
limbs[limb] |= ones << rem;
bit += count;
}
}
constexpr void sign_extend_range(std::uint64_t * limbs, unsigned from_bits, unsigned to_bits) noexcept
{
if (to_bits <= from_bits || from_bits == 0u)
{
return;
}
if (test_bit(limbs, from_bits - 1u))
{
fill_ones(limbs, from_bits, to_bits);
}
}
template <typename T>
constexpr void store_raw_limbs(const T & value, std::uint64_t out[4]) noexcept
{
out[0] = out[1] = out[2] = out[3] = 0;
if constexpr (std::is_same_v<T, uint256_t>)
{
out[0] = value.lower().lower();
out[1] = value.lower().upper();
out[2] = value.upper().lower();
out[3] = value.upper().upper();
}
else if constexpr (std::is_same_v<T, uint128_t>)
{
out[0] = value.lower();
out[1] = value.upper();
}
else if constexpr (std::is_same_v<T, simde_uint128> || std::is_same_v<T, simde_int128>)
{
const simde_uint128 bits = static_cast<simde_uint128>(value);
out[0] = static_cast<std::uint64_t>(bits);
out[1] = static_cast<std::uint64_t>(bits >> 64);
}
else
{
using unsigned_same = std::make_unsigned_t<T>;
out[0] = static_cast<std::uint64_t>(static_cast<unsigned_same>(value));
}
}
/// Low `dest_bits` of `value`, sign-extended when `value` is a narrower signed integer.
template <typename T>
constexpr void reduce_operand(const T & value, unsigned src_bits, bool is_signed,
unsigned dest_bits, std::uint64_t * dest, unsigned nlimbs) noexcept
{
for (unsigned i = 0; i < nlimbs; ++i)
{
dest[i] = 0;
}
std::uint64_t raw[4];
store_raw_limbs(value, raw);
mask_to_bits(raw, 4, src_bits);
const unsigned copying = nlimbs < 4u ? nlimbs : 4u;
for (unsigned i = 0; i < copying; ++i)
{
dest[i] = raw[i];
}
if (dest_bits > src_bits && is_signed)
{
sign_extend_range(dest, src_bits, dest_bits);
}
mask_to_bits(dest, nlimbs, dest_bits);
}
/// Product modulo `2^(64*nlimbs)`, using exactly `nlimbs` limbs of each operand.
constexpr void mul_low_limbs(std::uint64_t * out, const std::uint64_t * lhs,
const std::uint64_t * rhs, unsigned nlimbs) noexcept
{
for (unsigned i = 0; i < nlimbs; ++i)
{
out[i] = 0;
}
for (unsigned i = 0; i < nlimbs; ++i)
{
simde_uint128 carry = 0;
for (unsigned j = 0; i + j < nlimbs; ++j)
{
const simde_uint128 prod = simde_uint128(lhs[i]) * simde_uint128(rhs[j])
+ simde_uint128(out[i + j]) + carry;
out[i + j] = static_cast<std::uint64_t>(prod);
carry = prod >> 64;
}
}
}
constexpr void shift_left_limbs(std::uint64_t * limbs, std::size_t nlimbs, unsigned shift) noexcept
{
if (shift == 0u)
{
return;
}
const unsigned limb_shift = shift / 64u;
const unsigned bit_shift = shift % 64u;
std::uint64_t tmp[fixed_mul_buf_limbs] = {};
for (std::size_t i = limb_shift; i < nlimbs; ++i)
{
const std::size_t src = i - limb_shift;
std::uint64_t hi = limbs[src] << bit_shift;
std::uint64_t lo = 0;
if (bit_shift != 0u && src > 0u)
{
lo = limbs[src - 1u] >> (64u - bit_shift);
}
tmp[i] = hi | lo;
}
for (std::size_t i = 0; i < nlimbs; ++i)
{
limbs[i] = tmp[i];
}
}
constexpr void shift_right_limbs(std::uint64_t * limbs, std::size_t nlimbs, unsigned shift) noexcept
{
if (shift == 0u)
{
return;
}
const unsigned limb_shift = shift / 64u;
const unsigned bit_shift = shift % 64u;
std::uint64_t tmp[fixed_mul_buf_limbs] = {};
for (std::size_t i = 0; i + limb_shift < nlimbs; ++i)
{
const std::size_t src = i + limb_shift;
std::uint64_t lo = limbs[src] >> bit_shift;
std::uint64_t hi = 0;
if (bit_shift != 0u && src + 1u < nlimbs)
{
hi = limbs[src + 1u] << (64u - bit_shift);
}
tmp[i] = lo | hi;
}
for (std::size_t i = 0; i < nlimbs; ++i)
{
limbs[i] = tmp[i];
}
}
template <typename T>
constexpr T limbs_to_integral(const std::uint64_t * limbs) noexcept
{
if constexpr (std::is_same_v<T, uint256_t>)
{
return uint256_t{
uint128_t{limbs[3], limbs[2]},
uint128_t{limbs[1], limbs[0]}};
}
else if constexpr (std::is_same_v<T, uint128_t>)
{
return uint128_t{limbs[1], limbs[0]};
}
else if constexpr (std::is_same_v<T, simde_uint128> || std::is_same_v<T, simde_int128>)
{
const simde_uint128 bits = simde_uint128(limbs[0])
| (simde_uint128(limbs[1]) << 64);
return static_cast<T>(bits);
}
else
{
using unsigned_same = std::make_unsigned_t<T>;
return static_cast<T>(static_cast<unsigned_same>(limbs[0]));
}
}
} // namespace detail
/// @brief Multiply two fixed-point values into a chosen integer and fraction width.
/// @tparam IntegerBits Integer bits kept in the result, including the sign bit
/// when the result is signed. Bits above this wrap.
/// @tparam FractionalBits Fraction bits kept in the result. Lower fraction bits
/// of the exact product are discarded (floored).
///
/// The result is held in the smallest fixed-point word that can store
/// `IntegerBits + FractionalBits`. A signed word is used when either operand
/// is signed and the window is at most 128 bits; otherwise the window is the
/// unsigned residue.
template <unsigned IntegerBits,
unsigned FractionalBits,
unsigned LhsFractionalBits,
typename LhsIntegral,
unsigned RhsFractionalBits,
typename RhsIntegral>
constexpr auto fixed_mul(
fixedpoint<LhsFractionalBits, LhsIntegral> lhs,
fixedpoint<RhsFractionalBits, RhsIntegral> rhs) noexcept
-> typename fixed_mul_plan<IntegerBits, FractionalBits,
LhsFractionalBits, LhsIntegral, RhsFractionalBits, RhsIntegral>::result_type
{
using plan = fixed_mul_plan<IntegerBits, FractionalBits,
LhsFractionalBits, LhsIntegral, RhsFractionalBits, RhsIntegral>;
using integral = typename plan::integral_type;
if constexpr (plan::modulus_bits == 0u || plan::limbs == 0u)
{
return make_fixed_from_integral_type<FractionalBits, integral>(static_cast<integral>(0));
}
else
{
// 1. Local reduction into the multiply ring.
std::uint64_t left[8] = {};
std::uint64_t right[8] = {};
detail::reduce_operand(lhs.integral_representation(), plan::lhs_width, plan::lhs_signed,
plan::multiply_bits, left, plan::limbs);
detail::reduce_operand(rhs.integral_representation(), plan::rhs_width, plan::rhs_signed,
plan::multiply_bits, right, plan::limbs);
// 2. The single non-linear step: product in Z/2^multiply_bits Z.
std::uint64_t prod[detail::fixed_mul_buf_limbs] = {};
detail::mul_low_limbs(prod, left, right, plan::limbs);
detail::mask_to_bits(prod, detail::fixed_mul_buf_limbs, plan::multiply_bits);
// 3. Public extension up to the window, then the public radix shift.
if constexpr (plan::operands_signed)
{
detail::sign_extend_range(prod, plan::multiply_bits, plan::modulus_bits);
}
if constexpr (plan::align_shift > 0)
{
detail::shift_right_limbs(prod, detail::fixed_mul_buf_limbs,
static_cast<unsigned>(plan::align_shift));
}
else if constexpr (plan::align_shift < 0)
{
detail::shift_left_limbs(prod, detail::fixed_mul_buf_limbs,
static_cast<unsigned>(-plan::align_shift));
}
detail::mask_to_bits(prod, detail::fixed_mul_buf_limbs, plan::out_bits);
if constexpr (plan::result_is_signed)
{
detail::sign_extend_range(prod, plan::out_bits,
dpf::utils::bitlength_of_v<integral>);
}
return make_fixed_from_integral_type<FractionalBits, integral>(
detail::limbs_to_integral<integral>(prod));
}
}
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_FIXEDPOINT_MUL_HPP__

View file

@ -0,0 +1,69 @@
/// @file grotto/gadget_hints.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @details
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGET_HINTS_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGET_HINTS_HPP__
#include <cmath>
#include <array>
#include <limits>
namespace grotto
{
namespace gadgets
{
template <typename T>
struct gadget_hints
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr unsigned degree = 3;
static constexpr double * poles = nullptr;
static constexpr double * interesting_points = nullptr;
static constexpr bool has_canonical_representation = false;
static constexpr double * canonical_bounds = nullptr;
static constexpr std::array<double, degree+1> * canonical_polys = nullptr;
};
constexpr double ulp_of(double x)
{
return std::max(
std::abs(std::nexttoward(x, std::numeric_limits<double>::infinity())-x),
std::abs(std::nexttoward(x, x-std::numeric_limits<double>::infinity())));
}
template <typename T, std::size_t N>
struct gadget_domain
{
static constexpr T min()
{
double fmin = std::max(gadget_hints<T>::min,
-std::exp2(std::numeric_limits<T>::bits-N));
T tmin = static_cast<T>(fmin);
if (static_cast<double>(tmin) < fmin) tmin += std::exp2(-N);
return tmin;
}
static constexpr T max()
{
double fmax = std::max(gadget_hints<T>::max,
std::exp2(std::numeric_limits<T>::bits-N) - std::exp2(-N));
T tmax = static_cast<T>(fmax);
if (static_cast<double>(tmax) > fmax) tmax -= std::exp2(-N);
return tmax;
}
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGET_HINTS_HPP__

View file

@ -0,0 +1,24 @@
/// @file grotto/gadgets.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @details
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HPP__
// #include "grotto/gadgets/activations.hpp"
// #include "grotto/gadgets/binary.hpp"
#include "grotto/gadgets/decimal.hpp"
// #include "grotto/gadgets/elementary.hpp"
#include "grotto/gadgets/exponential.hpp"
// #include "grotto/gadgets/hyperbolic.hpp"
// #include "grotto/gadgets/logarithm.hpp"
// #include "grotto/gadgets/misc.hpp"
// #include "grotto/gadgets/powers.hpp"
// #include "grotto/gadgets/quantile.hpp"
// #include "grotto/gadgets/trigonometric.hpp"
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HPP__

View file

@ -0,0 +1,42 @@
/// @file grotto/gadgets/activations.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HPP__
#include "grotto/gadgets/activations/celu.hpp"
#include "grotto/gadgets/activations/elish.hpp"
#include "grotto/gadgets/activations/elu.hpp"
#include "grotto/gadgets/activations/gelu.hpp"
#include "grotto/gadgets/activations/hardelish.hpp"
#include "grotto/gadgets/activations/hardshrink.hpp"
#include "grotto/gadgets/activations/hardsigmoid.hpp"
#include "grotto/gadgets/activations/hardswish.hpp"
#include "grotto/gadgets/activations/hardtanh.hpp"
#include "grotto/gadgets/activations/leakyrelu.hpp"
#include "grotto/gadgets/activations/lecun_tanh.hpp"
#include "grotto/gadgets/activations/logsigmoid.hpp"
#include "grotto/gadgets/activations/mish.hpp"
#include "grotto/gadgets/activations/one_minus_sigmoid.hpp"
#include "grotto/gadgets/activations/relu.hpp"
#include "grotto/gadgets/activations/relu6.hpp"
#include "grotto/gadgets/activations/selu.hpp"
#include "grotto/gadgets/activations/serf.hpp"
#include "grotto/gadgets/activations/sigmoid.hpp"
#include "grotto/gadgets/activations/silu.hpp"
#include "grotto/gadgets/activations/smoothstep.hpp"
#include "grotto/gadgets/activations/softminus.hpp"
#include "grotto/gadgets/activations/softplus.hpp"
#include "grotto/gadgets/activations/softshrink.hpp"
#include "grotto/gadgets/activations/softsign.hpp"
#include "grotto/gadgets/activations/squared_relu.hpp"
#include "grotto/gadgets/hyperbolic/tanh.hpp"
#include "grotto/gadgets/activations/starrelu.hpp"
#include "grotto/gadgets/activations/tanhexp.hpp"
#include "grotto/gadgets/activations/tanhshrink.hpp"
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATION_HPP__

View file

@ -0,0 +1,51 @@
/// @file grotto/gadgets/activations/celu.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_CELU_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_CELU_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double celu_default_alpha = 1;
template <double const & alpha = celu_default_alpha>
struct celu
{
template <typename T>
T operator()(T x)
{
return std::min(std::max(0, x) + std::min(0, alpha * std::expm1(x / alpha)), std::numeric_limits<T>::max());
}
};
template <double const & alpha>
struct gadget_hints<celu<alpha>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_CELU_HPP__

View file

@ -0,0 +1,51 @@
/// @file grotto/gadgets/activations/elish.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELISH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELISH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "sigmoid.hpp"
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct elish
{
template <typename T>
T operator()(T x)
{
if (x < 0) return std::expm1(x)*sigmoid{}(x);
if (x >= 0) return std::min(x*sigmoid{}(x), std::numeric_limits<T>::max());
}
};
template <>
struct gadget_hints<elish>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELISH_HPP__

View file

@ -0,0 +1,52 @@
/// @file grotto/gadgets/activations/elu.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELU_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELU_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double elu_default_alpha = 1;
template <double const & alpha = elu_default_alpha>
struct elu
{
template <typename T>
T operator()(T x)
{
if (x <= 0) return alpha * std::expm1(x);
if (x > 0) return std::min(x, std::numeric_limits<T>::max());
}
};
template <double const & alpha>
struct gadget_hints<elu<alpha>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELU_HPP__

View file

@ -0,0 +1,49 @@
/// @file grotto/gadgets/activations/gelu.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_GELU_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_GELU_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct gelu
{
template <typename T>
T operator()(T x)
{
return std::min(x*(1+std::erf(x/std::sqrt(2)))/2, std::numeric_limits<T>::max());
}
};
template <>
struct gadget_hints<gelu>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_GELU_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/activations/hardelish.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDELISH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDELISH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct hardelish
{
template <typename T>
T operator()(T x)
{
if (x < 0) return std::expm1(x)*std::max(0, std::min(1,(x+1)/2));
if (x >= 0) return std::min(x*std::max(0,std::min(1,(x+1)/2)), std::numeric_limits<T>::max());
}
};
template <>
struct gadget_hints<hardelish>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDELISH_HPP__

View file

@ -0,0 +1,52 @@
/// @file grotto/gadgets/activations/hardshrink.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSHRINK_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSHRINK_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double hardshrink_default_lambda = 0.5;
template <double const & lambda = hardshrink_default_lambda>
struct hardshrink
{
template <typename T>
T operator()(T x)
{
if (std::abs(x) <= lambda) return 0;
return x;
}
};
template <double const & lambda>
struct gadget_hints<hardshrink<lambda>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { -lambda, lambda };
static constexpr unsigned degree = 1;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { -lambda, lambda };
static constexpr std::array<double, degree+1> canonical_polys[] = { {0,1}, {0}, {0,1} };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSHRINK_HPP__

View file

@ -0,0 +1,51 @@
/// @file grotto/gadgets/activations/hardsigmoid.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSIGMOID_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSIGMOID_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct hardsigmoid
{
template <typename T>
T operator()(T x)
{
if (x <= -3) return 0;
if (x >= 3) return 1;
return (x+3)/6;
}
};
template <>
struct gadget_hints<hardsigmoid>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { -3, 3 };
static constexpr unsigned degree = 1;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { -3, 3 };
static constexpr std::array<double, degree+1> canonical_polys[] = { {0}, {0.5,1/6.0}, {1} };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSIGMOID_HPP__

View file

@ -0,0 +1,51 @@
/// @file grotto/gadgets/activations/hardswish.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSWISH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSWISH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct hardswish
{
template <typename T>
T operator()(T x)
{
if (x <= -3) return 0;
if (x >= 3) return x;
return x*(x+3)/6;
}
};
template <>
struct gadget_hints<hardswish>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { -3, 3 };
static constexpr unsigned degree = 2;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { -3, 3 };
static constexpr std::array<double, degree+1> canonical_polys[] = { {0}, {0,0.5,1/6.0}, {0,1,0} };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSWISH_HPP__

View file

@ -0,0 +1,51 @@
/// @file grotto/gadgets/activations/hardtanh.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDTANH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDTANH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct hardtanh
{
template <typename T>
T operator()(T x)
{
if (x <= -1) return -1;
if (x >= 1) return 1;
return x;
}
};
template <>
struct gadget_hints<hardtanh>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { -1, 1 };
static constexpr unsigned degree = 1;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { -1, 1 };
static constexpr std::array<double, degree+1> canonical_polys[] = { {-1}, {0,1}, {1} };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDTANH_HPP__

View file

@ -0,0 +1,53 @@
/// @file grotto/gadgets/activations/leakyrelu.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LEAKYRELU_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LEAKYRELU_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double leakyrelu_default_negative_slope = 0.01;
static constexpr double leakyrelu_zero_negative_slope = 0.0;
template <double const & negative_slope = leakyrelu_default_negative_slope>
struct leakyrelu
{
template <typename T>
T operator()(T x)
{
if (x >= 0) return x;
return negative_slope * x;
}
};
template <double const & negative_slope>
struct gadget_hints<leakyrelu<negative_slope>>
{
inline static constexpr double min = std::numeric_limits<double>::lowest();
inline static constexpr double max = std::numeric_limits<double>::max();
inline static constexpr double poles[] = { };
inline static constexpr double interesting_points[] = { 0 };
inline static constexpr unsigned degree = 1;
inline static constexpr bool has_canonical_representation = true;
inline static constexpr double canonical_bounds[] = { 0 };
inline static constexpr std::array<double, degree+1> canonical_polys[] = { {0,negative_slope}, {0,1} };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LEAKYRELU_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/activations/lecun_tanh.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LECUNTANH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LECUNTANH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct lecun_tanh
{
template <typename T>
T operator()(T x)
{
return 1.7159*std::tanh(2*x/3);
}
};
template <>
struct gadget_hints<lecun_tanh>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LECUNTANH_HPP__

View file

@ -0,0 +1,47 @@
/// @file grotto/gadgets/activations/logsigmoid.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LOGSIGMOID_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LOGSIGMOID_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "sigmoid.hpp"
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct logsigmoid
{
template <typename T>
T operator()(T x) { return std::log(sigmoid{}(x)); }
};
template <>
struct gadget_hints<logsigmoid>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LOGSIGMOID_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/activations/mish.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_MISH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_MISH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "softplus.hpp"
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct mish
{
template <typename T>
T operator()(T x)
{
return x*std::tanh(softplus<>{}(x));
}
};
template <>
struct gadget_hints<mish>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_MISH_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/activations/one_minus_relu.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ONE_MINUS_SIGMOID_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ONE_MINUS_SIGMOID_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "sigmoid.hpp"
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct one_minus_sigmoid
{
template <typename T>
T operator()(T x)
{
return 1-sigmoid{}(x);
}
};
template <>
struct gadget_hints<one_minus_sigmoid>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ONE_MINUS_SIGMOID_HPP__

View file

@ -0,0 +1,30 @@
/// @file grotto/gadgets/activations/relu.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "leakyrelu.hpp"
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
using relu = leakyrelu<leakyrelu_zero_negative_slope>;
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU_HPP__

View file

@ -0,0 +1,51 @@
/// @file grotto/gadgets/activations/relu6.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU6_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU6_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double relu6_default_clip = 6;
template <double const & clip = 6>
struct relu6
{
template <typename T>
T operator()(T x)
{
return std::min(std::max(0, x), clip);
}
};
template <double const & clip>
struct gadget_hints<relu6<clip>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { 0, clip };
static constexpr unsigned degree = 1;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { 0, clip };
static constexpr std::array<double, degree+1> canonical_polys[] = { 0, {0,1}, clip };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU6_HPP__

View file

@ -0,0 +1,53 @@
/// @file grotto/gadgets/activations/selu.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SELU_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SELU_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double selu_default_alpha = 1.6732632423543772848170429916717;
static constexpr double selu_default_scale = 1.0507009873554804934193349852946;
template <double const & alpha = selu_default_alpha,
double const & scale = selu_default_scale>
struct selu
{
template <typename T>
T operator()(T x)
{
return scale*(std::max(0,x)+std::min(0,alpha*std::expm1(x)));
}
};
template <double const & alpha, double const & scale>
struct gadget_hints<selu<alpha, scale>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SELU_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/activations/serf.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SERF_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SERF_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "softplus.hpp"
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct serf
{
template <typename T>
T operator()(T x)
{
return x*std::erf(softplus<>{}(x));
}
};
template <>
struct gadget_hints<serf>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SERF_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/activations/sigmoid.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SIGMOID_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SIGMOID_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct sigmoid
{
template <typename T>
T operator()(T x) { return 1/(1+std::exp(-x)); }
};
template <>
struct gadget_hints<sigmoid>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SIGMOID_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/activations/silu.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SILU_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SILU_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct silu
{
template <typename T>
T operator()(T x) { return x*sigmoid{}(x); }
};
template <>
struct gadget_hints<silu>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SILU_HPP__

View file

@ -0,0 +1,53 @@
/// @file grotto/gadgets/activations/smoothstep.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SMOOTHSTEP_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SMOOTHSTEP_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double smoothstep_default_gamma = 1;
template <double const & gamma = smoothstep_default_gamma>
struct smoothstep
{
template <typename T>
T operator()(T x)
{
if (x <= -gamma/2) return 0;
if (x <= gamma/2) return 1;
if (std::abs(x) < gamma/2) return (-2/(gamma*gamma*gamma))*x*x*x+(3/(2*gamma))*x+0.5;
}
};
template <double const & gamma>
struct gadget_hints<smoothstep<gamma>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { -gamma/2, gamma/2 };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { -gamma/2, gamma/2 };
static constexpr std::array<double, degree+1> canonical_polys[] = { 0, {-2/(gamma*gamma*gamma),0,3/(2*gamma),0.5}, 1 };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SMOOTHSTEP_HPP__

View file

@ -0,0 +1,52 @@
/// @file grotto/gadgets/activations/softminus.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTMINUS_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTMINUS_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "softplus.hpp"
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double softminus_default_beta = 1;
template <double const & beta = softminus_default_beta>
struct softminus
{
template <typename T>
T operator()(T x)
{
return beta*x-softplus<beta>{}(x);
}
};
template <double const & beta>
struct gadget_hints<softminus<beta>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { 20 };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTMINUS_HPP__

View file

@ -0,0 +1,52 @@
/// @file grotto/gadgets/activations/softplus.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTPLUS_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTPLUS_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double softplus_default_beta = 1;
template <double const & beta = softplus_default_beta>
struct softplus
{
template <typename T>
T operator()(T x)
{
if (x > 20) return x*beta;
return (std::log1p(std::exp(beta*x)))/beta;
}
};
template <double const & beta>
struct gadget_hints<softplus<beta>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { 20 };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTPLUS_HPP__

View file

@ -0,0 +1,53 @@
/// @file grotto/gadgets/activations/softshrink.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTSHRINK_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTSHRINK_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double softshrink_default_lambda = 0.5;
template <double const & lambda = softshrink_default_lambda>
struct softshrink
{
template <typename T>
T operator()(T x)
{
if (std::abs(x) <= lambda) return 0;
if (x < lambda) return x+lambda;
if (x > lambda) return x-lambda;
}
};
template <double const & lambda>
struct gadget_hints<softshrink<lambda>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { -lambda, lambda };
static constexpr unsigned degree = 1;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { -lambda, lambda };
static constexpr std::array<double, degree+1> canonical_polys[] = { {lambda,1}, {0}, {-lambda,1} };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTSHRINK_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/activations/softsign.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTSIGN_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTSIGN_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct hardsign
{
template <typename T>
T operator()(T x) { return x/(1+std::abs(x)); }
};
template <>
struct gadget_hints<hardsign>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 1;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTSIGN_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/activations/squared_relu.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SQUAREDRELU_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SQUAREDRELU_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct squared_relu
{
template <typename T>
T operator()(T x)
{
if (x >= 0) return x*x;
return 0;
}
};
template <>
struct gadget_hints<squared_relu>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { 0 };
static constexpr unsigned degree = 2;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { 0 };
static constexpr std::array<double, degree+1> canonical_polys[] = { {0}, {0,0,1} };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SQUAREDRELU_HPP__

View file

@ -0,0 +1,54 @@
/// @file grotto/gadgets/activations/starrelu.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_STARRELU_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_STARRELU_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double starrelu_default_scale = 0.8944;
static constexpr double starrelu_default_shift = -0.4472;
template<double const & scale = starrelu_default_scale,
double const & shift = starrelu_default_shift>
struct starrelu
{
template <typename T>
T operator()(T x)
{
if (x < 0) return 0;
return scale*x*x+shift;
}
};
template <double const & scale, double const & shift>
struct gadget_hints<starrelu<shift, scale>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { 0 };
static constexpr unsigned degree = 2;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { 0 };
static constexpr std::array<double, degree+1> canonical_polys[] = { {0}, {0,0,1} };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_STARRELU_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/activations/tanhexp.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHEXP_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHEXP_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct tanhexp
{
template <typename T>
T operator()(T x) { return x*std::tanh(std::exp(x)); }
};
template <>
struct gadget_hints<tanhexp>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHEXP_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/activations/tanhshrink.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHSHRINK_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHSHRINK_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct tanhshrink
{
template <typename T>
T operator()(T x) { return x -std::tanh(x); }
};
template <>
struct gadget_hints<tanhshrink>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHSHRINK_HPP__

View file

@ -0,0 +1,22 @@
/// @file grotto/gadgets/binary.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_HPP__
// #include "binary/bit.hpp"
// #include "binary/bit_ceil.hpp"
// #include "binary/bit_floor.hpp"
// #include "binary/bit_width.hpp"
// #include "binary/clrsb.hpp"
// #include "binary/countl_one.hpp"
// #include "binary/countl_zero.hpp"
#include "grotto/gadgets/binary/has_single_bit.hpp"
// #include "elementary/prefix.hpp"
#include "grotto/gadgets/binary/sgn.hpp"
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/binary/bt.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/binary/bit_ceil.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief gadgetized form of `std::bit_ceil`
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_CEIL_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_CEIL_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_CEIL_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/binary/bit_floor.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief gadgetized form of `std::bit_floor`
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_FLOOR_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_FLOOR_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_FLOOR_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/binary/bit_width.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief gadgetized form of `std::bit_width`
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_WIDTH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_WIDTH_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_WIDTH_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/binary/clrsb.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief gadgetized form of `__builtin_clzll`
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_CLRSB_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_CLRSB_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_CLRSB_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/binary/countl_one.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief gadgetized form of `std::countl_one`
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ONE_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ONE_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ONE_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/binary/countl_zero.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief gadgetized form of `std::countl_zero`
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ZERO_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ZERO_HPP__
#include <array>
#include <limits>
#include <portable-snippets/builtin/builtin.h>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct countl_zero
{
template <typename T>
T operator()(T x)
{
if (x == 0) return std::numeric_limits<T>::bits();
return psnip_builtin_clz64(static_cast<uint64_t>(static_cast<double>(x)));
}
};
template <>
struct gadget_hints<countl_zero>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { 0 };
static constexpr unsigned degree = 0;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> hint_canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ZERO_HPP__

View file

@ -0,0 +1,255 @@
/// @file grotto/gadgets/binary/has_single_bit.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief gadgetized form of `std::has_single_bit`
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_HAS_SINGLE_BIT_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_HAS_SINGLE_BIT_HPP__
#include <array>
#include <limits>
#include <portable-snippets/builtin/builtin.h>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct has_single_bit
{
template <typename T>
T operator()(T x)
{
if (x == 0) return 0;
uint64_t x_ = static_cast<uint64_t>(static_cast<double>(x > 0 ? x : 1.0 / x));
return psnip_builtin_popcount64(x_) == 1 ? 1 : 0;
}
};
template <>
struct gadget_hints<has_single_bit>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = {
-0x1.0000000000000p+0063, +0x1.0000000000000p-0063,
+0x1.0000000000000p-0062, +0x1.0000000000000p-0061,
+0x1.0000000000000p-0060, +0x1.0000000000000p-0059,
+0x1.0000000000000p-0058, +0x1.0000000000000p-0057,
+0x1.0000000000000p-0056, +0x1.0000000000000p-0055,
+0x1.0000000000000p-0054, +0x1.0000000000000p-0053,
+0x1.0000000000000p-0052, +0x1.0000000000000p-0051,
+0x1.0000000000000p-0050, +0x1.0000000000000p-0049,
+0x1.0000000000000p-0048, +0x1.0000000000000p-0047,
+0x1.0000000000000p-0046, +0x1.0000000000000p-0045,
+0x1.0000000000000p-0044, +0x1.0000000000000p-0043,
+0x1.0000000000000p-0042, +0x1.0000000000000p-0041,
+0x1.0000000000000p-0040, +0x1.0000000000000p-0039,
+0x1.0000000000000p-0038, +0x1.0000000000000p-0037,
+0x1.0000000000000p-0036, +0x1.0000000000000p-0035,
+0x1.0000000000000p-0034, +0x1.0000000000000p-0033,
+0x1.0000000000000p-0032, +0x1.0000000000000p-0031,
+0x1.0000000000000p-0030, +0x1.0000000000000p-0029,
+0x1.0000000000000p-0028, +0x1.0000000000000p-0027,
+0x1.0000000000000p-0026, +0x1.0000000000000p-0025,
+0x1.0000000000000p-0024, +0x1.0000000000000p-0023,
+0x1.0000000000000p-0022, +0x1.0000000000000p-0021,
+0x1.0000000000000p-0020, +0x1.0000000000000p-0019,
+0x1.0000000000000p-0018, +0x1.0000000000000p-0017,
+0x1.0000000000000p-0016, +0x1.0000000000000p-0015,
+0x1.0000000000000p-0014, +0x1.0000000000000p-0013,
+0x1.0000000000000p-0012, +0x1.0000000000000p-0011,
+0x1.0000000000000p-0010, +0x1.0000000000000p-0009,
+0x1.0000000000000p-0008, +0x1.0000000000000p-0007,
+0x1.0000000000000p-0006, +0x1.0000000000000p-0005,
+0x1.0000000000000p-0004, +0x1.0000000000000p-0003,
+0x1.0000000000000p-0002, +0x1.0000000000000p-0001,
+0x1.0000000000000p+0000, +0x1.0000000000000p+0001,
+0x1.0000000000000p+0002, +0x1.0000000000000p+0003,
+0x1.0000000000000p+0004, +0x1.0000000000000p+0005,
+0x1.0000000000000p+0006, +0x1.0000000000000p+0007,
+0x1.0000000000000p+0008, +0x1.0000000000000p+0009,
+0x1.0000000000000p+0010, +0x1.0000000000000p+0011,
+0x1.0000000000000p+0012, +0x1.0000000000000p+0013,
+0x1.0000000000000p+0014, +0x1.0000000000000p+0015,
+0x1.0000000000000p+0016, +0x1.0000000000000p+0017,
+0x1.0000000000000p+0018, +0x1.0000000000000p+0019,
+0x1.0000000000000p+0020, +0x1.0000000000000p+0021,
+0x1.0000000000000p+0022, +0x1.0000000000000p+0023,
+0x1.0000000000000p+0024, +0x1.0000000000000p+0025,
+0x1.0000000000000p+0026, +0x1.0000000000000p+0027,
+0x1.0000000000000p+0028, +0x1.0000000000000p+0029,
+0x1.0000000000000p+0030, +0x1.0000000000000p+0031,
+0x1.0000000000000p+0032, +0x1.0000000000000p+0033,
+0x1.0000000000000p+0034, +0x1.0000000000000p+0035,
+0x1.0000000000000p+0036, +0x1.0000000000000p+0037,
+0x1.0000000000000p+0038, +0x1.0000000000000p+0039,
+0x1.0000000000000p+0040, +0x1.0000000000000p+0041,
+0x1.0000000000000p+0042, +0x1.0000000000000p+0043,
+0x1.0000000000000p+0044, +0x1.0000000000000p+0045,
+0x1.0000000000000p+0046, +0x1.0000000000000p+0047,
+0x1.0000000000000p+0048, +0x1.0000000000000p+0049,
+0x1.0000000000000p+0050, +0x1.0000000000000p+0051,
+0x1.0000000000000p+0052, +0x1.0000000000000p+0053,
+0x1.0000000000000p+0054, +0x1.0000000000000p+0055,
+0x1.0000000000000p+0056, +0x1.0000000000000p+0057,
+0x1.0000000000000p+0058, +0x1.0000000000000p+0059,
+0x1.0000000000000p+0060, +0x1.0000000000000p+0061,
+0x1.0000000000000p+0062 };
static constexpr unsigned degree = 0;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = {
-0x1.0000000000000p+0063, -0x1.0000000000000p+0063,
+0x1.0000000000000p-0063, +0x1.0000000000000p-0063,
+0x1.0000000000000p-0062, +0x1.0000000000000p-0062,
+0x1.0000000000000p-0061, +0x1.0000000000000p-0061,
+0x1.0000000000000p-0060, +0x1.0000000000000p-0060,
+0x1.0000000000000p-0059, +0x1.0000000000000p-0059,
+0x1.0000000000000p-0058, +0x1.0000000000000p-0058,
+0x1.0000000000000p-0057, +0x1.0000000000000p-0057,
+0x1.0000000000000p-0056, +0x1.0000000000000p-0056,
+0x1.0000000000000p-0055, +0x1.0000000000000p-0055,
+0x1.0000000000000p-0054, +0x1.0000000000000p-0054,
+0x1.0000000000000p-0053, +0x1.0000000000000p-0053,
+0x1.0000000000000p-0052, +0x1.0000000000000p-0052,
+0x1.0000000000000p-0051, +0x1.0000000000000p-0051,
+0x1.0000000000000p-0050, +0x1.0000000000000p-0050,
+0x1.0000000000000p-0049, +0x1.0000000000000p-0049,
+0x1.0000000000000p-0048, +0x1.0000000000000p-0048,
+0x1.0000000000000p-0047, +0x1.0000000000000p-0047,
+0x1.0000000000000p-0046, +0x1.0000000000000p-0046,
+0x1.0000000000000p-0045, +0x1.0000000000000p-0045,
+0x1.0000000000000p-0044, +0x1.0000000000000p-0044,
+0x1.0000000000000p-0043, +0x1.0000000000000p-0043,
+0x1.0000000000000p-0042, +0x1.0000000000000p-0042,
+0x1.0000000000000p-0041, +0x1.0000000000000p-0041,
+0x1.0000000000000p-0040, +0x1.0000000000000p-0040,
+0x1.0000000000000p-0039, +0x1.0000000000000p-0039,
+0x1.0000000000000p-0038, +0x1.0000000000000p-0038,
+0x1.0000000000000p-0037, +0x1.0000000000000p-0037,
+0x1.0000000000000p-0036, +0x1.0000000000000p-0036,
+0x1.0000000000000p-0035, +0x1.0000000000000p-0035,
+0x1.0000000000000p-0034, +0x1.0000000000000p-0034,
+0x1.0000000000000p-0033, +0x1.0000000000000p-0033,
+0x1.0000000000000p-0032, +0x1.0000000000000p-0032,
+0x1.0000000000000p-0031, +0x1.0000000000000p-0031,
+0x1.0000000000000p-0030, +0x1.0000000000000p-0030,
+0x1.0000000000000p-0029, +0x1.0000000000000p-0029,
+0x1.0000000000000p-0028, +0x1.0000000000000p-0028,
+0x1.0000000000000p-0027, +0x1.0000000000000p-0027,
+0x1.0000000000000p-0026, +0x1.0000000000000p-0026,
+0x1.0000000000000p-0025, +0x1.0000000000000p-0025,
+0x1.0000000000000p-0024, +0x1.0000000000000p-0024,
+0x1.0000000000000p-0023, +0x1.0000000000000p-0023,
+0x1.0000000000000p-0022, +0x1.0000000000000p-0022,
+0x1.0000000000000p-0021, +0x1.0000000000000p-0021,
+0x1.0000000000000p-0020, +0x1.0000000000000p-0020,
+0x1.0000000000000p-0019, +0x1.0000000000000p-0019,
+0x1.0000000000000p-0018, +0x1.0000000000000p-0018,
+0x1.0000000000000p-0017, +0x1.0000000000000p-0017,
+0x1.0000000000000p-0016, +0x1.0000000000000p-0016,
+0x1.0000000000000p-0015, +0x1.0000000000000p-0015,
+0x1.0000000000000p-0014, +0x1.0000000000000p-0014,
+0x1.0000000000000p-0013, +0x1.0000000000000p-0013,
+0x1.0000000000000p-0012, +0x1.0000000000000p-0012,
+0x1.0000000000000p-0011, +0x1.0000000000000p-0011,
+0x1.0000000000000p-0010, +0x1.0000000000000p-0010,
+0x1.0000000000000p-0009, +0x1.0000000000000p-0009,
+0x1.0000000000000p-0008, +0x1.0000000000000p-0008,
+0x1.0000000000000p-0007, +0x1.0000000000000p-0007,
+0x1.0000000000000p-0006, +0x1.0000000000000p-0006,
+0x1.0000000000000p-0005, +0x1.0000000000000p-0005,
+0x1.0000000000000p-0004, +0x1.0000000000000p-0004,
+0x1.0000000000000p-0003, +0x1.0000000000000p-0003,
+0x1.0000000000000p-0002, +0x1.0000000000000p-0002,
+0x1.0000000000000p-0001, +0x1.0000000000000p-0001,
+0x1.0000000000000p+0000, +0x1.0000000000000p+0000,
+0x1.0000000000000p+0001, +0x1.0000000000000p+0001,
+0x1.0000000000000p+0002, +0x1.0000000000000p+0002,
+0x1.0000000000000p+0003, +0x1.0000000000000p+0003,
+0x1.0000000000000p+0004, +0x1.0000000000000p+0004,
+0x1.0000000000000p+0005, +0x1.0000000000000p+0005,
+0x1.0000000000000p+0006, +0x1.0000000000000p+0006,
+0x1.0000000000000p+0007, +0x1.0000000000000p+0007,
+0x1.0000000000000p+0008, +0x1.0000000000000p+0008,
+0x1.0000000000000p+0009, +0x1.0000000000000p+0009,
+0x1.0000000000000p+0010, +0x1.0000000000000p+0010,
+0x1.0000000000000p+0011, +0x1.0000000000000p+0011,
+0x1.0000000000000p+0012, +0x1.0000000000000p+0012,
+0x1.0000000000000p+0013, +0x1.0000000000000p+0013,
+0x1.0000000000000p+0014, +0x1.0000000000000p+0014,
+0x1.0000000000000p+0015, +0x1.0000000000000p+0015,
+0x1.0000000000000p+0016, +0x1.0000000000000p+0016,
+0x1.0000000000000p+0017, +0x1.0000000000000p+0017,
+0x1.0000000000000p+0018, +0x1.0000000000000p+0018,
+0x1.0000000000000p+0019, +0x1.0000000000000p+0019,
+0x1.0000000000000p+0020, +0x1.0000000000000p+0020,
+0x1.0000000000000p+0021, +0x1.0000000000000p+0021,
+0x1.0000000000000p+0022, +0x1.0000000000000p+0022,
+0x1.0000000000000p+0023, +0x1.0000000000000p+0023,
+0x1.0000000000000p+0024, +0x1.0000000000000p+0024,
+0x1.0000000000000p+0025, +0x1.0000000000000p+0025,
+0x1.0000000000000p+0026, +0x1.0000000000000p+0026,
+0x1.0000000000000p+0027, +0x1.0000000000000p+0027,
+0x1.0000000000000p+0028, +0x1.0000000000000p+0028,
+0x1.0000000000000p+0029, +0x1.0000000000000p+0029,
+0x1.0000000000000p+0030, +0x1.0000000000000p+0030,
+0x1.0000000000000p+0031, +0x1.0000000000000p+0031,
+0x1.0000000000000p+0032, +0x1.0000000000000p+0032,
+0x1.0000000000000p+0033, +0x1.0000000000000p+0033,
+0x1.0000000000000p+0034, +0x1.0000000000000p+0034,
+0x1.0000000000000p+0035, +0x1.0000000000000p+0035,
+0x1.0000000000000p+0036, +0x1.0000000000000p+0036,
+0x1.0000000000000p+0037, +0x1.0000000000000p+0037,
+0x1.0000000000000p+0038, +0x1.0000000000000p+0038,
+0x1.0000000000000p+0039, +0x1.0000000000000p+0039,
+0x1.0000000000000p+0040, +0x1.0000000000000p+0040,
+0x1.0000000000000p+0041, +0x1.0000000000000p+0041,
+0x1.0000000000000p+0042, +0x1.0000000000000p+0042,
+0x1.0000000000000p+0043, +0x1.0000000000000p+0043,
+0x1.0000000000000p+0044, +0x1.0000000000000p+0044,
+0x1.0000000000000p+0045, +0x1.0000000000000p+0045,
+0x1.0000000000000p+0046, +0x1.0000000000000p+0046,
+0x1.0000000000000p+0047, +0x1.0000000000000p+0047,
+0x1.0000000000000p+0048, +0x1.0000000000000p+0048,
+0x1.0000000000000p+0049, +0x1.0000000000000p+0049,
+0x1.0000000000000p+0050, +0x1.0000000000000p+0050,
+0x1.0000000000000p+0051, +0x1.0000000000000p+0051,
+0x1.0000000000000p+0052, +0x1.0000000000000p+0052,
+0x1.0000000000000p+0053, +0x1.0000000000000p+0053,
+0x1.0000000000000p+0054, +0x1.0000000000000p+0054,
+0x1.0000000000000p+0055, +0x1.0000000000000p+0055,
+0x1.0000000000000p+0056, +0x1.0000000000000p+0056,
+0x1.0000000000000p+0057, +0x1.0000000000000p+0057,
+0x1.0000000000000p+0058, +0x1.0000000000000p+0058,
+0x1.0000000000000p+0059, +0x1.0000000000000p+0059,
+0x1.0000000000000p+0060, +0x1.0000000000000p+0060,
+0x1.0000000000000p+0061, +0x1.0000000000000p+0061,
+0x1.0000000000000p+0062, +0x1.0000000000000p+0062
};
static constexpr std::array<double, degree+1> canonical_polys[] = {
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0
};
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_HAS_SINGLE_BIT_HPP__

View file

@ -0,0 +1,25 @@
/// @file grotto/gadgets/binary/prefix.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PREFIX_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PREFIX_HPP__
#include "gt.hpp"
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PREFIX_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/binary/sg.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_SGN_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_SGN_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "../../gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct sgn
{
template <typename T>
T operator()(T x)
{
if (x == 0) return 0;
else return std::signbit(static_cast<double>(x));
}
};
template <>
struct gadget_hints<sgn>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { 0 };
static constexpr unsigned degree = 0;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { 0, 0 };
static constexpr std::array<double, degree+1> canonical_polys[] = { -1, 0, 1 };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_SGN_HPP__

View file

@ -0,0 +1,16 @@
/// @file grotto/gadgets/decimal.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HPP__
#include "grotto/gadgets/decimal/dec_ceil.hpp"
#include "grotto/gadgets/decimal/dec_floor.hpp"
#include "grotto/gadgets/decimal/dec_width.hpp"
#include "grotto/gadgets/decimal/has_single_digit.hpp"
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/decimal/dec_ceil.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_CEIL_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_CEIL_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_CEIL_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/decimal/dec_floor.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_FLOOR_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_FLOOR_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_FLOOR_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/decimal/dec_width.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_WIDTH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_WIDTH_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_WIDTH_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/decimal/has_single_digit.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HAS_SINGLE_DIGIT_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HAS_SINGLE_DIGIT_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HAS_SINGLE_DIGIT_HPP__

View file

@ -0,0 +1,32 @@
/// @file grotto/gadgets/elementary.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_HPP__
#include "grotto/gadgets/elementary/abs.hpp"
#include "grotto/gadgets/elementary/approx.hpp"
#include "grotto/gadgets/elementary/boxcar.hpp"
#include "grotto/gadgets/elementary/clip.hpp"
#include "grotto/gadgets/elementary/eq.hpp"
#include "grotto/gadgets/elementary/geq.hpp"
#include "grotto/gadgets/elementary/gt.hpp"
// #include "grotto/gadgets/elementary/identity.hpp"
#include "grotto/gadgets/elementary/leq.hpp"
#include "grotto/gadgets/elementary/lt.hpp"
#include "grotto/gadgets/elementary/negative.hpp"
#include "grotto/gadgets/elementary/neq.hpp"
#include "grotto/gadgets/elementary/nonnegative.hpp"
#include "grotto/gadgets/elementary/nonpositive.hpp"
// #include "grotto/gadgets/elementary/pmone.hpp"
#include "grotto/gadgets/elementary/positive.hpp"
#include "grotto/gadgets/elementary/rect.hpp"
#include "grotto/gadgets/elementary/step.hpp"
// #include "grotto/gadgets/elementary/ternary.hpp"
#include "grotto/gadgets/elementary/zero.hpp"
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/elementary/abs.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ABS_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ABS_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct abs
{
template <typename T>
T operator()(T x) { return std::abs(static_cast<double>(x)); }
};
template <>
struct gadget_hints<abs>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { 0 };
static constexpr unsigned degree = 1;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { 0 };
static constexpr std::array<double, degree+1> canonical_polys[] = { { -1, 0 }, { 1, 0 } };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ABS_HPP__

View file

@ -0,0 +1,52 @@
/// @file grotto/gadgets/elementary/approx.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_APPROX_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_APPROX_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double approx_default_target = 0;
static constexpr unsigned approx_default_ULPs = 1;
template <double const & target = approx_default_target,
unsigned const & ULPs = approx_default_ULPs>
struct approx
{
template <typename T>
T operator()(T x) { return std::abs(x - target) <= ULPs * ulp_of(target) ? 1 : 0; }
};
template <double const & target,
unsigned const & ULPs>
struct gadget_hints<approx<target, ULPs>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr unsigned degree = 0;
static constexpr double poles[] = { };
static constexpr bool has_canonical_representation = true;
static constexpr double interesting_points[] = { target - ULPs * ulp_of(target), target + ULPs * ulp_of(target) };
static constexpr double canonical_bounds[] = { target - ULPs * ulp_of(target), target + ULPs * ulp_of(target), target + ULPs * ulp_of(target) };
static constexpr std::array<double, degree+1> canonical_polys[] = { 0, 1, 1, 0 };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_APPROX_HPP__

View file

@ -0,0 +1,56 @@
/// @file grotto/gadgets/elementary/boxcar.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_BOXCAR_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_BOXCAR_HPP__
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double boxcar_default_outside = 0;
static constexpr double boxcar_default_inside = 1;
template <double const & from,
double const & to,
double const & outside = boxcar_default_outside,
double const & inside = boxcar_default_inside>
struct boxcar
{
template <typename T>
T operator()(T x) { return (x < from || x > to) ? outside : inside; }
};
template <double const & from,
double const & to,
double const & outside,
double const & inside>
struct gadget_hints<boxcar<from, to, inside, outside>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr unsigned degree = 0;
static constexpr double poles[] = { };
static constexpr bool has_canonical_representation = true;
static constexpr double interesting_points[] = { from, to };
static constexpr double canonical_bounds[] = { from, to };
static constexpr std::array<double, degree+1> canonical_polys[] = { outside, inside, outside };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_BOXCAR_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/elemwntary/clip.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_CLIP_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_CLIP_HPP__
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
template <double const & lower,
double const & upper>
struct clip
{
static_assert(lower <= upper);
template <typename T>
T operator()(T x) { return std::max(std::min(x, upper), lower); }
};
template <double const & lower,
double const & upper>
struct gadget_hints<clip<lower, upper>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr unsigned degree = 1;
static constexpr double poles[] = { };
static constexpr bool has_canonical_representation = true;
static constexpr double interesting_points[] = { lower, upper };
static constexpr double canonical_bounds[] = { lower, upper };
static constexpr std::array<double, degree+1> canonical_polys[] = { { lower, 0 }, { 0, 1 }, { upper, 0 } };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_CLIP_HPP__

View file

@ -0,0 +1,47 @@
/// @file grotto/gadgets/elementary/eq.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_EQ_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_EQ_HPP__
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
template <double const & target>
struct eq
{
template <typename T>
T operator()(T x) { return x == target; }
};
template <double const & target>
struct gadget_hints<eq<target>>
{
static constexpr double min = std::numeric_limits<double>::lowest();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr unsigned degree = 0;
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { target };
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { target, target };
static constexpr std::array<double, degree+1> canonical_polys[] = { 0, 1, 0 };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_EQ_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/elementary/geq.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GEQ_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GEQ_HPP__
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
template <double const & target>
struct geq
{
template <typename T>
T operator()(T x) { return x >= target; }
};
template <double const & target>
struct gadget_hints<geq<target>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { target };
static constexpr bool has_canonical_representation = true;
static constexpr unsigned degree = 0;
static constexpr double canonical_bounds[] = { target, target };
static constexpr std::array<double, degree+1> canonical_polys[] = { 0, 1, 1 };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GEQ_HPP__

View file

@ -0,0 +1,47 @@
/// @file grotto/gadgets/elementary/gt.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GT_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GT_HPP__
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
template <double const & target>
struct gt
{
template <typename T>
T operator()(T x) { return x > target; }
};
template <double const & target>
struct gadget_hints<gt<target>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr unsigned degree = 0;
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { target };
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { target, target };
static constexpr std::array<double, degree+1> canonical_polys[] = { 0, 0, 1 };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GT_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/elementary/identity.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_IDENTITY_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_IDENTITY_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_IDENTITY_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/elementary/leqw.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LEQ_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LEQ_HPP__
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
template <double const & target>
struct leq
{
template <typename T>
T operator()(T x) { return x <= target; }
};
template <double const & target>
struct gadget_hints<leq<target>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { target };
static constexpr unsigned degree = 0;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { target, target };
static constexpr std::array<double, degree+1> canonical_polys[] = { 1, 1, 0 };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LEQ_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/elementary/lt.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LT_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LT_HPP__
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
template <double const & target>
struct lt
{
template <typename T>
T operator()(T x) { return x < target; }
};
template <double const & target>
struct gadget_hints<lt<target>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { target };
static constexpr unsigned degree = 0;
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { target, target };
static constexpr std::array<double, degree+1> canonical_polys[] = { 1, 0, 0 };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LT_HPP__

View file

@ -0,0 +1,26 @@
/// @file grotto/gadgets/elementary/negative.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEGATIVE_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEGATIVE_HPP__
#include "lt.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double lt_target_zero = 0;
using negative = lt<lt_target_zero>;
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEGATIVE_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/elementary/neq.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEQ_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEQ_HPP__
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
template <double const & target>
struct neq
{
template <typename T>
T operator()(T x) { return x != target; }
};
template <double const & target>
struct gadget_hints<neq<target>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr unsigned degree = 0;
static constexpr double poles[] = { };
static constexpr bool has_canonical_representation = true;
static constexpr double interesting_points[] = { target };
static constexpr double canonical_bounds[] = { target, target };
static constexpr std::array<double, degree+1> canonical_polys[] = { 1, 0, 1 };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEQ_HPP__

View file

@ -0,0 +1,26 @@
/// @file grotto/gadgets/elementary/nonnegative.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONNEGATIVE_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONNEGATIVE_HPP__
#include "geq.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double geq_target_zero = 0;
using nonnegative = geq<geq_target_zero>;
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONNEGATIVE_HPP__

View file

@ -0,0 +1,26 @@
/// @file grotto/gadgets/elementary/nonpositive.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONPOSITIVE_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONPOSITIVE_HPP__
#include "leq.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double leq_target_zero = 0;
using nonpositive = leq<leq_target_zero>;
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONPOSITIVE_HPP__

View file

@ -0,0 +1,26 @@
/// @file grotto/gadgets/elementary/nonzero.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONZERO_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONZERO_HPP__
#include "neq.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double neq_target_zero = 0;
using nonzero = neq<neq_target_zero>;
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONZERO_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/elementary/pmone.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PMONE_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PMONE_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PMONE_HPP__

View file

@ -0,0 +1,26 @@
/// @file grotto/gadgets/elementary/positive.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_POSITIVE_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_POSITIVE_HPP__
#include "gt.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double gt_target_zero = 0;
using positive = gt<gt_target_zero>;
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_POSITIVE_HPP__

View file

@ -0,0 +1,45 @@
/// @file grotto/gadgets/elementary/rect.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_RECT_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_RECT_HPP__
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct rect
{
template <typename T>
T operator()(T x) { return x == 0; }
};
template <>
struct gadget_hints<rect>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr unsigned degree = 0;
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { -0.5, 0.5 };
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { -0.5, -0.5, 0.5, 0.5 };
static constexpr std::array<double, degree+1> canonical_polys[] = { 0, 0.5, 1, 0.50, 0 };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_RECT_HPP__

View file

@ -0,0 +1,54 @@
/// @file grotto/gadgets/elementary/step.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_STEP_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_STEP_HPP__
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double step_default_before = 0;
static constexpr double step_default_after = 1;
template <double const & at,
double const & before = step_default_before,
double const & after = step_default_after>
struct step
{
template <typename T>
T operator()(T x) { return x < at ? before : after; }
};
template <double const & at,
double const & before,
double const & after>
struct gadget_hints<step<at, before, after>>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr unsigned degree = 0;
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { at };
static constexpr bool has_canonical_representation = true;
static constexpr double canonical_bounds[] = { at };
static constexpr std::array<double, degree+1> canonical_polys[] = { before, after };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_STEP_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/elementary/ternary.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_TERNARY_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_TERNARY_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_TERNARY_HPP__

View file

@ -0,0 +1,26 @@
/// @file grotto/gadgets/elementary/zero.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ZERO_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ZERO_HPP__
#include "eq.hpp"
namespace grotto
{
namespace gadgets
{
static constexpr double eq_target_zero = 0;
using zero = eq<eq_target_zero>;
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ZERO_HPP__

View file

@ -0,0 +1,15 @@
/// @file grotto/gadgets/exponential.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_HPP__
#include "grotto/gadgets/exponential/exp.hpp"
#include "grotto/gadgets/exponential/exp2.hpp"
#include "grotto/gadgets/exponential/exp10.hpp"
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/exponential/exp.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief gadgetized form of `std::exp`
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct exp
{
template <typename T>
T operator()(T x) { return std::min(std::exp(static_cast<double>(x)), std::numeric_limits<T>::max()); }
};
template <>
struct gadget_hints<exp>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double * poles = nullptr;
static constexpr double * interesting_points = nullptr;
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double * canonical_bounds = nullptr;
static constexpr std::array<double, degree+1> * canonical_polys = nullptr;
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/exponential/exp10.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief gadgetized form of `std::exp10`
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP10_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP10_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct exp10
{
template <typename T>
T operator()(T x) { return std::min(std::pow(10, static_cast<double>(x)), std::numeric_limits<T>::max()); }
};
template <>
struct gadget_hints<exp10>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double * poles = nullptr;
static constexpr double * interesting_points = nullptr;
static constexpr unsigned degree = 3;
static constexpr bool canonical_representation = false;
static constexpr double * canonical_bounds = nullptr;
static constexpr std::array<double, degree+1> * hint_canonical_polys = nullptr;
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP10_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/exponential/exp2.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief gadgetized form of `std::exp2`
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP2_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP2_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct exp2
{
template <typename T>
T operator()(T x) { return std::min(std::exp2(static_cast<double>(x)), std::numeric_limits<T>::max()); }
};
template <>
struct gadget_hints<exp2>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double * poles = nullptr;
static constexpr double * interesting_points = nullptr;
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double * canonical_bounds = nullptr;
static constexpr std::array<double, degree+1> * canonical_polys = nullptr;
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP2_HPP__

View file

@ -0,0 +1,24 @@
/// @file grotto/gadgets/hyperbolic.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_HPP__
#include "grotto/gadgets/hyperbolic/acosh.hpp"
#include "grotto/gadgets/hyperbolic/acoth.hpp"
#include "grotto/gadgets/hyperbolic/acsch.hpp"
#include "grotto/gadgets/hyperbolic/asech.hpp"
#include "grotto/gadgets/hyperbolic/asinh.hpp"
#include "grotto/gadgets/hyperbolic/atanh.hpp"
#include "grotto/gadgets/hyperbolic/cosh.hpp"
#include "grotto/gadgets/hyperbolic/coth.hpp"
#include "grotto/gadgets/hyperbolic/csch.hpp"
#include "grotto/gadgets/hyperbolic/sech.hpp"
#include "grotto/gadgets/hyperbolic/sinh.hpp"
#include "grotto/gadgets/hyperbolic/tanh.hpp"
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/hyperbolic/acosh.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOSH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOSH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
// Returns the inverse hyperbolic cosine of a number.
// The number must be greater than or equal to 1.
struct acosh
{
template <typename T>
T operator()(T x) {
if (x < 1) return -1; // TODO
return std::acosh(static_cast<double>(x)); }
};
template <>
struct gadget_hints<acosh>
{
static constexpr double min = 1;
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOSH_HPP__

View file

@ -0,0 +1,48 @@
/// @file grotto/gadgets/hyperbolic/acoth.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOTH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOTH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct acoth
{
template <typename T>
T operator()(T x) {
if (std::abs(x) <= 1) return 0; // TODO
return std::atanh(1 / static_cast<double>(x)); }
};
template <>
struct gadget_hints<acoth>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { -1, 1 };
static constexpr double interesting_points[] = { -1, 1 };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOTH_HPP__

View file

@ -0,0 +1,51 @@
/// @file grotto/gadgets/hyperbolic/acsch.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACSCH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACSCH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct acsch
{
template <typename T>
T operator()(T x)
{
if (x == 0) return 0; // TODO
if (x < 0) return std::max(std::asinh(1/static_cast<double>(x)), std::numeric_limits<T>::min());
if (x > 0) return std::min(std::asinh(1/static_cast<double>(x)), std::numeric_limits<T>::max());
}
};
template <>
struct gadget_hints<acsch>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { 0 };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACSCH_HPP__

View file

@ -0,0 +1,51 @@
/// @file grotto/gadgets/hyperbolic/asech.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASECH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASECH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct asech
{
template <typename T>
T operator()(T x)
{
if (x <= 0) return 0; // TODO
if (x > 1) return 0; // TODO
return std::acosh(1/static_cast<double>(x));
}
};
template <>
struct gadget_hints<asech>
{
static constexpr double min = 0;
static constexpr double max = 1;
static constexpr double poles[] = { 0 };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASECH_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/hyperbolic/asinh.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASINH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASINH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct asinh
{
template <typename T>
T operator()(T x) { return std::asinh(static_cast<double>(x)); }
};
template <>
struct gadget_hints<asinh>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASINH_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/hyperbolic/atanh.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ATANH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ATANH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct atanh
{
template <typename T>
T operator()(T x)
{
if (std::abs(x) >= 1) return 0;
return std::atanh(static_cast<double>(x));
}
};
template <>
struct gadget_hints<atanh>
{
static constexpr double min = -1;
static constexpr double max = 1;
static constexpr double poles[] = { -1, 1 };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ATANH_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/hyperbolic/cosh.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COSH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COSH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct cosh
{
template <typename T>
T operator()(T x) { return std::min(std::cosh(static_cast<double>(x)), std::numeric_limits<T>::max()); }
};
template <>
struct gadget_hints<cosh>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COSH_HPP__

View file

@ -0,0 +1,51 @@
/// @file grotto/gadgets/hyperbolic/coth.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COTH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COTH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct coth
{
template <typename T>
T operator()(T x)
{
if (x == 0) return 0;
if (x < 0) return std::max(std::cosh(static_cast<double>(x))/std::sinh(static_cast<double>(x)), std::numeric_limits<T>::min());
if (x > 0) return std::min(std::cosh(static_cast<double>(x))/std::sinh(static_cast<double>(x)), std::numeric_limits<T>::max());
}
};
template <>
struct gadget_hints<coth>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { 0 };
static constexpr double interesting_points[] = { 0 };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COTH_HPP__

View file

@ -0,0 +1,51 @@
/// @file grotto/gadgets/hyperbolic/csch.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_CSCH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_CSCH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct csch
{
template <typename T>
T operator()(T x)
{
if (x == 0) return 0;
if (x < 0) return std::max(1/std::sinh(static_cast<double>(x)), std::numeric_limits<T>::min());
if (x > 0) return std::min(1/std::sinh(static_cast<double>(x)), std::numeric_limits<T>::max());
}
};
template <>
struct gadget_hints<csch>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { 0 };
static constexpr double interesting_points[] = { 0 };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_CSCH_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/hyperbolic/sech.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SECH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SECH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct sech
{
template <typename T>
T operator()(T x) { return 1/std::cosh(static_cast<double>(x)); }
};
template <>
struct gadget_hints<sech>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SECH_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/hyperbolic/sinh.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SINH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SINH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct sinh
{
template <typename T>
T operator()(T x)
{
if (x < 0) return std::max(std::sinh(static_cast<double>(x)), std::numeric_limits<T>::min());
if (x >= 0) return std::min(std::sinh(static_cast<double>(x)), std::numeric_limits<T>::max());
}
};
template <>
struct gadget_hints<sinh>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SINH_HPP__

View file

@ -0,0 +1,46 @@
/// @file grotto/gadgets/hyperbolic/tanh.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_TANH_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_TANH_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct tanh
{
template <typename T>
T operator()(T x) { return std::tanh(static_cast<double>(x)); }
};
template <>
struct gadget_hints<tanh>
{
static constexpr double min = std::numeric_limits<double>::min();
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_TANH_HPP__

View file

@ -0,0 +1,21 @@
/// @file grotto/gadgets/logarithm.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_HPP__
// #include "grotto/gadgets/logarithm/ilog10.hpp"
#include "grotto/gadgets/logarithm/ilogb.hpp"
// #include "grotto/gadgets/logarithm/ilog16.hpp"
// #include "grotto/gadgets/logarithm/ilog256.hpp"
#include "grotto/gadgets/logarithm/lg.hpp"
#include "grotto/gadgets/logarithm/ln.hpp"
#include "grotto/gadgets/logarithm/log10.hpp"
// #include "grotto/gadgets/logarithm/logn.hpp"
// #include "grotto/gadgets/logarithm/logstar.hpp"
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/logarithm/ilog10.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG10_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG10_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct ilog256
{
template <typename T>
T operator()(T x)
{
if (x <= 0) return 0; // TODO
return std::ceil(std::log2(static_cast(x))/8);
}
};
template <>
struct gadget_hints<ilog256>
{
static constexpr double min = std::exp2(-63);
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double hint_poles[] = { };
static constexpr double hint_interesting_points[] = { 0 };
static constexpr unsigned degree = 0;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> hint_canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG10_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/logarithm/ilog16.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG16_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG16_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct ilog16
{
template <typename T>
T operator()(T x)
{
if (x <= 0) return 0; // TODO
return std::ceil(std::log2(static_cast(x))/4);
}
};
template <>
struct gadget_hints<ilog16>
{
static constexpr double min = std::exp2(-63);
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double hint_poles[] = { };
static constexpr double hint_interesting_points[] = { 0 };
static constexpr unsigned degree = 0;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> hint_canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG16_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/logarithm/ilog256.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG256_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG256_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct ilog256
{
template <typename T>
T operator()(T x)
{
if (x <= 0) return 0; // TODO
return std::ceil(std::log2(static_cast(x))/8);
}
};
template <>
struct gadget_hints<ilog256>
{
static constexpr double min = std::exp2(-63);
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double hint_poles[] = { };
static constexpr double hint_interesting_points[] = { 0 };
static constexpr unsigned degree = 0;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> hint_canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG256_HPP__

View file

@ -0,0 +1,307 @@
/// @file grotto/gadgets/logarithm/ilogb.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOGB_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOGB_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct ilogb
{
template <typename T>
T operator()(T x)
{
if (x <= 0) return 0; // TODO
return std::ilogb(static_cast<double>(x));
}
};
template <>
struct gadget_hints<grotto::gadgets::ilogb>
{
static constexpr double min = std::exp2(-63);
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { };
static constexpr double interesting_points[] = { 0 };
static constexpr unsigned degree = 0;
static constexpr bool has_canonical_representation = true;
static constexpr std::array<double, 508> canonical_bounds = {
-0x1.0000000000000p+0063, -0x1.0000000000000p+0063,
-0x1.0000000000000p+0062, -0x1.0000000000000p+0062,
-0x1.0000000000000p+0061, -0x1.0000000000000p+0061,
-0x1.0000000000000p+0060, -0x1.0000000000000p+0060,
-0x1.0000000000000p+0059, -0x1.0000000000000p+0059,
-0x1.0000000000000p+0058, -0x1.0000000000000p+0058,
-0x1.0000000000000p+0057, -0x1.0000000000000p+0057,
-0x1.0000000000000p+0056, -0x1.0000000000000p+0056,
-0x1.0000000000000p+0055, -0x1.0000000000000p+0055,
-0x1.0000000000000p+0054, -0x1.0000000000000p+0054,
-0x1.0000000000000p+0053, -0x1.0000000000000p+0053,
-0x1.0000000000000p+0052, -0x1.0000000000000p+0052,
-0x1.0000000000000p+0051, -0x1.0000000000000p+0051,
-0x1.0000000000000p+0050, -0x1.0000000000000p+0050,
-0x1.0000000000000p+0049, -0x1.0000000000000p+0049,
-0x1.0000000000000p+0048, -0x1.0000000000000p+0048,
-0x1.0000000000000p+0047, -0x1.0000000000000p+0047,
-0x1.0000000000000p+0046, -0x1.0000000000000p+0046,
-0x1.0000000000000p+0045, -0x1.0000000000000p+0045,
-0x1.0000000000000p+0044, -0x1.0000000000000p+0044,
-0x1.0000000000000p+0043, -0x1.0000000000000p+0043,
-0x1.0000000000000p+0042, -0x1.0000000000000p+0042,
-0x1.0000000000000p+0041, -0x1.0000000000000p+0041,
-0x1.0000000000000p+0040, -0x1.0000000000000p+0040,
-0x1.0000000000000p+0039, -0x1.0000000000000p+0039,
-0x1.0000000000000p+0038, -0x1.0000000000000p+0038,
-0x1.0000000000000p+0037, -0x1.0000000000000p+0037,
-0x1.0000000000000p+0036, -0x1.0000000000000p+0036,
-0x1.0000000000000p+0035, -0x1.0000000000000p+0035,
-0x1.0000000000000p+0034, -0x1.0000000000000p+0034,
-0x1.0000000000000p+0033, -0x1.0000000000000p+0033,
-0x1.0000000000000p+0032, -0x1.0000000000000p+0032,
-0x1.0000000000000p+0031, -0x1.0000000000000p+0031,
-0x1.0000000000000p+0030, -0x1.0000000000000p+0030,
-0x1.0000000000000p+0029, -0x1.0000000000000p+0029,
-0x1.0000000000000p+0028, -0x1.0000000000000p+0028,
-0x1.0000000000000p+0027, -0x1.0000000000000p+0027,
-0x1.0000000000000p+0026, -0x1.0000000000000p+0026,
-0x1.0000000000000p+0025, -0x1.0000000000000p+0025,
-0x1.0000000000000p+0024, -0x1.0000000000000p+0024,
-0x1.0000000000000p+0023, -0x1.0000000000000p+0023,
-0x1.0000000000000p+0022, -0x1.0000000000000p+0022,
-0x1.0000000000000p+0021, -0x1.0000000000000p+0021,
-0x1.0000000000000p+0020, -0x1.0000000000000p+0020,
-0x1.0000000000000p+0019, -0x1.0000000000000p+0019,
-0x1.0000000000000p+0018, -0x1.0000000000000p+0018,
-0x1.0000000000000p+0017, -0x1.0000000000000p+0017,
-0x1.0000000000000p+0016, -0x1.0000000000000p+0016,
-0x1.0000000000000p+0015, -0x1.0000000000000p+0015,
-0x1.0000000000000p+0014, -0x1.0000000000000p+0014,
-0x1.0000000000000p+0013, -0x1.0000000000000p+0013,
-0x1.0000000000000p+0012, -0x1.0000000000000p+0012,
-0x1.0000000000000p+0011, -0x1.0000000000000p+0011,
-0x1.0000000000000p+0010, -0x1.0000000000000p+0010,
-0x1.0000000000000p+0009, -0x1.0000000000000p+0009,
-0x1.0000000000000p+0008, -0x1.0000000000000p+0008,
-0x1.0000000000000p+0007, -0x1.0000000000000p+0007,
-0x1.0000000000000p+0006, -0x1.0000000000000p+0006,
-0x1.0000000000000p+0005, -0x1.0000000000000p+0005,
-0x1.0000000000000p+0004, -0x1.0000000000000p+0004,
-0x1.0000000000000p+0003, -0x1.0000000000000p+0003,
-0x1.0000000000000p+0002, -0x1.0000000000000p+0002,
-0x1.0000000000000p+0001, -0x1.0000000000000p+0001,
-0x1.0000000000000p+0000, -0x1.0000000000000p+0000,
-0x1.0000000000000p-0001, -0x1.0000000000000p-0001,
-0x1.0000000000000p-0002, -0x1.0000000000000p-0002,
-0x1.0000000000000p-0003, -0x1.0000000000000p-0003,
-0x1.0000000000000p-0004, -0x1.0000000000000p-0004,
-0x1.0000000000000p-0005, -0x1.0000000000000p-0005,
-0x1.0000000000000p-0006, -0x1.0000000000000p-0006,
-0x1.0000000000000p-0007, -0x1.0000000000000p-0007,
-0x1.0000000000000p-0008, -0x1.0000000000000p-0008,
-0x1.0000000000000p-0009, -0x1.0000000000000p-0009,
-0x1.0000000000000p-0010, -0x1.0000000000000p-0010,
-0x1.0000000000000p-0011, -0x1.0000000000000p-0011,
-0x1.0000000000000p-0012, -0x1.0000000000000p-0012,
-0x1.0000000000000p-0013, -0x1.0000000000000p-0013,
-0x1.0000000000000p-0014, -0x1.0000000000000p-0014,
-0x1.0000000000000p-0015, -0x1.0000000000000p-0015,
-0x1.0000000000000p-0016, -0x1.0000000000000p-0016,
-0x1.0000000000000p-0017, -0x1.0000000000000p-0017,
-0x1.0000000000000p-0018, -0x1.0000000000000p-0018,
-0x1.0000000000000p-0019, -0x1.0000000000000p-0019,
-0x1.0000000000000p-0020, -0x1.0000000000000p-0020,
-0x1.0000000000000p-0021, -0x1.0000000000000p-0021,
-0x1.0000000000000p-0022, -0x1.0000000000000p-0022,
-0x1.0000000000000p-0023, -0x1.0000000000000p-0023,
-0x1.0000000000000p-0024, -0x1.0000000000000p-0024,
-0x1.0000000000000p-0025, -0x1.0000000000000p-0025,
-0x1.0000000000000p-0026, -0x1.0000000000000p-0026,
-0x1.0000000000000p-0027, -0x1.0000000000000p-0027,
-0x1.0000000000000p-0028, -0x1.0000000000000p-0028,
-0x1.0000000000000p-0029, -0x1.0000000000000p-0029,
-0x1.0000000000000p-0030, -0x1.0000000000000p-0030,
-0x1.0000000000000p-0031, -0x1.0000000000000p-0031,
-0x1.0000000000000p-0032, -0x1.0000000000000p-0032,
-0x1.0000000000000p-0033, -0x1.0000000000000p-0033,
-0x1.0000000000000p-0034, -0x1.0000000000000p-0034,
-0x1.0000000000000p-0035, -0x1.0000000000000p-0035,
-0x1.0000000000000p-0036, -0x1.0000000000000p-0036,
-0x1.0000000000000p-0037, -0x1.0000000000000p-0037,
-0x1.0000000000000p-0038, -0x1.0000000000000p-0038,
-0x1.0000000000000p-0039, -0x1.0000000000000p-0039,
-0x1.0000000000000p-0040, -0x1.0000000000000p-0040,
-0x1.0000000000000p-0041, -0x1.0000000000000p-0041,
-0x1.0000000000000p-0042, -0x1.0000000000000p-0042,
-0x1.0000000000000p-0043, -0x1.0000000000000p-0043,
-0x1.0000000000000p-0044, -0x1.0000000000000p-0044,
-0x1.0000000000000p-0045, -0x1.0000000000000p-0045,
-0x1.0000000000000p-0046, -0x1.0000000000000p-0046,
-0x1.0000000000000p-0047, -0x1.0000000000000p-0047,
-0x1.0000000000000p-0048, -0x1.0000000000000p-0048,
-0x1.0000000000000p-0049, -0x1.0000000000000p-0049,
-0x1.0000000000000p-0050, -0x1.0000000000000p-0050,
-0x1.0000000000000p-0051, -0x1.0000000000000p-0051,
-0x1.0000000000000p-0052, -0x1.0000000000000p-0052,
-0x1.0000000000000p-0053, -0x1.0000000000000p-0053,
-0x1.0000000000000p-0054, -0x1.0000000000000p-0054,
-0x1.0000000000000p-0055, -0x1.0000000000000p-0055,
-0x1.0000000000000p-0056, -0x1.0000000000000p-0056,
-0x1.0000000000000p-0057, -0x1.0000000000000p-0057,
-0x1.0000000000000p-0058, -0x1.0000000000000p-0058,
-0x1.0000000000000p-0059, -0x1.0000000000000p-0059,
-0x1.0000000000000p-0060, -0x1.0000000000000p-0060,
-0x1.0000000000000p-0061, -0x1.0000000000000p-0061,
-0x1.0000000000000p-0062, -0x1.0000000000000p-0062,
-0x1.0000000000000p-0063, -0x1.0000000000000p-0063,
+0x0.0000000000000p+0000, +0x0.0000000000000p+0000,
+0x1.0000000000000p-0063, +0x1.0000000000000p-0063,
+0x1.0000000000000p-0062, +0x1.0000000000000p-0062,
+0x1.0000000000000p-0061, +0x1.0000000000000p-0061,
+0x1.0000000000000p-0060, +0x1.0000000000000p-0060,
+0x1.0000000000000p-0059, +0x1.0000000000000p-0059,
+0x1.0000000000000p-0058, +0x1.0000000000000p-0058,
+0x1.0000000000000p-0057, +0x1.0000000000000p-0057,
+0x1.0000000000000p-0056, +0x1.0000000000000p-0056,
+0x1.0000000000000p-0055, +0x1.0000000000000p-0055,
+0x1.0000000000000p-0054, +0x1.0000000000000p-0054,
+0x1.0000000000000p-0053, +0x1.0000000000000p-0053,
+0x1.0000000000000p-0052, +0x1.0000000000000p-0052,
+0x1.0000000000000p-0051, +0x1.0000000000000p-0051,
+0x1.0000000000000p-0050, +0x1.0000000000000p-0050,
+0x1.0000000000000p-0049, +0x1.0000000000000p-0049,
+0x1.0000000000000p-0048, +0x1.0000000000000p-0048,
+0x1.0000000000000p-0047, +0x1.0000000000000p-0047,
+0x1.0000000000000p-0046, +0x1.0000000000000p-0046,
+0x1.0000000000000p-0045, +0x1.0000000000000p-0045,
+0x1.0000000000000p-0044, +0x1.0000000000000p-0044,
+0x1.0000000000000p-0043, +0x1.0000000000000p-0043,
+0x1.0000000000000p-0042, +0x1.0000000000000p-0042,
+0x1.0000000000000p-0041, +0x1.0000000000000p-0041,
+0x1.0000000000000p-0040, +0x1.0000000000000p-0040,
+0x1.0000000000000p-0039, +0x1.0000000000000p-0039,
+0x1.0000000000000p-0038, +0x1.0000000000000p-0038,
+0x1.0000000000000p-0037, +0x1.0000000000000p-0037,
+0x1.0000000000000p-0036, +0x1.0000000000000p-0036,
+0x1.0000000000000p-0035, +0x1.0000000000000p-0035,
+0x1.0000000000000p-0034, +0x1.0000000000000p-0034,
+0x1.0000000000000p-0033, +0x1.0000000000000p-0033,
+0x1.0000000000000p-0032, +0x1.0000000000000p-0032,
+0x1.0000000000000p-0031, +0x1.0000000000000p-0031,
+0x1.0000000000000p-0030, +0x1.0000000000000p-0030,
+0x1.0000000000000p-0029, +0x1.0000000000000p-0029,
+0x1.0000000000000p-0028, +0x1.0000000000000p-0028,
+0x1.0000000000000p-0027, +0x1.0000000000000p-0027,
+0x1.0000000000000p-0026, +0x1.0000000000000p-0026,
+0x1.0000000000000p-0025, +0x1.0000000000000p-0025,
+0x1.0000000000000p-0024, +0x1.0000000000000p-0024,
+0x1.0000000000000p-0023, +0x1.0000000000000p-0023,
+0x1.0000000000000p-0022, +0x1.0000000000000p-0022,
+0x1.0000000000000p-0021, +0x1.0000000000000p-0021,
+0x1.0000000000000p-0020, +0x1.0000000000000p-0020,
+0x1.0000000000000p-0019, +0x1.0000000000000p-0019,
+0x1.0000000000000p-0018, +0x1.0000000000000p-0018,
+0x1.0000000000000p-0017, +0x1.0000000000000p-0017,
+0x1.0000000000000p-0016, +0x1.0000000000000p-0016,
+0x1.0000000000000p-0015, +0x1.0000000000000p-0015,
+0x1.0000000000000p-0014, +0x1.0000000000000p-0014,
+0x1.0000000000000p-0013, +0x1.0000000000000p-0013,
+0x1.0000000000000p-0012, +0x1.0000000000000p-0012,
+0x1.0000000000000p-0011, +0x1.0000000000000p-0011,
+0x1.0000000000000p-0010, +0x1.0000000000000p-0010,
+0x1.0000000000000p-0009, +0x1.0000000000000p-0009,
+0x1.0000000000000p-0008, +0x1.0000000000000p-0008,
+0x1.0000000000000p-0007, +0x1.0000000000000p-0007,
+0x1.0000000000000p-0006, +0x1.0000000000000p-0006,
+0x1.0000000000000p-0005, +0x1.0000000000000p-0005,
+0x1.0000000000000p-0004, +0x1.0000000000000p-0004,
+0x1.0000000000000p-0003, +0x1.0000000000000p-0003,
+0x1.0000000000000p-0002, +0x1.0000000000000p-0002,
+0x1.0000000000000p-0001, +0x1.0000000000000p-0001,
+0x1.0000000000000p+0000, +0x1.0000000000000p+0000,
+0x1.0000000000000p+0001, +0x1.0000000000000p+0001,
+0x1.0000000000000p+0002, +0x1.0000000000000p+0002,
+0x1.0000000000000p+0003, +0x1.0000000000000p+0003,
+0x1.0000000000000p+0004, +0x1.0000000000000p+0004,
+0x1.0000000000000p+0005, +0x1.0000000000000p+0005,
+0x1.0000000000000p+0006, +0x1.0000000000000p+0006,
+0x1.0000000000000p+0007, +0x1.0000000000000p+0007,
+0x1.0000000000000p+0008, +0x1.0000000000000p+0008,
+0x1.0000000000000p+0009, +0x1.0000000000000p+0009,
+0x1.0000000000000p+0010, +0x1.0000000000000p+0010,
+0x1.0000000000000p+0011, +0x1.0000000000000p+0011,
+0x1.0000000000000p+0012, +0x1.0000000000000p+0012,
+0x1.0000000000000p+0013, +0x1.0000000000000p+0013,
+0x1.0000000000000p+0014, +0x1.0000000000000p+0014,
+0x1.0000000000000p+0015, +0x1.0000000000000p+0015,
+0x1.0000000000000p+0016, +0x1.0000000000000p+0016,
+0x1.0000000000000p+0017, +0x1.0000000000000p+0017,
+0x1.0000000000000p+0018, +0x1.0000000000000p+0018,
+0x1.0000000000000p+0019, +0x1.0000000000000p+0019,
+0x1.0000000000000p+0020, +0x1.0000000000000p+0020,
+0x1.0000000000000p+0021, +0x1.0000000000000p+0021,
+0x1.0000000000000p+0022, +0x1.0000000000000p+0022,
+0x1.0000000000000p+0023, +0x1.0000000000000p+0023,
+0x1.0000000000000p+0024, +0x1.0000000000000p+0024,
+0x1.0000000000000p+0025, +0x1.0000000000000p+0025,
+0x1.0000000000000p+0026, +0x1.0000000000000p+0026,
+0x1.0000000000000p+0027, +0x1.0000000000000p+0027,
+0x1.0000000000000p+0028, +0x1.0000000000000p+0028,
+0x1.0000000000000p+0029, +0x1.0000000000000p+0029,
+0x1.0000000000000p+0030, +0x1.0000000000000p+0030,
+0x1.0000000000000p+0031, +0x1.0000000000000p+0031,
+0x1.0000000000000p+0032, +0x1.0000000000000p+0032,
+0x1.0000000000000p+0033, +0x1.0000000000000p+0033,
+0x1.0000000000000p+0034, +0x1.0000000000000p+0034,
+0x1.0000000000000p+0035, +0x1.0000000000000p+0035,
+0x1.0000000000000p+0036, +0x1.0000000000000p+0036,
+0x1.0000000000000p+0037, +0x1.0000000000000p+0037,
+0x1.0000000000000p+0038, +0x1.0000000000000p+0038,
+0x1.0000000000000p+0039, +0x1.0000000000000p+0039,
+0x1.0000000000000p+0040, +0x1.0000000000000p+0040,
+0x1.0000000000000p+0041, +0x1.0000000000000p+0041,
+0x1.0000000000000p+0042, +0x1.0000000000000p+0042,
+0x1.0000000000000p+0043, +0x1.0000000000000p+0043,
+0x1.0000000000000p+0044, +0x1.0000000000000p+0044,
+0x1.0000000000000p+0045, +0x1.0000000000000p+0045,
+0x1.0000000000000p+0046, +0x1.0000000000000p+0046,
+0x1.0000000000000p+0047, +0x1.0000000000000p+0047,
+0x1.0000000000000p+0048, +0x1.0000000000000p+0048,
+0x1.0000000000000p+0049, +0x1.0000000000000p+0049,
+0x1.0000000000000p+0050, +0x1.0000000000000p+0050,
+0x1.0000000000000p+0051, +0x1.0000000000000p+0051,
+0x1.0000000000000p+0052, +0x1.0000000000000p+0052,
+0x1.0000000000000p+0053, +0x1.0000000000000p+0053,
+0x1.0000000000000p+0054, +0x1.0000000000000p+0054,
+0x1.0000000000000p+0055, +0x1.0000000000000p+0055,
+0x1.0000000000000p+0056, +0x1.0000000000000p+0056,
+0x1.0000000000000p+0057, +0x1.0000000000000p+0057,
+0x1.0000000000000p+0058, +0x1.0000000000000p+0058,
+0x1.0000000000000p+0059, +0x1.0000000000000p+0059,
+0x1.0000000000000p+0060, +0x1.0000000000000p+0060,
+0x1.0000000000000p+0061, +0x1.0000000000000p+0061,
+0x1.0000000000000p+0062, +0x1.0000000000000p+0062
};
static constexpr std::array<std::array<double, degree+1>, 510> canonical_polys = {
63, 63, 62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 57, 57, 56, 56, 55, 55, 54, 54, 53, 53, 52, 52, 51, 51, 50, 50, 49, 49, 48, 48, 47, 47, 46, 46, 45, 45, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 39, 39, 38, 38, 37, 37, 36, 36, 35, 35, 34, 34, 33, 33, 32, 32, 31, 31, 30, 30, 29, 29, 28, 28, 27, 27, 26, 26, 25, 25, 24, 24, 23, 23, 22, 22, 21, 21, 20, 20, 19, 19, 18, 18, 17, 17, 16, 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, -8, -8, -9, -9, -10, -10, -11, -11, -12, -12, -13, -13, -14, -14, -15, -15, -16, -16, -17, -17, -18, -18, -19, -19, -20, -20, -21, -21, -22, -22, -23, -23, -24, -24, -25, -25, -26, -26, -27, -27, -28, -28, -29, -29, -30, -30, -31, -31, -32, -32, -33, -33, -34, -34, -35, -35, -36, -36, -37, -37, -38, -38, -39, -39, -40, -40, -41, -41, -42, -42, -43, -43, -44, -44, -45, -45, -46, -46, -47, -47, -48, -48, -49, -49, -50, -50, -51, -51, -52, -52, -53, -53, -54, -54, -55, -55, -56, -56, -57, -57, -58, -58, -59, -59, -60, -60, -61, -61, -62, -62, -63, -63, -64, -64, -63, -63, -62, -62, -61, -61, -60, -60, -59, -59, -58, -58, -57, -57, -56, -56, -55, -55, -54, -54, -53, -53, -52, -52, -51, -51, -50, -50, -49, -49, -48, -48, -47, -47, -46, -46, -45, -45, -44, -44, -43, -43, -42, -42, -41, -41, -40, -40, -39, -39, -38, -38, -37, -37, -36, -36, -35, -35, -34, -34, -33, -33, -32, -32, -31, -31, -30, -30, -29, -29, -28, -28, -27, -27, -26, -26, -25, -25, -24, -24, -23, -23, -22, -22, -21, -21, -20, -20, -19, -19, -18, -18, -17, -17, -16, -16, -15, -15, -14, -14, -13, -13, -12, -12, -11, -11, -10, -10, -9, -9, -8, -8, -7, -7, -6, -6, -5, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46, 46, 47, 47, 48, 48, 49, 49, 50, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 63, 63
};
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOGB_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/logarithm/lg.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LG_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LG_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct lg
{
template <typename T>
T operator()(T x)
{
if (x <= 0) return 0; // TODO
return std::log2(static_cast<double>(x));
}
};
template <>
struct gadget_hints<lg>
{
static constexpr double min = std::exp2(-63);
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { 0 };
static constexpr double interesting_points[] = { 0 };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LG_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/logarithm/ln.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LN_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LN_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct ln
{
template <typename T>
T operator()(T x)
{
if (x <= 0) return 0; // TODO
return std::log(static_cast<double>(x));
}
};
template <>
struct gadget_hints<ln>
{
static constexpr double min = std::exp2(-63);
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double poles[] = { 0 };
static constexpr double interesting_points[] = { 0 };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LN_HPP__

View file

@ -0,0 +1,50 @@
/// @file grotto/gadgets/logarithm/log10.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LOG10_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LOG10_HPP__
#include <cmath>
#include <array>
#include <limits>
#include "grotto/gadget_hints.hpp"
namespace grotto
{
namespace gadgets
{
struct log10
{
template <typename T>
T operator()(T x)
{
if (x <= 0) return 0; // TODO
return std::log10(static_cast<double>(x));
}
};
template <>
struct gadget_hints<log10>
{
static constexpr double min = std::exp2(-63);
static constexpr double max = std::numeric_limits<double>::max();
static constexpr double hint_poles[] = { 0 };
static constexpr double hint_interesting_points[] = { 0 };
static constexpr unsigned degree = 3;
static constexpr bool has_canonical_representation = false;
static constexpr double canonical_bounds[] = { };
static constexpr std::array<double, degree+1> hint_canonical_polys[] = { };
};
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LOG10_HPP__

View file

@ -0,0 +1,23 @@
/// @file grotto/gadgets/logarithm/logn.hpp
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @brief
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
/// see [LICENSE.md](@ref GPLv2) for details.
#ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHMS_LOGN_HPP__
#define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHMS_LOGN_HPP__
namespace grotto
{
namespace gadgets
{
} // namespace gadgets
} // namespace grotto
#endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHMS_LOGN_HPP__

Some files were not shown because too many files have changed in this diff Show more