├── doc ├── libdpf.bib ├── assets │ ├── libdpf.psd │ ├── libdpf-logo.png │ ├── libdpf-tagline.png │ └── libdpf-wordmark.png ├── pages │ ├── basics.md │ ├── iterables.md │ ├── output_types.md │ └── introduction.md ├── namespaces.dox ├── footer.html └── directories.dox ├── test ├── .gitignore ├── tests │ ├── all_test.cpp │ ├── setbit_index_iterable_test.cpp │ ├── advice_bit_iterable_test.cpp │ └── helpers │ │ ├── custom_output_type_large_xor.hpp │ │ └── custom_output_type_small.hpp └── README.md ├── BUGS.md ├── CHANGES.md ├── .deepsource.toml ├── examples ├── input_types │ ├── custom.cpp │ ├── xor_wrapper.cpp │ ├── extended_types.cpp │ ├── integral_types.cpp │ ├── modint.cpp │ ├── keyword.cpp │ ├── keyword_int_map.cpp │ └── bitstring.cpp ├── output_types │ ├── bit.cpp │ ├── custom.cpp │ ├── bitstring.cpp │ ├── xor_wrapper.cpp │ ├── extended_types.cpp │ ├── integral_types.cpp │ └── wildcard.cpp ├── iterables │ ├── zip_iterable.cpp │ ├── parallel_bit_iterable.cpp │ ├── setbit_index_iterable.cpp │ ├── subinterval_iterable.cpp │ ├── subsequence_iterable.cpp │ └── advice_bit_iterable.cpp └── evaluation │ ├── output_buffers.cpp │ ├── eval_point.cpp │ ├── eval_full.cpp │ └── eval_interval.cpp ├── TODO.md ├── CPPLINT.cfg ├── include ├── dpf │ ├── literals.hpp │ ├── sequence_utils.hpp │ ├── prg_dummy.hpp │ └── prg.hpp ├── grotto │ ├── gadgets │ │ ├── misc │ │ │ ├── sinc.hpp │ │ │ ├── gamma.hpp │ │ │ ├── expint.hpp │ │ │ ├── lgamma.hpp │ │ │ ├── reimann_zeta.hpp │ │ │ ├── i0.hpp │ │ │ ├── erf.hpp │ │ │ ├── erfc.hpp │ │ │ └── entropy.hpp │ │ ├── binary │ │ │ ├── bit.hpp │ │ │ ├── clrsb.hpp │ │ │ ├── prefix.hpp │ │ │ ├── bit_ceil.hpp │ │ │ ├── bit_floor.hpp │ │ │ ├── bit_width.hpp │ │ │ ├── countl_one.hpp │ │ │ ├── sgn.hpp │ │ │ └── countl_zero.hpp │ │ ├── exponential.hpp │ │ ├── quantile │ │ │ ├── gamma.hpp │ │ │ ├── cauchy.hpp │ │ │ ├── pareto.hpp │ │ │ ├── laplace.hpp │ │ │ ├── poisson.hpp │ │ │ ├── gaussian.hpp │ │ │ ├── logistic.hpp │ │ │ ├── powerlaw.hpp │ │ │ ├── geometric.hpp │ │ │ ├── lognormal.hpp │ │ │ ├── chisquared.hpp │ │ │ ├── standard_t.hpp │ │ │ └── exponential.hpp │ │ ├── logarithm │ │ │ ├── logn.hpp │ │ │ ├── logstar.hpp │ │ │ ├── lg.hpp │ │ │ ├── ln.hpp │ │ │ ├── log10.hpp │ │ │ ├── ilog16.hpp │ │ │ ├── ilog10.hpp │ │ │ └── ilog256.hpp │ │ ├── decimal │ │ │ ├── dec_ceil.hpp │ │ │ ├── dec_floor.hpp │ │ │ ├── dec_width.hpp │ │ │ └── has_single_digit.hpp │ │ ├── elementary │ │ │ ├── pmone.hpp │ │ │ ├── ternary.hpp │ │ │ ├── identity.hpp │ │ │ ├── zero.hpp │ │ │ ├── nonzero.hpp │ │ │ ├── negative.hpp │ │ │ ├── positive.hpp │ │ │ ├── nonnegative.hpp │ │ │ ├── nonpositive.hpp │ │ │ ├── rect.hpp │ │ │ ├── abs.hpp │ │ │ ├── lt.hpp │ │ │ ├── geq.hpp │ │ │ ├── gt.hpp │ │ │ ├── neq.hpp │ │ │ ├── eq.hpp │ │ │ ├── leq.hpp │ │ │ └── clip.hpp │ │ ├── decimal.hpp │ │ ├── powers.hpp │ │ ├── activations │ │ │ ├── relu.hpp │ │ │ ├── silu.hpp │ │ │ ├── sigmoid.hpp │ │ │ ├── softsign.hpp │ │ │ ├── tanhexp.hpp │ │ │ ├── tanhshrink.hpp │ │ │ ├── mish.hpp │ │ │ ├── serf.hpp │ │ │ ├── logsigmoid.hpp │ │ │ ├── lecun_tanh.hpp │ │ │ ├── gelu.hpp │ │ │ ├── squared_relu.hpp │ │ │ ├── hardtanh.hpp │ │ │ ├── one_minus_sigmoid.hpp │ │ │ ├── hardswish.hpp │ │ │ ├── elish.hpp │ │ │ ├── hardsigmoid.hpp │ │ │ ├── relu6.hpp │ │ │ ├── hardelish.hpp │ │ │ ├── elu.hpp │ │ │ ├── softminus.hpp │ │ │ ├── celu.hpp │ │ │ ├── softplus.hpp │ │ │ └── hardshrink.hpp │ │ ├── binary.hpp │ │ ├── misc.hpp │ │ ├── logarithm.hpp │ │ ├── hyperbolic.hpp │ │ ├── quantile.hpp │ │ ├── trigonometric.hpp │ │ ├── hyperbolic │ │ │ ├── tanh.hpp │ │ │ ├── sech.hpp │ │ │ ├── asinh.hpp │ │ │ ├── atanh.hpp │ │ │ ├── cosh.hpp │ │ │ ├── asech.hpp │ │ │ ├── acoth.hpp │ │ │ ├── acosh.hpp │ │ │ ├── sinh.hpp │ │ │ ├── csch.hpp │ │ │ ├── acsch.hpp │ │ │ └── coth.hpp │ │ ├── trigonometric │ │ │ ├── atan.hpp │ │ │ ├── cos.hpp │ │ │ ├── sin.hpp │ │ │ ├── deg2rad.hpp │ │ │ ├── acot.hpp │ │ │ ├── rad2deg.hpp │ │ │ ├── acos.hpp │ │ │ ├── asin.hpp │ │ │ ├── tan.hpp │ │ │ ├── sec.hpp │ │ │ ├── csc.hpp │ │ │ ├── acsc.hpp │ │ │ ├── asec.hpp │ │ │ └── cot.hpp │ │ ├── powers │ │ │ ├── cbrt.hpp │ │ │ ├── sqrt.hpp │ │ │ ├── qtrt.hpp │ │ │ ├── icbrt.hpp │ │ │ ├── isqrt.hpp │ │ │ ├── iqtrt.hpp │ │ │ └── reciprocal.hpp │ │ ├── elementary.hpp │ │ └── exponential │ │ │ ├── exp.hpp │ │ │ ├── exp2.hpp │ │ │ └── exp10.hpp │ └── gadgets.hpp └── grotto.hpp ├── AUTHORS.md ├── .gitignore ├── .gitmodules ├── Makefile └── thirdparty └── bsd ├── nlist.h └── sys └── poll.h /doc/libdpf.bib: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /BUGS.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "cxx" -------------------------------------------------------------------------------- /doc/assets/libdpf.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DigitalLibertiesLab/libdpf/HEAD/doc/assets/libdpf.psd -------------------------------------------------------------------------------- /doc/assets/libdpf-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DigitalLibertiesLab/libdpf/HEAD/doc/assets/libdpf-logo.png -------------------------------------------------------------------------------- /doc/assets/libdpf-tagline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DigitalLibertiesLab/libdpf/HEAD/doc/assets/libdpf-tagline.png -------------------------------------------------------------------------------- /doc/assets/libdpf-wordmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DigitalLibertiesLab/libdpf/HEAD/doc/assets/libdpf-wordmark.png -------------------------------------------------------------------------------- /examples/input_types/custom.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/output_types/bit.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/output_types/custom.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/input_types/xor_wrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/iterables/zip_iterable.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/output_types/bitstring.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/output_types/xor_wrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/evaluation/output_buffers.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/input_types/extended_types.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/output_types/extended_types.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /doc/pages/basics.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Point functions {#point_functions} 4 | 5 | # DPF Trees {#dpf_trees} 6 | -------------------------------------------------------------------------------- /examples/iterables/parallel_bit_iterable.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/iterables/setbit_index_iterable.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/iterables/subinterval_iterable.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /examples/iterables/subsequence_iterable.cpp: -------------------------------------------------------------------------------- 1 | #include "dpf.hpp" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | - foo 4 | 5 | - bar -------------------------------------------------------------------------------- /doc/pages/iterables.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # dpf::setbit_index_iterable 4 | 5 | # dpf::subsequence_iterable 6 | 7 | # dpf::subinterval_iterable 8 | 9 | # dpf::zip_iterable 10 | 11 | # dpf::parallel_bit_iterable 12 | 13 | # dpf::advice_bit_iterable -------------------------------------------------------------------------------- /examples/output_types/integral_types.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "dpf.hpp" 4 | 5 | int main(int argc, char * argv[]) 6 | { 7 | using value_type = int; 8 | using output = bool; 9 | 10 | auto [dpf0, dpf1] = dpf::make_dpf(12); 11 | 12 | std::cout << (res0 ^ res1) << "\n"; 13 | std::cout << values[2] << "\n"; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # Don't search for additional CPPLINT.cfg in parent directories. 2 | set noparent 3 | 4 | # include project root in path construction (for header guards) 5 | root=.. 6 | 7 | # { should almost always be on a new line 8 | filter=-whitespace/braces 9 | 10 | # Scope specifiers are indent +2 spaces 11 | filter=-whitespace/indent 12 | 13 | # An else should appear on the same line as the preceding } 14 | filter=-whitespace/newline -------------------------------------------------------------------------------- /include/dpf/literals.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LIBDPF_INCLUDE_DPF_LITERALS_HPP__ 2 | #define LIBDPF_INCLUDE_DPF_LITERALS_HPP__ 3 | 4 | namespace dpf 5 | { 6 | 7 | namespace literals 8 | { 9 | 10 | namespace modints{} using namespace dpf::literals::modints; 11 | namespace xints{} using namespace dpf::literals::xints; 12 | namespace bitstrings{} using namespace dpf::literals::bitstrings; 13 | 14 | } // namespace literals 15 | 16 | } // namespace dpf 17 | 18 | #endif // LIBDPF_INCLUDE_DPF_LITERALS_HPP__ 19 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | - Ryan Henry 4 | 5 |    6 | 7 | - Christopher Jiang 8 | 9 |    10 | 11 | - Kyle Storrier 12 | 13 |    14 | 15 | - Adithya Vadapalli 16 | 17 |    -------------------------------------------------------------------------------- /include/dpf/sequence_utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LIBDPF_INCLUDE_DPF_SEQUENCE_UTILS_HPP__ 2 | #define LIBDPF_INCLUDE_DPF_SEQUENCE_UTILS_HPP__ 3 | 4 | namespace dpf 5 | { 6 | 7 | struct return_type_tag_{}; 8 | 9 | struct return_entire_node_tag_ final : public return_type_tag_ {}; 10 | // static constexpr auto return_entire_node_tag = return_entire_node_tag_{}; 11 | 12 | struct return_output_only_tag_ final : public return_type_tag_ {}; 13 | // static constexpr auto return_output_only_tag = return_output_only_tag_{}; 14 | 15 | } // namespace dpf 16 | 17 | #endif // LIBDPF_INCLUDE_DPF_SEQUENCE_UTILS_HPP__ 18 | -------------------------------------------------------------------------------- /doc/pages/output_types.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Integer scalar types 4 | 5 | # Extended-precision integer scalar types 6 | 7 | # dpf::bit 8 | 9 | # dpf::bitstring 10 | 11 | # dpf::wildcard 12 | A `dpf::wildcard` is a struct template with a single parameter 13 | `T`, which must be a trivially copyable type (as indicated by 14 | `std::is_trivially_copyable`). It is used as a placeholder 15 | for an instance of type `T`, which can be assigned later. Its 16 | intended to wrap an output types of a DPF. 17 | 18 | 19 | # dpf::xor_wrapper 20 | 21 | # Custom output type requirements {#custom_output_types} -------------------------------------------------------------------------------- /include/grotto/gadgets/misc/sinc.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/misc/sinc.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_SINC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_SINC_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_SINC_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/binary/bit.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/binary/bt.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/misc/gamma.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/misc/gamma.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_GAMMA_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_GAMMA_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_GAMMA_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/misc/expint.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/misc/expint.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_EXPINT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_EXPINT_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_EXPINT_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/misc/lgamma.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/misc/lgamma.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_LGAMMA_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_LGAMMA_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_LGAMMA_HPP__ 24 | -------------------------------------------------------------------------------- /examples/output_types/wildcard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "dpf.hpp" 4 | 5 | int main(int argc, char * argv[]) 6 | { 7 | using input_type = uint8_t; 8 | using output_type = dpf::wildcard_value; 9 | using dpf_type = dpf::utils::dpf_type_t; 10 | input_type x = 12; 11 | output_type y; 12 | auto [dpf0, dpf1] = dpf::make_dpf(x, y); 13 | 14 | 15 | std::array points{12, 34, 56, 78, 90}; 16 | auto recipe0 = dpf::make_sequence_recipe(dpf0, std::begin(points), std::end(points)); 17 | auto recipe1 = dpf::make_sequence_recipe(dpf1, std::begin(points), std::end(points)); 18 | } -------------------------------------------------------------------------------- /include/grotto/gadgets/exponential.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/exponential.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_HPP__ 10 | 11 | #include "grotto/gadgets/exponential/exp.hpp" 12 | #include "grotto/gadgets/exponential/exp2.hpp" 13 | #include "grotto/gadgets/exponential/exp10.hpp" 14 | 15 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_HPP__ 16 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/gamma.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/gamma.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_GAMMA_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_GAMMA_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_GAMMA_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/logarithm/logn.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/logarithm/logn.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHMS_LOGN_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHMS_LOGN_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHMS_LOGN_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/cauchy.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/cauchy.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_CAUCHY_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_CAUCHY_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_CAUCHY_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/pareto.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/pareto.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_PARETO_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_PARETO_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_PARETO_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/decimal/dec_ceil.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/decimal/dec_ceil.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_CEIL_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_CEIL_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_CEIL_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/pmone.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/pmone.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PMONE_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PMONE_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PMONE_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/laplace.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/laplace.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_LAPLACE_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_LAPLACE_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_LAPLACE_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/poisson.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/poisson.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_POISSON_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_POISSON_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_POISSON_HPP__ 24 | -------------------------------------------------------------------------------- /test/tests/all_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | system("./bin/dpf_key_test"); 6 | system("./bin/wildcard_test"); 7 | 8 | system("./bin/eval_point_test"); 9 | system("./bin/eval_interval_test"); 10 | system("./bin/eval_full_test"); 11 | system("./bin/eval_sequence_test"); 12 | 13 | system("./bin/eval_point_multi_test"); 14 | system("./bin/eval_interval_multi_test"); 15 | system("./bin/eval_full_multi_test"); 16 | system("./bin/eval_sequence_multi_test"); 17 | 18 | system("./bin/advice_bit_iterable_test"); 19 | system("./bin/parallel_bit_iterable_test"); 20 | system("./bin/setbit_index_iterable_test"); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/decimal/dec_floor.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/decimal/dec_floor.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_FLOOR_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_FLOOR_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_FLOOR_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/decimal/dec_width.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/decimal/dec_width.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_WIDTH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_WIDTH_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_DEC_WIDTH_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/misc/reimann_zeta.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/misc/reimann_zeta.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_REIMANN_ZETA_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_REIMANN_ZETA_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_REIMANN_ZETA_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/gaussian.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/gaussian.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_GAUSSIAN_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_GAUSSIAN_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_GAUSSIAN_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/logistic.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/logistic.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_LOGISTIC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_LOGISTIC_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_LOGISTIC_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/powerlaw.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/powerlaw.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_POWERLAW_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_POWERLAW_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_POWERLAW_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/ternary.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/ternary.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_TERNARY_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_TERNARY_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_TERNARY_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/logarithm/logstar.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/logarithm/logstar.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHMS_LOGSTAR_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHMS_LOGSTAR_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHMS_LOGSTAR_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/geometric.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/geometric.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_GEOMETRIC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_GEOMETRIC_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_GEOMETRIC_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/lognormal.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/lognormal.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_LOGNORMAL_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_LOGNORMAL_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_LOGNORMAL_HPP__ 24 | -------------------------------------------------------------------------------- /doc/namespaces.dox: -------------------------------------------------------------------------------- 1 | /// @namespace dpf 2 | /// @brief the `::dpf` namespace 3 | /// @details all components of `libdpf++` live in this namespace (or one of 4 | /// the namespaces nested within it) 5 | 6 | /// @namespace dpf::utils 7 | /// @brief the `dpf::utils` namespace 8 | /// @details this is where all the utils go 9 | 10 | /// @namespace dpf::details 11 | /// @brief the `dpf::details` namespace` 12 | /// @details this is where details go 13 | 14 | /// @namespace dpf::internal 15 | /// @brief the `dpf::internal` namespace 16 | /// @details this is where internal stuff goes 17 | 18 | /// @namespace dpf::wildcards 19 | /// @brief the `dpf::wildcards` namespace 20 | /// @details this is where pre-define wildcards go -------------------------------------------------------------------------------- /include/grotto/gadgets/binary/clrsb.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/binary/clrsb.hpp 2 | /// @author Ryan Henry 3 | /// @brief gadgetized form of `__builtin_clzll` 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_CLRSB_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_CLRSB_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_CLRSB_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/identity.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/identity.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_IDENTITY_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_IDENTITY_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_IDENTITY_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/misc/i0.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/misc/i0.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | // Modified Bessel function of the first kind, order 0 9 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_I0_HPP__ 10 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_I0_HPP__ 11 | 12 | namespace grotto 13 | { 14 | 15 | namespace gadgets 16 | { 17 | 18 | 19 | 20 | } // namespace gadgets 21 | 22 | } // namespace grotto 23 | 24 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_I0_HPP__ 25 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/chisquared.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/chisquared.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_CHISQUARED_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_CHISQUARED_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_CHISQUARED_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/standard_t.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/standard_t.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_STANDARD_T_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_STANDARD_T_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_STANDARD_T_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile/exponential.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quatile/exponential.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_EXPONENTIAL_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_EXPONENTIAL_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_EXPONENTIAL_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/binary/prefix.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/binary/prefix.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PREFIX_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PREFIX_HPP__ 10 | 11 | #include "gt.hpp" 12 | 13 | namespace grotto 14 | { 15 | 16 | namespace gadgets 17 | { 18 | 19 | 20 | 21 | } // namespace gadgets 22 | 23 | } // namespace grotto 24 | 25 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_PREFIX_HPP__ 26 | -------------------------------------------------------------------------------- /include/grotto/gadgets/decimal.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/decimal.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HPP__ 10 | 11 | #include "grotto/gadgets/decimal/dec_ceil.hpp" 12 | #include "grotto/gadgets/decimal/dec_floor.hpp" 13 | #include "grotto/gadgets/decimal/dec_width.hpp" 14 | #include "grotto/gadgets/decimal/has_single_digit.hpp" 15 | 16 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HPP__ 17 | -------------------------------------------------------------------------------- /include/grotto/gadgets/binary/bit_ceil.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/binary/bit_ceil.hpp 2 | /// @author Ryan Henry 3 | /// @brief gadgetized form of `std::bit_ceil` 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_CEIL_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_CEIL_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_CEIL_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/binary/bit_floor.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/binary/bit_floor.hpp 2 | /// @author Ryan Henry 3 | /// @brief gadgetized form of `std::bit_floor` 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_FLOOR_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_FLOOR_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_FLOOR_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/binary/bit_width.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/binary/bit_width.hpp 2 | /// @author Ryan Henry 3 | /// @brief gadgetized form of `std::bit_width` 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_WIDTH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_WIDTH_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_BIT_WIDTH_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/binary/countl_one.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/binary/countl_one.hpp 2 | /// @author Ryan Henry 3 | /// @brief gadgetized form of `std::countl_one` 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ONE_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ONE_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ONE_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto/gadgets/decimal/has_single_digit.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/decimal/has_single_digit.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HAS_SINGLE_DIGIT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HAS_SINGLE_DIGIT_HPP__ 10 | 11 | namespace grotto 12 | { 13 | 14 | namespace gadgets 15 | { 16 | 17 | 18 | 19 | } // namespace gadgets 20 | 21 | } // namespace grotto 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_DECIMAL_HAS_SINGLE_DIGIT_HPP__ 24 | -------------------------------------------------------------------------------- /include/grotto.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto.hpp 2 | /// @author Ryan Henry 3 | /// @brief includes all headers needed for basic Grotto functionality 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_HPP__ 10 | 11 | #include "grotto/fixedpoint.hpp" 12 | 13 | #include "grotto/gadget_hints.hpp" 14 | 15 | #include "grotto/gadgets.hpp" 16 | 17 | #include "grotto/hexfloat.hpp" 18 | 19 | #include "grotto/piecewise.hpp" 20 | 21 | #include "grotto/prefix_parity.hpp" 22 | 23 | #endif // LIBDPF_INCLUDE_GROTTO_HPP__ 24 | -------------------------------------------------------------------------------- /examples/evaluation/eval_point.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "dpf.hpp" 4 | 5 | int main(int arc, char * argv[]) 6 | { 7 | uint16_t x = 42; 8 | auto [dpf0, dpf1] = dpf::make_dpf(x); 9 | 10 | auto res = dpf::eval_point(dpf0, x); 11 | 12 | std::cout << *dpf::eval_point(dpf0, 41) << " ^ " << *dpf::eval_point(dpf1, 41) << " = " << (*dpf::eval_point(dpf0, 41) ^ *dpf::eval_point(dpf1, 41)) << "\n"; // = 0 13 | std::cout << *dpf::eval_point(dpf0, x) << " ^ " << *dpf::eval_point(dpf1, x) << " = " << (*dpf::eval_point(dpf0, x) ^ *dpf::eval_point(dpf1, x)) << "\n"; // = 1 14 | std::cout << *dpf::eval_point(dpf0, 43) << " ^ " << *dpf::eval_point(dpf1, 43) << " = " << (*dpf::eval_point(dpf0, 43) ^ *dpf::eval_point(dpf1, 43)) << "\n"; // = 0 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/zero.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/zero.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ZERO_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ZERO_HPP__ 10 | 11 | #include "eq.hpp" 12 | 13 | namespace grotto 14 | { 15 | 16 | namespace gadgets 17 | { 18 | 19 | static constexpr double eq_target_zero = 0; 20 | using zero = eq; 21 | 22 | } // namespace gadgets 23 | 24 | } // namespace grotto 25 | 26 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ZERO_HPP__ 27 | -------------------------------------------------------------------------------- /examples/input_types/integral_types.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "dpf.hpp" 4 | 5 | int main(int argc, char * argv[]) 6 | { 7 | using value_type = int; 8 | 9 | std::vector values = {12, 34, 56, 78}; 10 | 11 | auto [dpf0, dpf1] = dpf::make_dpf(value_type{56}); 12 | 13 | int i=0; 14 | value_type res0{}; 15 | auto [buf0, iter0] = dpf::eval_sequence(dpf0, std::begin(values), std::end(values)); 16 | for (auto b : iter0) { if (b) res0 ^= values[i]; i++; } 17 | 18 | i=0; 19 | value_type res1{}; 20 | auto [buf1, iter1] = dpf::eval_sequence(dpf1, std::begin(values), std::end(values)); 21 | for (auto b : iter1) { if (b) res1 ^= values[i]; i++; } 22 | 23 | std::cout << (res0 ^ res1) << "\n"; 24 | std::cout << values[2] << "\n"; 25 | } -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/nonzero.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/nonzero.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONZERO_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONZERO_HPP__ 10 | 11 | #include "neq.hpp" 12 | 13 | namespace grotto 14 | { 15 | 16 | namespace gadgets 17 | { 18 | 19 | static constexpr double neq_target_zero = 0; 20 | using nonzero = neq; 21 | 22 | } // namespace gadgets 23 | 24 | } // namespace grotto 25 | 26 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONZERO_HPP__ 27 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/negative.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/negative.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEGATIVE_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEGATIVE_HPP__ 10 | 11 | #include "lt.hpp" 12 | 13 | namespace grotto 14 | { 15 | 16 | namespace gadgets 17 | { 18 | 19 | static constexpr double lt_target_zero = 0; 20 | using negative = lt; 21 | 22 | } // namespace gadgets 23 | 24 | } // namespace grotto 25 | 26 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEGATIVE_HPP__ 27 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/positive.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/positive.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_POSITIVE_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_POSITIVE_HPP__ 10 | 11 | #include "gt.hpp" 12 | 13 | namespace grotto 14 | { 15 | 16 | namespace gadgets 17 | { 18 | 19 | static constexpr double gt_target_zero = 0; 20 | using positive = gt; 21 | 22 | } // namespace gadgets 23 | 24 | } // namespace grotto 25 | 26 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_POSITIVE_HPP__ 27 | -------------------------------------------------------------------------------- /include/grotto/gadgets/powers.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/powers.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_HPP__ 10 | 11 | #include "grotto/gadgets/powers/cbrt.hpp" 12 | #include "grotto/gadgets/powers/icbrt.hpp" 13 | #include "grotto/gadgets/powers/iqtrt.hpp" 14 | #include "grotto/gadgets/powers/isqrt.hpp" 15 | #include "grotto/gadgets/powers/qtrt.hpp" 16 | #include "grotto/gadgets/powers/reciprocal.hpp" 17 | #include "grotto/gadgets/powers/sqrt.hpp" 18 | 19 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_HPP__ 20 | -------------------------------------------------------------------------------- /doc/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/nonnegative.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/nonnegative.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONNEGATIVE_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONNEGATIVE_HPP__ 10 | 11 | #include "geq.hpp" 12 | 13 | namespace grotto 14 | { 15 | 16 | namespace gadgets 17 | { 18 | 19 | static constexpr double geq_target_zero = 0; 20 | using nonnegative = geq; 21 | 22 | } // namespace gadgets 23 | 24 | } // namespace grotto 25 | 26 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONNEGATIVE_HPP__ 27 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/nonpositive.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/nonpositive.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONPOSITIVE_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONPOSITIVE_HPP__ 10 | 11 | #include "leq.hpp" 12 | 13 | namespace grotto 14 | { 15 | 16 | namespace gadgets 17 | { 18 | 19 | static constexpr double leq_target_zero = 0; 20 | using nonpositive = leq; 21 | 22 | } // namespace gadgets 23 | 24 | } // namespace grotto 25 | 26 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NONPOSITIVE_HPP__ 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Doxygen 35 | build/docs/** 36 | doc/doxygen.log 37 | doc/libdpf.tag.xml 38 | doc/libdpf_full.md 39 | 40 | # Visual Studio Code 41 | .vscode 42 | .vscode/** 43 | !.vscode/settings.json 44 | !.vscode/tasks.json 45 | !.vscode/launch.json 46 | !.vscode/extensions.json 47 | !.vscode/*.code-snippets 48 | 49 | # Local History for Visual Studio Code 50 | .history/ 51 | 52 | # Built Visual Studio Code Extensions 53 | *.vsix 54 | 55 | # CPP lint 56 | __pycache__/** 57 | -------------------------------------------------------------------------------- /doc/directories.dox: -------------------------------------------------------------------------------- 1 | /// @dir ./doc 2 | /// @brief input files used by `Doxygen` to produce this documentation 3 | 4 | /// @dir ./doc/assets 5 | /// @brief image files 6 | 7 | /// @dir ./examples 8 | /// @brief sample code listings to demonstrate use of various `libdpf++` features 9 | 10 | /// @dir ./examples/evaluation 11 | /// @brief evaluation 12 | 13 | /// @dir ./examples/input_types 14 | /// @brief inputs 15 | 16 | /// @dir ./examples/output_types 17 | /// @brief outputs 18 | 19 | /// @dir ./examples/iterables 20 | /// @brief iterable 21 | 22 | /// @dir ./include 23 | /// @brief location of `dph.hpp` and many other `libdpf++` headers in `include/dpf` 24 | 25 | /// @dir ./include/dpf 26 | /// @brief location of most `libdpf++` headers 27 | 28 | /// @dir ./test 29 | /// @brief collection of `GTest` test cases 30 | 31 | /// @dir ./thirdparty 32 | /// @brief submodules and other third-party content 33 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/relu.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/relu.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "leakyrelu.hpp" 16 | #include "grotto/gadget_hints.hpp" 17 | 18 | namespace grotto 19 | { 20 | 21 | namespace gadgets 22 | { 23 | 24 | using relu = leakyrelu; 25 | 26 | } // namespace gadgets 27 | 28 | } // namespace grotto 29 | 30 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU_HPP__ 31 | -------------------------------------------------------------------------------- /include/grotto/gadgets/binary.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/binary.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_HPP__ 10 | 11 | // #include "binary/bit.hpp" 12 | // #include "binary/bit_ceil.hpp" 13 | // #include "binary/bit_floor.hpp" 14 | // #include "binary/bit_width.hpp" 15 | // #include "binary/clrsb.hpp" 16 | // #include "binary/countl_one.hpp" 17 | // #include "binary/countl_zero.hpp" 18 | #include "grotto/gadgets/binary/has_single_bit.hpp" 19 | // #include "elementary/prefix.hpp" 20 | #include "grotto/gadgets/binary/sgn.hpp" 21 | 22 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_HPP__ 23 | -------------------------------------------------------------------------------- /examples/iterables/advice_bit_iterable.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dpf.hpp" 3 | 4 | int main(int argc, char * argv[]) 5 | { 6 | using input_type = uint16_t; 7 | using output_type = dpf::bit; 8 | using dpf_type = dpf::utils::dpf_type_t; 9 | auto memo0 = dpf::make_basic_full_memoizer(); 10 | auto memo1 = dpf::make_basic_full_memoizer(); 11 | input_type x = 42; 12 | output_type y = dpf::bit::one; 13 | auto [dpf0, dpf1] = dpf::make_dpf(x, y); 14 | 15 | auto advice0 = dpf::advice_bits_of(memo0); 16 | auto advice1 = dpf::advice_bits_of(memo1); 17 | 18 | auto it0 = std::begin(advice0), it1 = std::begin(advice1); 19 | for (std::size_t i = 0; i < std::size_t(1)< 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_HPP__ 10 | 11 | #include "grotto/gadgets/misc/entropy.hpp" 12 | #include "grotto/gadgets/misc/erf.hpp" 13 | #include "grotto/gadgets/misc/erfc.hpp" 14 | // #include "grotto/gadgets/misc/expint.hpp" 15 | // #include "grotto/gadgets/misc/gamma.hpp" 16 | // #include "grotto/gadgets/misc/i0.hpp" 17 | // #include "grotto/gadgets/misc/lgamma.hpp" 18 | // #include "grotto/gadgets/misc/reimann_zeta.hpp" 19 | // #include "grotto/gadgets/misc/sinc.hpp" 20 | 21 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_HPP__ 22 | -------------------------------------------------------------------------------- /examples/input_types/modint.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "dpf.hpp" 4 | 5 | int main(int argc, char * argv[]) 6 | { 7 | dpf::modint<10> a(2048); // 2048 % 2^10 = 0 8 | dpf::modint<10> b(1026); // 1026 % 2^10 = 2 9 | std::cout << a + b << std::endl; // = 2 10 | 11 | dpf::modint<10> c(2051); // 2051 % 2^10 = 3 12 | dpf::modint<10> d(1026); // 1026 % 2^10 = 2 13 | std::cout << c - d << std::endl; // = 1 14 | 15 | dpf::modint<10> e(2050); // 2050 % 2^10 = 2 16 | dpf::modint<10> f(1026); // 1026 % 2^10 = 2 17 | std::cout << e * f << std::endl; // = 4 18 | 19 | dpf::modint<10> g(2052); // 2052 % 2^10 = 4 20 | dpf::modint<10> h(1026); // 1026 % 2^10 = 2 21 | std::cout << g / h << std::endl; // = 2 22 | 23 | dpf::modint<10> i(2048); // 2048 % 2^10 = 0 24 | dpf::modint<10> j(1024); // 1024 % 2^10 = 0 25 | std::cout << (i == j) << std::endl; // = 1 26 | } -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "thirdparty/hedley"] 2 | path = thirdparty/hedley 3 | url = https://github.com/DigitalLibertiesLab/hedley.git 4 | [submodule "thirdparty/portable-snippets"] 5 | path = thirdparty/portable-snippets 6 | url = https://github.com/DigitalLibertiesLab/portable-snippets.git 7 | [submodule "thirdparty/doxygen-awesome-css"] 8 | path = thirdparty/doxygen-awesome-css 9 | url = https://github.com/DigitalLibertiesLab/doxygen-awesome-css.git 10 | branch = libdpf 11 | [submodule "thirdparty/json"] 12 | path = thirdparty/json 13 | url = https://github.com/DigitalLibertiesLab/json.git 14 | [submodule "thirdparty/simde"] 15 | path = thirdparty/simde 16 | url = https://github.com/DigitalLibertiesLab/simde.git 17 | [submodule "thirdparty/asio"] 18 | path = thirdparty/asio 19 | url = https://github.com/DigitalLibertiesLab/asio.git 20 | [submodule "test/googletest"] 21 | path = test/googletest 22 | url = https://github.com/google/googletest.git 23 | -------------------------------------------------------------------------------- /include/grotto/gadgets/logarithm.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/logarithm.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_HPP__ 10 | 11 | // #include "grotto/gadgets/logarithm/ilog10.hpp" 12 | #include "grotto/gadgets/logarithm/ilogb.hpp" 13 | // #include "grotto/gadgets/logarithm/ilog16.hpp" 14 | // #include "grotto/gadgets/logarithm/ilog256.hpp" 15 | #include "grotto/gadgets/logarithm/lg.hpp" 16 | #include "grotto/gadgets/logarithm/ln.hpp" 17 | #include "grotto/gadgets/logarithm/log10.hpp" 18 | // #include "grotto/gadgets/logarithm/logn.hpp" 19 | // #include "grotto/gadgets/logarithm/logstar.hpp" 20 | 21 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_HPP__ 22 | -------------------------------------------------------------------------------- /include/grotto/gadgets.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @details 5 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 6 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 7 | /// see [LICENSE.md](@ref GPLv2) for details. 8 | 9 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HPP__ 10 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HPP__ 11 | 12 | // #include "grotto/gadgets/activations.hpp" 13 | // #include "grotto/gadgets/binary.hpp" 14 | #include "grotto/gadgets/decimal.hpp" 15 | // #include "grotto/gadgets/elementary.hpp" 16 | #include "grotto/gadgets/exponential.hpp" 17 | // #include "grotto/gadgets/hyperbolic.hpp" 18 | // #include "grotto/gadgets/logarithm.hpp" 19 | // #include "grotto/gadgets/misc.hpp" 20 | // #include "grotto/gadgets/powers.hpp" 21 | // #include "grotto/gadgets/quantile.hpp" 22 | // #include "grotto/gadgets/trigonometric.hpp" 23 | 24 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HPP__ 25 | -------------------------------------------------------------------------------- /examples/input_types/keyword.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "dpf.hpp" 4 | 5 | int main(int argc, char * argv[]) 6 | { 7 | using keyword_type = dpf::keyword<3, dpf::alphabets::lowercase_alpha>; 8 | using value_type = int; 9 | 10 | std::vector keys = {"cat", "dog", "bat", "pig"}; 11 | std::vector values = {12, 34, 56, 78}; 12 | 13 | auto [dpf0, dpf1] = dpf::make_dpf(keyword_type{"bat"}); 14 | // auto [dpf0, dpf1] = dpf::make_dpf(keyword_type{"rat"}); // key does not exist; result will be 0 15 | 16 | int i=0; 17 | value_type res0{}; 18 | auto [buf0, iter0] = dpf::eval_sequence(dpf0, std::begin(keys), std::end(keys)); 19 | for (auto b : iter0) { if (b) res0 ^= values[i]; i++; } 20 | 21 | i=0; 22 | value_type res1{}; 23 | auto [buf1, iter1] = dpf::eval_sequence(dpf1, std::begin(keys), std::end(keys)); 24 | for (auto b : iter1) { if (b) res1 ^= values[i]; i++; } 25 | 26 | std::cout << (res0 ^ res1) << "\n"; 27 | std::cout << values[2] << "\n"; 28 | } -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_HPP__ 10 | 11 | #include "grotto/gadgets/hyperbolic/acosh.hpp" 12 | #include "grotto/gadgets/hyperbolic/acoth.hpp" 13 | #include "grotto/gadgets/hyperbolic/acsch.hpp" 14 | #include "grotto/gadgets/hyperbolic/asech.hpp" 15 | #include "grotto/gadgets/hyperbolic/asinh.hpp" 16 | #include "grotto/gadgets/hyperbolic/atanh.hpp" 17 | #include "grotto/gadgets/hyperbolic/cosh.hpp" 18 | #include "grotto/gadgets/hyperbolic/coth.hpp" 19 | #include "grotto/gadgets/hyperbolic/csch.hpp" 20 | #include "grotto/gadgets/hyperbolic/sech.hpp" 21 | #include "grotto/gadgets/hyperbolic/sinh.hpp" 22 | #include "grotto/gadgets/hyperbolic/tanh.hpp" 23 | 24 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_HPP__ 25 | -------------------------------------------------------------------------------- /test/tests/setbit_index_iterable_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "dpf.hpp" 4 | 5 | TEST(SetbitIndexIterableTest, BasicUsage) 6 | { 7 | using input_type = uint16_t; 8 | using output_type = dpf::bit; 9 | input_type x = 0xAAAA; 10 | output_type y = dpf::bit::one; 11 | auto [dpf0, dpf1] = dpf::make_dpf(x, y); 12 | auto [buf0, iter0] = dpf::eval_full(dpf0); 13 | auto [buf1, iter1] = dpf::eval_full(dpf1); 14 | 15 | auto setbit0 = dpf::indices_set_in(iter0), 16 | setbit1 = dpf::indices_set_in(iter1); 17 | 18 | auto it0 = std::begin(setbit0), it0end = std::end(setbit0), 19 | it1 = std::begin(setbit1), it1end = std::end(setbit1); 20 | for (; it0 != it0end && it1 != it1end; ++it0, ++it1) 21 | { 22 | if (*it0 == x) 23 | { 24 | ASSERT_EQ(*(++it0), *it1); 25 | } 26 | else if (*it1 == x) 27 | { 28 | ASSERT_EQ(*it0, *(++it1)); 29 | } 30 | else 31 | { 32 | ASSERT_EQ(*it0, *it1); 33 | } 34 | } 35 | ASSERT_EQ(it0, it0end); 36 | ASSERT_EQ(it1, it1end); 37 | } 38 | -------------------------------------------------------------------------------- /include/grotto/gadgets/quantile.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/quantile.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_HPP__ 10 | 11 | // #include "groo/gadgets/quantile/cauchy.hpp" 12 | // #include "groo/gadgets/quantile/chisquared.hpp" 13 | // #include "groo/gadgets/quantile/exponential.hpp" 14 | // #include "groo/gadgets/quantile/gamma.hpp" 15 | // #include "groo/gadgets/quantile/gaussian.hpp" 16 | // #include "groo/gadgets/quantile/geometric.hpp" 17 | // #include "groo/gadgets/quantile/laplace.hpp" 18 | // #include "groo/gadgets/quantile/logistic.hpp" 19 | // #include "groo/gadgets/quantile/lognormal.hpp" 20 | // #include "groo/gadgets/quantile/pareto.hpp" 21 | // #include "groo/gadgets/quantile/poisson.hpp" 22 | // #include "groo/gadgets/quantile/powerlaw.hpp" 23 | // #include "groo/gadgets/quantile/standard_t.hpp" 24 | 25 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_QUANTILE_HPP__ 26 | -------------------------------------------------------------------------------- /examples/input_types/keyword_int_map.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "dpf.hpp" 5 | 6 | int main(int argc, char * argv[]) 7 | { 8 | static constexpr char lc[] = "abcdefghijklmnopqrstuvwxyz"; 9 | using keyword_type = dpf::keyword<3, lc>; 10 | using value_type = int; 11 | 12 | std::map database{{"cat", 12}, 13 | {"bat", 34}, 14 | {"dog", 56}, 15 | {"pig", 78}}; 16 | 17 | keyword_type x = "bat"; 18 | std::cout << x << std::endl; 19 | auto [dpf0, dpf1] = dpf::make_dpf(x); 20 | 21 | value_type share0{}, share1{}; 22 | auto path0 = dpf::make_basic_path_memoizer(dpf0); 23 | auto path1 = dpf::make_basic_path_memoizer(dpf1); 24 | for (auto & [key, value] : database) 25 | { 26 | if (dpf::eval_point(dpf0, key, path0)) {share0 ^= value; std::cout << value << std::endl;} 27 | if (dpf::eval_point(dpf1, key, path1)) share1 ^= value; 28 | } 29 | 30 | std::cout << share0 << share1 << "\n"; 31 | std::cout << std::string(x) << "(" << x << ")->" << (share0 ^ share1) << "\n"; 32 | } -------------------------------------------------------------------------------- /examples/input_types/bitstring.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dpf.hpp" 3 | 4 | int main() { 5 | // Define a bit array with 10 bits 6 | using BitArrayBase = dpf::bit_array_base; 7 | using ConcreteBitArray = dpf::bit_array_base; 8 | 9 | ConcreteBitArray arr(10); 10 | 11 | // Set some bits to true 12 | arr.set(1); 13 | arr.set(3); 14 | arr.set(5); 15 | 16 | // Print the bit array 17 | std::cout << "Bit Array: "; 18 | for (std::size_t i = 0; i < arr.size(); ++i) { 19 | std::cout << arr[i]; 20 | } 21 | std::cout << std::endl; 22 | 23 | // Check if specific bits are set 24 | std::cout << "Bit at index 1 is set: " << arr.test(1) << std::endl; 25 | std::cout << "Bit at index 2 is set: " << arr.test(2) << std::endl; 26 | 27 | // Count the number of bits set to true 28 | std::cout << "Number of bits set to true: " << arr.count() << std::endl; 29 | 30 | // Toggle some bits 31 | arr.flip(3); 32 | arr.flip(6); 33 | 34 | // Print the modified bit array 35 | std::cout << "Modified Bit Array: "; 36 | for (std::size_t i = 0; i < arr.size(); ++i) { 37 | std::cout << arr[i]; 38 | } 39 | std::cout << std::endl; 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /test/tests/advice_bit_iterable_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "dpf.hpp" 4 | 5 | TEST(AdviceBitIterableTest, BasicUsage) 6 | { 7 | using input_type = uint16_t; 8 | using output_type = dpf::bit; 9 | using dpf_type = dpf::utils::dpf_type_t; 10 | auto memo0 = dpf::make_basic_full_memoizer(), 11 | memo1 = dpf::make_basic_full_memoizer(); 12 | input_type x = 0xAAAA; 13 | output_type y = dpf::bit::one; 14 | auto [dpf0, dpf1] = dpf::make_dpf(x, y); 15 | auto [buf0, iter0] = dpf::eval_full(dpf0, memo0); 16 | auto [buf1, iter1] = dpf::eval_full(dpf1, memo1); 17 | 18 | auto advice0 = dpf::advice_bits_of(memo0), 19 | advice1 = dpf::advice_bits_of(memo1); 20 | 21 | auto it0 = std::begin(advice0), it1 = std::begin(advice1); 22 | for (std::size_t i = 0; i < std::size_t(1)< 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_HPP__ 10 | 11 | #include "grotto/gadgets/trigonometric/acos.hpp" 12 | #include "grotto/gadgets/trigonometric/acot.hpp" 13 | #include "grotto/gadgets/trigonometric/acsc.hpp" 14 | #include "grotto/gadgets/trigonometric/asec.hpp" 15 | #include "grotto/gadgets/trigonometric/asin.hpp" 16 | #include "grotto/gadgets/trigonometric/atan.hpp" 17 | #include "grotto/gadgets/trigonometric/cos.hpp" 18 | #include "grotto/gadgets/trigonometric/cot.hpp" 19 | #include "grotto/gadgets/trigonometric/csc.hpp" 20 | #include "grotto/gadgets/trigonometric/deg2rad.hpp" 21 | #include "grotto/gadgets/trigonometric/rad2deg.hpp" 22 | #include "grotto/gadgets/trigonometric/sec.hpp" 23 | #include "grotto/gadgets/trigonometric/sin.hpp" 24 | #include "grotto/gadgets/trigonometric/tan.hpp" 25 | 26 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_HPP__ 27 | -------------------------------------------------------------------------------- /examples/evaluation/eval_full.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "dpf.hpp" 4 | 5 | int main(int arc, char * argv[]) 6 | { 7 | uint16_t x = 42; // Input value 8 | using prg = dpf::prg::counter_wrapper; // This is just to count the number of PRG invocations 9 | auto before = prg::count(); // In order to show how much this program cost 10 | auto [dpf0, dpf1] = dpf::make_dpf(x); 11 | auto after = prg::count(); 12 | std::cout << "dpf::make_dpf used " << (after-before) << "\n"; 13 | 14 | before = prg::count(); 15 | auto [buf0, iter0] = dpf::eval_full(dpf0); 16 | after = prg::count(); 17 | std::cout << "dpf::eval_full(dpf0) used " << (after-before) << "\n"; 18 | before = prg::count(); 19 | auto [buf1, iter1] = dpf::eval_full(dpf1); 20 | after = prg::count(); 21 | std::cout << "dpf::eval_full(dpf1) used " << (after-before) << "\n"; 22 | // Retrieve the original input by iterating over the two buffers 23 | for (size_t i = 0; i < buf0.size(); ++i) { 24 | bool item1 = buf0[i]; 25 | bool item2 = buf1[i]; 26 | if (item1 ^ item2) std::cout << "The original input is: " << i << std::endl; 27 | } 28 | 29 | std::cout << "Total PRG invocation: " << prg::count() << "\n"; 30 | return 0; 31 | } -------------------------------------------------------------------------------- /include/grotto/gadgets/misc/erf.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/misc/erf.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_ERF_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_ERF_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct erf 24 | { 25 | template 26 | T operator()(T x) { std::erf(static_cast(x)); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double hint_poles[] = { }; 35 | static constexpr double hint_interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array hint_canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_ERF_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/misc/erfc.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/misc/erfc.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_ERFC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_ERFC_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct erf 24 | { 25 | template 26 | T operator()(T x) { std::erfc(static_cast(x)); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double hint_poles[] = { }; 35 | static constexpr double hint_interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array hint_canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_ERFC_HPP__ 47 | -------------------------------------------------------------------------------- /include/dpf/prg_dummy.hpp: -------------------------------------------------------------------------------- 1 | /// @file dpf/prg_dummy.hpp 2 | /// @brief 3 | /// @details 4 | /// @author Ryan Henry 5 | /// @copyright Copyright (c) 2019-2024 Ryan Henry and [others](@ref authors) 6 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 7 | /// see [LICENSE.md](@ref license) for details. 8 | 9 | #ifndef LIBDPF_INCLUDE_DPF_PRG_DUMMY_HPP__ 10 | #define LIBDPF_INCLUDE_DPF_PRG_DUMMY_HPP__ 11 | 12 | #include 13 | #include 14 | 15 | #include "hedley/hedley.h" 16 | #include "portable-snippets/exact-int/exact-int.h" 17 | 18 | #include "dpf/utils.hpp" 19 | 20 | namespace dpf 21 | { 22 | 23 | namespace prg 24 | { 25 | 26 | struct dummy final 27 | { 28 | using block_type = simde__m128i; 29 | 30 | static block_type eval(block_type seed, psnip_uint32_t) 31 | { 32 | return seed; 33 | } 34 | 35 | static auto eval01(block_type seed) 36 | { 37 | HEDLEY_PRAGMA(GCC diagnostic push) 38 | HEDLEY_PRAGMA(GCC diagnostic ignored "-Wignored-attributes") 39 | return std::array{seed, seed}; 40 | HEDLEY_PRAGMA(GCC diagnostic pop) 41 | } 42 | 43 | static void eval(block_type seed, block_type * HEDLEY_RESTRICT output, 44 | psnip_uint32_t count_, psnip_uint32_t = 0) 45 | { 46 | std::fill_n(output, count_, seed); 47 | } 48 | }; // struct dummy 49 | 50 | } // namespace prg 51 | 52 | } // namespace dpf 53 | 54 | #endif // LIBDPF_INCLUDE_DPF_PRG_DUMMY_HPP__ 55 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/silu.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/silu.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SILU_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SILU_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct silu 24 | { 25 | template 26 | T operator()(T x) { return x*sigmoid{}(x); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SILU_HPP__ 47 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: docs 2 | docs: 3 | @mkdir -p build/docs 4 | @sed -e '/%LIBDPF_INCLUDE_GETTING_STARTED_INTRODUCTION%/{r doc/pages/introduction.md' -e 'd}' doc/libdpf.md > doc/libdpf_full.md 5 | @sed -i -e '/%LIBDPF_INCLUDE_GETTING_DPF_BASICS%/{r doc/pages/basics.md' -e 'd}' doc/libdpf_full.md 6 | @sed -i -e '/%LIBDPF_INCLUDE_GETTING_STARTED_INPUT_TYPES%/{r doc/pages/input_types.md' -e 'd}' doc/libdpf_full.md 7 | @sed -i -e '/%LIBDPF_INCLUDE_GETTING_STARTED_OUTPUT_TYPES%/{r doc/pages/output_types.md' -e 'd}' doc/libdpf_full.md 8 | @sed -i -e '/%LIBDPF_INCLUDE_GETTING_STARTED_EVALUATION%/{r doc/pages/evaluation.md' -e 'd}' doc/libdpf_full.md 9 | @sed -i -e '/%LIBDPF_INCLUDE_GETTING_STARTED_ITERABLES%/{r doc/pages/iterables.md' -e 'd}' doc/libdpf_full.md 10 | @sed -i -e '/%LIBDPF_INCLUDE_PIR_PIR1%/{r doc/pages/pir1.md' -e 'd}' doc/libdpf_full.md 11 | @sed -i -e '/%LIBDPF_INCLUDE_MISC_BUGS%/{r BUGS.md' -e 'd}' doc/libdpf_full.md 12 | @sed -i -e '/%LIBDPF_INCLUDE_MISC_CHANGES%/{r CHANGES.md' -e 'd}' doc/libdpf_full.md 13 | @sed -i -e '/%LIBDPF_INCLUDE_MISC_TODO%/{r TODO.md' -e 'd}' doc/libdpf_full.md 14 | @sed -i -e '/%LIBDPF_INCLUDE_MISC_SUBMODULES%/{r doc/pages/submodules.md' -e 'd}' doc/libdpf_full.md 15 | @sed -i -e '/%LIBDPF_INCLUDE_MISC_AUTHORS%/{r AUTHORS.md' -e 'd}' doc/libdpf_full.md 16 | @sed -i -e '/%LIBDPF_INCLUDE_MISC_LICENSE%/{r LICENSE.md' -e 'd}' doc/libdpf_full.md 17 | @sed -i -e '/%LIBDPF_INCLUDE_CODE_LISTINGS%/{r doc/pages/listings.md' -e 'd}' doc/libdpf_full.md 18 | @doxygen doc/Doxyfile -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/rect.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/rect.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_RECT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_RECT_HPP__ 10 | 11 | #include 12 | #include 13 | 14 | #include "grotto/gadget_hints.hpp" 15 | 16 | namespace grotto 17 | { 18 | 19 | namespace gadgets 20 | { 21 | 22 | struct rect 23 | { 24 | template 25 | T operator()(T x) { return x == 0; } 26 | }; 27 | 28 | template <> 29 | struct gadget_hints 30 | { 31 | static constexpr double min = std::numeric_limits::min(); 32 | static constexpr double max = std::numeric_limits::max(); 33 | static constexpr unsigned degree = 0; 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { -0.5, 0.5 }; 36 | static constexpr bool has_canonical_representation = true; 37 | static constexpr double canonical_bounds[] = { -0.5, -0.5, 0.5, 0.5 }; 38 | static constexpr std::array canonical_polys[] = { 0, 0.5, 1, 0.50, 0 }; 39 | }; 40 | 41 | } // namespace gadgets 42 | 43 | } // namespace grotto 44 | 45 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_RECT_HPP__ 46 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/tanh.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/tanh.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_TANH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_TANH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct tanh 24 | { 25 | template 26 | T operator()(T x) { return std::tanh(static_cast(x)); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_TANH_HPP__ 47 | -------------------------------------------------------------------------------- /test/tests/helpers/custom_output_type_large_xor.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class custom_output_type_large_xor 4 | { 5 | public: 6 | constexpr custom_output_type_large_xor() 7 | : a_{0}, b_{0}, c_{0}, d_{0} 8 | { } 9 | 10 | constexpr custom_output_type_large_xor(uint64_t val) 11 | : a_{val}, b_{val}, c_{val}, d_{val} 12 | { } 13 | 14 | constexpr custom_output_type_large_xor(uint64_t a, uint64_t b, uint64_t c, uint64_t d) 15 | : a_{a}, b_{b}, c_{c}, d_{d} 16 | { } 17 | 18 | custom_output_type_large_xor operator-(const custom_output_type_large_xor & rhs) const 19 | { 20 | return this->operator^(rhs); 21 | } 22 | 23 | custom_output_type_large_xor operator^(const custom_output_type_large_xor & rhs) const 24 | { 25 | return custom_output_type_large_xor{this->a_ ^ rhs.a_, this->b_ ^ rhs.b_, this->c_ ^ rhs.c_, this->d_ ^ rhs.d_}; 26 | } 27 | 28 | bool operator==(const custom_output_type_large_xor & rhs) const 29 | { 30 | return this->a_ == rhs.a_ && this->b_ == rhs.b_ && this->c_ == rhs.c_ && this->d_ == rhs.d_; 31 | } 32 | 33 | private: 34 | uint64_t a_, b_, c_, d_; 35 | }; 36 | 37 | namespace dpf::utils 38 | { 39 | 40 | template <> 41 | struct make_from_integral_value 42 | { 43 | constexpr custom_output_type_large_xor operator()(uint64_t val) const noexcept 44 | { 45 | return custom_output_type_large_xor{val, val, val, val}; 46 | } 47 | }; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/sech.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/sech.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SECH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SECH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct sech 24 | { 25 | template 26 | T operator()(T x) { return 1/std::cosh(static_cast(x)); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SECH_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/asinh.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/asinh.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASINH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASINH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct asinh 24 | { 25 | template 26 | T operator()(T x) { return std::asinh(static_cast(x)); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASINH_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/sigmoid.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/sigmoid.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SIGMOID_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SIGMOID_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct sigmoid 24 | { 25 | template 26 | T operator()(T x) { return 1/(1+std::exp(-x)); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SIGMOID_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/abs.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/abs.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ABS_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ABS_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct abs 24 | { 25 | template 26 | T operator()(T x) { return std::abs(static_cast(x)); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { 0 }; 36 | static constexpr unsigned degree = 1; 37 | static constexpr bool has_canonical_representation = true; 38 | static constexpr double canonical_bounds[] = { 0 }; 39 | static constexpr std::array canonical_polys[] = { { -1, 0 }, { 1, 0 } }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_ABS_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/atan.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/atan.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ATAN_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ATAN_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct atan 24 | { 25 | template 26 | T operator()(T x) { return std::atan(static_cast(x)); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ATAN_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/softsign.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/softsign.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTSIGN_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTSIGN_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct hardsign 24 | { 25 | template 26 | T operator()(T x) { return x/(1+std::abs(x)); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { }; 36 | static constexpr unsigned degree = 1; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTSIGN_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/tanhexp.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/tanhexp.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHEXP_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHEXP_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct tanhexp 24 | { 25 | template 26 | T operator()(T x) { return x*std::tanh(std::exp(x)); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHEXP_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/powers/cbrt.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/powers/cbrt.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_CBRT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_CBRT_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct cbrt 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x < 0) return 0; // TODO 29 | return std::cbrt(static_cast(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = 0; 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_CBRT_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/powers/sqrt.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/powers/sqrt.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_SQRT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_SQRT_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct sqrt 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x < 0) return 0; // TODO 29 | return std::sqrt(static_cast(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = 0; 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_SQRT_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/atanh.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/atanh.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ATANH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ATANH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct atanh 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (std::abs(x) >= 1) return 0; 29 | return std::atanh(static_cast(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = -1; 37 | static constexpr double max = 1; 38 | static constexpr double poles[] = { -1, 1 }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ATANH_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/powers/qtrt.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/powers/qtrt.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_QTRT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_QTRT_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct qtrt 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x < 0) return 0; // TODO 29 | return std::pow(static_cast(x), 0.25); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = 0; 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_QTRT_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/tanhshrink.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/tanhshrink.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHSHRINK_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHSHRINK_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct tanhshrink 24 | { 25 | template 26 | T operator()(T x) { return x -std::tanh(x); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_TANHSHRINK_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/cos.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/cos.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_COS_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_COS_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct cos 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (std::abs(x) >= M_PI) return 0; // TODO 29 | return std::cos(static_cast(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = -M_PI; 37 | static constexpr double max = M_PI; 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_COS_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/sin.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/sin.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_SIN_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_SIN_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct sin 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (std::abs(x) >= M_PI) return 0; // TODO 29 | return std::sin(static_cast(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = -M_PI; 37 | static constexpr double max = M_PI; 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_SIN_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/lt.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/lt.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LT_HPP__ 10 | 11 | #include 12 | #include 13 | 14 | #include "grotto/gadget_hints.hpp" 15 | 16 | namespace grotto 17 | { 18 | 19 | namespace gadgets 20 | { 21 | 22 | template 23 | struct lt 24 | { 25 | template 26 | T operator()(T x) { return x < target; } 27 | }; 28 | 29 | template 30 | struct gadget_hints> 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { target }; 36 | static constexpr unsigned degree = 0; 37 | static constexpr bool has_canonical_representation = true; 38 | static constexpr double canonical_bounds[] = { target, target }; 39 | static constexpr std::array canonical_polys[] = { 1, 0, 0 }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LT_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/logarithm/lg.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/logarithm/lg.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LG_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LG_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct lg 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= 0) return 0; // TODO 29 | return std::log2(static_cast(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::exp2(-63); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { 0 }; 39 | static constexpr double interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LG_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/logarithm/ln.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/logarithm/ln.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LN_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LN_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct ln 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= 0) return 0; // TODO 29 | return std::log(static_cast(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::exp2(-63); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { 0 }; 39 | static constexpr double interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LN_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/geq.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/geq.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GEQ_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GEQ_HPP__ 10 | 11 | #include 12 | #include 13 | 14 | #include "grotto/gadget_hints.hpp" 15 | 16 | namespace grotto 17 | { 18 | 19 | namespace gadgets 20 | { 21 | 22 | template 23 | struct geq 24 | { 25 | template 26 | T operator()(T x) { return x >= target; } 27 | }; 28 | 29 | template 30 | struct gadget_hints> 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { target }; 36 | static constexpr bool has_canonical_representation = true; 37 | static constexpr unsigned degree = 0; 38 | static constexpr double canonical_bounds[] = { target, target }; 39 | static constexpr std::array canonical_polys[] = { 0, 1, 1 }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GEQ_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/gt.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/gt.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GT_HPP__ 10 | 11 | #include 12 | #include 13 | 14 | #include "grotto/gadget_hints.hpp" 15 | 16 | namespace grotto 17 | { 18 | 19 | namespace gadgets 20 | { 21 | 22 | template 23 | struct gt 24 | { 25 | template 26 | T operator()(T x) { return x > target; } 27 | }; 28 | 29 | 30 | template 31 | struct gadget_hints> 32 | { 33 | static constexpr double min = std::numeric_limits::min(); 34 | static constexpr double max = std::numeric_limits::max(); 35 | static constexpr unsigned degree = 0; 36 | static constexpr double poles[] = { }; 37 | static constexpr double interesting_points[] = { target }; 38 | static constexpr bool has_canonical_representation = true; 39 | static constexpr double canonical_bounds[] = { target, target }; 40 | static constexpr std::array canonical_polys[] = { 0, 0, 1 }; 41 | }; 42 | 43 | } // namespace gadgets 44 | 45 | } // namespace grotto 46 | 47 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_GT_HPP__ 48 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/neq.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/neq.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEQ_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEQ_HPP__ 10 | 11 | #include 12 | #include 13 | 14 | #include "grotto/gadget_hints.hpp" 15 | 16 | namespace grotto 17 | { 18 | 19 | namespace gadgets 20 | { 21 | 22 | template 23 | struct neq 24 | { 25 | template 26 | T operator()(T x) { return x != target; } 27 | }; 28 | 29 | template 30 | struct gadget_hints> 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr unsigned degree = 0; 35 | static constexpr double poles[] = { }; 36 | static constexpr bool has_canonical_representation = true; 37 | static constexpr double interesting_points[] = { target }; 38 | static constexpr double canonical_bounds[] = { target, target }; 39 | static constexpr std::array canonical_polys[] = { 1, 0, 1 }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_NEQ_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/cosh.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/cosh.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COSH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COSH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct cosh 24 | { 25 | template 26 | T operator()(T x) { return std::min(std::cosh(static_cast(x)), std::numeric_limits::max()); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { }; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double canonical_bounds[] = { }; 39 | static constexpr std::array canonical_polys[] = { }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COSH_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_HPP__ 10 | 11 | #include "grotto/gadgets/elementary/abs.hpp" 12 | #include "grotto/gadgets/elementary/approx.hpp" 13 | #include "grotto/gadgets/elementary/boxcar.hpp" 14 | #include "grotto/gadgets/elementary/clip.hpp" 15 | #include "grotto/gadgets/elementary/eq.hpp" 16 | #include "grotto/gadgets/elementary/geq.hpp" 17 | #include "grotto/gadgets/elementary/gt.hpp" 18 | // #include "grotto/gadgets/elementary/identity.hpp" 19 | #include "grotto/gadgets/elementary/leq.hpp" 20 | #include "grotto/gadgets/elementary/lt.hpp" 21 | #include "grotto/gadgets/elementary/negative.hpp" 22 | #include "grotto/gadgets/elementary/neq.hpp" 23 | #include "grotto/gadgets/elementary/nonnegative.hpp" 24 | #include "grotto/gadgets/elementary/nonpositive.hpp" 25 | // #include "grotto/gadgets/elementary/pmone.hpp" 26 | #include "grotto/gadgets/elementary/positive.hpp" 27 | #include "grotto/gadgets/elementary/rect.hpp" 28 | #include "grotto/gadgets/elementary/step.hpp" 29 | // #include "grotto/gadgets/elementary/ternary.hpp" 30 | #include "grotto/gadgets/elementary/zero.hpp" 31 | 32 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_HPP__ 33 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/eq.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/eq.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_EQ_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_EQ_HPP__ 10 | 11 | #include 12 | #include 13 | 14 | #include "grotto/gadget_hints.hpp" 15 | 16 | namespace grotto 17 | { 18 | 19 | namespace gadgets 20 | { 21 | 22 | template 23 | struct eq 24 | { 25 | template 26 | T operator()(T x) { return x == target; } 27 | }; 28 | 29 | 30 | template 31 | struct gadget_hints> 32 | { 33 | static constexpr double min = std::numeric_limits::lowest(); 34 | static constexpr double max = std::numeric_limits::max(); 35 | static constexpr unsigned degree = 0; 36 | static constexpr double poles[] = { }; 37 | static constexpr double interesting_points[] = { target }; 38 | static constexpr bool has_canonical_representation = true; 39 | static constexpr double canonical_bounds[] = { target, target }; 40 | static constexpr std::array canonical_polys[] = { 0, 1, 0 }; 41 | }; 42 | 43 | } // namespace gadgets 44 | 45 | } // namespace grotto 46 | 47 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_EQ_HPP__ 48 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/leq.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elementary/leqw.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LEQ_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LEQ_HPP__ 10 | 11 | #include 12 | #include 13 | 14 | #include "grotto/gadget_hints.hpp" 15 | 16 | namespace grotto 17 | { 18 | 19 | namespace gadgets 20 | { 21 | 22 | template 23 | struct leq 24 | { 25 | template 26 | T operator()(T x) { return x <= target; } 27 | }; 28 | 29 | template 30 | struct gadget_hints> 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double poles[] = { }; 35 | static constexpr double interesting_points[] = { target }; 36 | static constexpr unsigned degree = 0; 37 | static constexpr bool has_canonical_representation = true; 38 | static constexpr double canonical_bounds[] = { target, target }; 39 | static constexpr std::array canonical_polys[] = { 1, 1, 0 }; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_LEQ_HPP__ 47 | -------------------------------------------------------------------------------- /test/tests/helpers/custom_output_type_small.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class custom_output_type_small 4 | { 5 | public: 6 | constexpr custom_output_type_small() 7 | : val_{0} 8 | { } 9 | 10 | constexpr custom_output_type_small(uint64_t val) 11 | : val_{val} 12 | { } 13 | 14 | custom_output_type_small operator+(const custom_output_type_small & rhs) const 15 | { 16 | return custom_output_type_small{this->val_ + rhs.val_}; 17 | } 18 | 19 | custom_output_type_small operator-(const custom_output_type_small & rhs) const 20 | { 21 | return custom_output_type_small{this->val_ - rhs.val_}; 22 | } 23 | 24 | custom_output_type_small operator^(const custom_output_type_small & rhs) const 25 | { 26 | return custom_output_type_small{this->val_ ^ rhs.val_}; 27 | } 28 | 29 | bool operator==(const custom_output_type_small & rhs) const 30 | { 31 | return this->val_ == rhs.val_; 32 | } 33 | 34 | private: 35 | uint64_t val_; 36 | }; 37 | 38 | namespace dpf::leaf_arithmetic 39 | { 40 | 41 | HEDLEY_PRAGMA(GCC diagnostic push) 42 | HEDLEY_PRAGMA(GCC diagnostic ignored "-Wignored-attributes") 43 | template <> struct add_t final : public detail::add2x64_t {}; 44 | template <> struct subtract_t final : public detail::sub2x64_t {}; 45 | template <> struct multiply_t final : public detail::mul2x64_t {}; 46 | HEDLEY_PRAGMA(GCC diagnostic pop) 47 | 48 | } 49 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/mish.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/mish.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_MISH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_MISH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "softplus.hpp" 16 | #include "grotto/gadget_hints.hpp" 17 | 18 | namespace grotto 19 | { 20 | 21 | namespace gadgets 22 | { 23 | 24 | struct mish 25 | { 26 | template 27 | T operator()(T x) 28 | { 29 | return x*std::tanh(softplus<>{}(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_MISH_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/serf.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/serf.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SERF_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SERF_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "softplus.hpp" 16 | #include "grotto/gadget_hints.hpp" 17 | 18 | namespace grotto 19 | { 20 | 21 | namespace gadgets 22 | { 23 | 24 | struct serf 25 | { 26 | template 27 | T operator()(T x) 28 | { 29 | return x*std::erf(softplus<>{}(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SERF_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/binary/sgn.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/binary/sg.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_SGN_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_SGN_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct sgn 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x == 0) return 0; 29 | else return std::signbit(static_cast(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 0; 41 | static constexpr bool has_canonical_representation = true; 42 | static constexpr double canonical_bounds[] = { 0, 0 }; 43 | static constexpr std::array canonical_polys[] = { -1, 0, 1 }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_SGN_HPP__ 51 | -------------------------------------------------------------------------------- /doc/pages/introduction.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | ## Synopsis {#synopsis} 4 | 5 | `libdpf++` is a fast and extensible, header-only C++17 implementation of 6 | `(2,2)-`*distributed point functions* (or *DPFs*). In addition to core DPF 7 | functionality, `libdpf++` provides a plethora of data structures, helper 8 | functions, and syntactic sugar designed to facilitate seamless integration 9 | into higher-level cryptographic protocols and primitives. With its focus on 10 | speed and ease of use, `libdpf++` is an ideal building block for implementing 11 | private information retrieval (PIR), secure multiparty computation (MPC), 12 | zero-knowledge arguments, anonymous messaging, and more. 13 | 14 | ## Features {#features} 15 | 16 | - input types 17 | - output types 18 | - wildcards 19 | - multiple leaves 20 | - evaluation types 21 | - memoizers 22 | - json serialization 23 | - asynchronous I/O 24 | 25 | ## Credits {#credits} 26 | 27 | - Adithya Vadapalli (IIT Kanpur) 28 | - Kyle Storrier (UCalgary) 29 | - Allan Lyons (UCalgary) 30 | 31 | ## Disclaimer {#disclaimer} 32 | 33 | We bet you $50 that there is at least one security bug in this code base. If you are you use this code, it is on you to verify that bug does not cross any of the same code paths as you. -------------------------------------------------------------------------------- /examples/evaluation/eval_interval.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dpf.hpp" 3 | 4 | int main(int arc, char * argv[]) 5 | { 6 | uint16_t x = 42, y; 7 | using prg = dpf::prg::counter_wrapper; 8 | 9 | // Make the DPF 10 | auto before = prg::count(); 11 | auto [dpf0, dpf1] = dpf::make_dpf(x); 12 | auto after = prg::count(); 13 | std::cout << "dpf::make_dpf prg invocation: " << (after-before) << "\n"; 14 | 15 | // Evaluate the DPF by interval 16 | before = prg::count(); 17 | int from = 0, to = 49; 18 | auto [buf0, iter0] = dpf::eval_interval(dpf0, from, to); 19 | auto [buf1, iter1] = dpf::eval_interval(dpf1, from, to); 20 | after = prg::count(); 21 | std::cout << "dpf::eval_interval prg invocation: " << (after-before) << "\n"; 22 | 23 | // Retrieve the original input by iterating over the two buffers 24 | std::vector result; 25 | for (size_t i = from; i < to+1; ++i) { 26 | bool item1 = buf0[i]; 27 | bool item2 = buf1[i]; 28 | result.push_back(item1 ^ item2); 29 | if (item1 ^ item2) y=i; 30 | } 31 | // Print out the XOR interval 32 | for (const auto& item : result) { 33 | std::cout << static_cast(item); 34 | } 35 | std::cout << std::endl; 36 | if (y == x) std::cout << "The orginal value is: " << x << std::endl; 37 | else std::cout << "The evaluated inputs did not match the original value." << std::endl; 38 | 39 | std::cout << "Total PRG invocation: " << prg::count() << std::endl; 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/logsigmoid.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/logsigmoid.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LOGSIGMOID_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LOGSIGMOID_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "sigmoid.hpp" 16 | #include "grotto/gadget_hints.hpp" 17 | 18 | namespace grotto 19 | { 20 | 21 | namespace gadgets 22 | { 23 | 24 | struct logsigmoid 25 | { 26 | template 27 | T operator()(T x) { return std::log(sigmoid{}(x)); } 28 | }; 29 | 30 | template <> 31 | struct gadget_hints 32 | { 33 | static constexpr double min = std::numeric_limits::min(); 34 | static constexpr double max = std::numeric_limits::max(); 35 | static constexpr double poles[] = { }; 36 | static constexpr double interesting_points[] = { }; 37 | static constexpr unsigned degree = 3; 38 | static constexpr bool has_canonical_representation = false; 39 | static constexpr double canonical_bounds[] = { }; 40 | static constexpr std::array canonical_polys[] = { }; 41 | }; 42 | 43 | } // namespace gadgets 44 | 45 | } // namespace grotto 46 | 47 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LOGSIGMOID_HPP__ 48 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/asech.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/asech.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASECH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASECH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct asech 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= 0) return 0; // TODO 29 | if (x > 1) return 0; // TODO 30 | return std::acosh(1/static_cast(x)); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = 0; 38 | static constexpr double max = 1; 39 | static constexpr double poles[] = { 0 }; 40 | static constexpr double interesting_points[] = { }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ASECH_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/lecun_tanh.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/lecun_tanh.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | 9 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LECUNTANH_HPP__ 10 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LECUNTANH_HPP__ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "grotto/gadget_hints.hpp" 17 | 18 | namespace grotto 19 | { 20 | 21 | namespace gadgets 22 | { 23 | 24 | struct lecun_tanh 25 | { 26 | template 27 | T operator()(T x) 28 | { 29 | return 1.7159*std::tanh(2*x/3); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_LECUNTANH_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/gelu.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/gelu.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_GELU_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_GELU_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct gelu 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | return std::min(x*(1+std::erf(x/std::sqrt(2)))/2, std::numeric_limits::max()); 29 | } 30 | }; 31 | 32 | template <> 33 | struct gadget_hints 34 | { 35 | static constexpr double min = std::numeric_limits::min(); 36 | static constexpr double max = std::numeric_limits::max(); 37 | static constexpr double poles[] = { }; 38 | static constexpr double interesting_points[] = { }; 39 | static constexpr unsigned degree = 3; 40 | static constexpr bool has_canonical_representation = false; 41 | static constexpr double canonical_bounds[] = { }; 42 | static constexpr std::array canonical_polys[] = { }; 43 | }; 44 | 45 | } // namespace gadgets 46 | 47 | } // namespace grotto 48 | 49 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_GELU_HPP__ 50 | -------------------------------------------------------------------------------- /include/grotto/gadgets/logarithm/log10.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/logarithm/log10.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LOG10_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LOG10_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct log10 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= 0) return 0; // TODO 29 | return std::log10(static_cast(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::exp2(-63); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double hint_poles[] = { 0 }; 39 | static constexpr double hint_interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array hint_canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_LOG10_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/exponential/exp.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/exponential/exp.hpp 2 | /// @author Ryan Henry 3 | /// @brief gadgetized form of `std::exp` 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct exp 24 | { 25 | template 26 | T operator()(T x) { return std::min(std::exp(static_cast(x)), std::numeric_limits::max()); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double * poles = nullptr; 35 | static constexpr double * interesting_points = nullptr; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double * canonical_bounds = nullptr; 39 | static constexpr std::array * canonical_polys = nullptr; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/logarithm/ilog16.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/logarithm/ilog16.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG16_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG16_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct ilog16 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= 0) return 0; // TODO 29 | return std::ceil(std::log2(static_cast(x))/4); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::exp2(-63); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double hint_poles[] = { }; 39 | static constexpr double hint_interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 0; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array hint_canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG16_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/logarithm/ilog10.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/logarithm/ilog10.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG10_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG10_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct ilog256 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= 0) return 0; // TODO 29 | return std::ceil(std::log2(static_cast(x))/8); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::exp2(-63); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double hint_poles[] = { }; 39 | static constexpr double hint_interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 0; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array hint_canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG10_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/deg2rad.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/deg2rad.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRY_DEG2RAD_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRY_DEG2RAD_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct deg2rad 24 | { 25 | template 26 | T operator()(T x) { 27 | double X = std::fmod(static_cast(x), 360); 28 | if (X < 0) X += 360; 29 | return X*180/M_PI; 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = -180; 37 | static constexpr double max = 180; 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 1; 41 | static constexpr bool has_canonical_representation = true; 42 | static constexpr double canonical_bounds[] = { 0 }; 43 | static constexpr std::array canonical_polys[] = { { 180/M_PI, 0 } }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRY_DEG2RAD_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/exponential/exp2.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/exponential/exp2.hpp 2 | /// @author Ryan Henry 3 | /// @brief gadgetized form of `std::exp2` 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP2_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP2_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct exp2 24 | { 25 | template 26 | T operator()(T x) { return std::min(std::exp2(static_cast(x)), std::numeric_limits::max()); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double * poles = nullptr; 35 | static constexpr double * interesting_points = nullptr; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool has_canonical_representation = false; 38 | static constexpr double * canonical_bounds = nullptr; 39 | static constexpr std::array * canonical_polys = nullptr; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP2_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/acoth.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/acoth.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOTH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOTH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct acoth 24 | { 25 | template 26 | T operator()(T x) { 27 | if (std::abs(x) <= 1) return 0; // TODO 28 | return std::atanh(1 / static_cast(x)); } 29 | }; 30 | 31 | template <> 32 | struct gadget_hints 33 | { 34 | static constexpr double min = std::numeric_limits::min(); 35 | static constexpr double max = std::numeric_limits::max(); 36 | static constexpr double poles[] = { -1, 1 }; 37 | static constexpr double interesting_points[] = { -1, 1 }; 38 | static constexpr unsigned degree = 3; 39 | static constexpr bool has_canonical_representation = false; 40 | static constexpr double canonical_bounds[] = { }; 41 | static constexpr std::array canonical_polys[] = { }; 42 | }; 43 | 44 | } // namespace gadgets 45 | 46 | } // namespace grotto 47 | 48 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOTH_HPP__ 49 | -------------------------------------------------------------------------------- /include/grotto/gadgets/logarithm/ilog256.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/logarithm/ilog256.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG256_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG256_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct ilog256 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= 0) return 0; // TODO 29 | return std::ceil(std::log2(static_cast(x))/8); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::exp2(-63); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double hint_poles[] = { }; 39 | static constexpr double hint_interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 0; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array hint_canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_LOGARITHM_ILOG256_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/powers/icbrt.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/powers/icbrt.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_ICBRT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_ICBRT_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct icbrt 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= 0) return 0; // TODO 29 | return std::min(1.0 / std::cbrt(static_cast(x)), std::numeric_limits::max()); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::exp2(-63); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { 0 }; 39 | static constexpr double interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_ICBRT_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/powers/isqrt.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/powers/isqrt.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_ISQRT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_ISQRT_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct isqrt 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= 0) return 0; // TODO 29 | return std::min(1.0 / std::sqrt(static_cast(x)), std::numeric_limits::max()); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::exp2(-63); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { 0 }; 39 | static constexpr double interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_ISQRT_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/acot.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/acot.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ACOT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ACOT_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct acot 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x == 0) return 0; //TODO 29 | return std::atan(1/static_cast(x)); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { 0 }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ACOT_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/powers/iqtrt.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/powers/iqtrt.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_IQTRT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_IQTRT_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct iqtrt 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= 0) return 0; // TODO 29 | return std::min(1.0 / std::pow(static_cast(x), 0.25), std::numeric_limits::max()); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::exp2(-63); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { 0 }; 39 | static constexpr double interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_IQTRT_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/exponential/exp10.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/exponential/exp10.hpp 2 | /// @author Ryan Henry 3 | /// @brief gadgetized form of `std::exp10` 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP10_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP10_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct exp10 24 | { 25 | template 26 | T operator()(T x) { return std::min(std::pow(10, static_cast(x)), std::numeric_limits::max()); } 27 | }; 28 | 29 | template <> 30 | struct gadget_hints 31 | { 32 | static constexpr double min = std::numeric_limits::min(); 33 | static constexpr double max = std::numeric_limits::max(); 34 | static constexpr double * poles = nullptr; 35 | static constexpr double * interesting_points = nullptr; 36 | static constexpr unsigned degree = 3; 37 | static constexpr bool canonical_representation = false; 38 | static constexpr double * canonical_bounds = nullptr; 39 | static constexpr std::array * hint_canonical_polys = nullptr; 40 | }; 41 | 42 | } // namespace gadgets 43 | 44 | } // namespace grotto 45 | 46 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_EXPONENTIAL_EXP10_HPP__ 47 | -------------------------------------------------------------------------------- /include/grotto/gadgets/misc/entropy.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/misc/entropy.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_ENTROPY_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_ENTROPY_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct entropy 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x < 0) return 0; //TODO 29 | if (x == 0) return 0; 30 | return std::min(-x * std::log(x), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = 0; 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double hint_poles[] = { }; 40 | static constexpr double hint_interesting_points[] = { }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array hint_canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_MISC_ENTROPY_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/squared_relu.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/squared_relu.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SQUAREDRELU_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SQUAREDRELU_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct squared_relu 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x >= 0) return x*x; 29 | return 0; 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 2; 41 | static constexpr bool has_canonical_representation = true; 42 | static constexpr double canonical_bounds[] = { 0 }; 43 | static constexpr std::array canonical_polys[] = { {0}, {0,0,1} }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SQUAREDRELU_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/hardtanh.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/hardtanh.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDTANH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDTANH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct hardtanh 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= -1) return -1; 29 | if (x >= 1) return 1; 30 | return x; 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { }; 40 | static constexpr double interesting_points[] = { -1, 1 }; 41 | static constexpr unsigned degree = 1; 42 | static constexpr bool has_canonical_representation = true; 43 | static constexpr double canonical_bounds[] = { -1, 1 }; 44 | static constexpr std::array canonical_polys[] = { {-1}, {0,1}, {1} }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDTANH_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/one_minus_sigmoid.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/one_minus_relu.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ONE_MINUS_SIGMOID_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ONE_MINUS_SIGMOID_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "sigmoid.hpp" 16 | #include "grotto/gadget_hints.hpp" 17 | 18 | namespace grotto 19 | { 20 | 21 | namespace gadgets 22 | { 23 | 24 | struct one_minus_sigmoid 25 | { 26 | template 27 | T operator()(T x) 28 | { 29 | return 1-sigmoid{}(x); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ONE_MINUS_SIGMOID_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/acosh.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/acosh.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOSH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOSH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | // Returns the inverse hyperbolic cosine of a number. 24 | // The number must be greater than or equal to 1. 25 | struct acosh 26 | { 27 | template 28 | T operator()(T x) { 29 | if (x < 1) return -1; // TODO 30 | return std::acosh(static_cast(x)); } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = 1; 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACOSH_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/hardswish.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/hardswish.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSWISH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSWISH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct hardswish 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= -3) return 0; 29 | if (x >= 3) return x; 30 | return x*(x+3)/6; 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { }; 40 | static constexpr double interesting_points[] = { -3, 3 }; 41 | static constexpr unsigned degree = 2; 42 | static constexpr bool has_canonical_representation = true; 43 | static constexpr double canonical_bounds[] = { -3, 3 }; 44 | static constexpr std::array canonical_polys[] = { {0}, {0,0.5,1/6.0}, {0,1,0} }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSWISH_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/elish.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/elish.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELISH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELISH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "sigmoid.hpp" 16 | #include "grotto/gadget_hints.hpp" 17 | 18 | namespace grotto 19 | { 20 | 21 | namespace gadgets 22 | { 23 | 24 | struct elish 25 | { 26 | template 27 | T operator()(T x) 28 | { 29 | if (x < 0) return std::expm1(x)*sigmoid{}(x); 30 | if (x >= 0) return std::min(x*sigmoid{}(x), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { }; 40 | static constexpr double interesting_points[] = { }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELISH_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/hardsigmoid.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/hardsigmoid.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSIGMOID_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSIGMOID_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct hardsigmoid 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x <= -3) return 0; 29 | if (x >= 3) return 1; 30 | return (x+3)/6; 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { }; 40 | static constexpr double interesting_points[] = { -3, 3 }; 41 | static constexpr unsigned degree = 1; 42 | static constexpr bool has_canonical_representation = true; 43 | static constexpr double canonical_bounds[] = { -3, 3 }; 44 | static constexpr std::array canonical_polys[] = { {0}, {0.5,1/6.0}, {1} }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSIGMOID_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/relu6.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/relu6.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU6_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU6_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | static constexpr double relu6_default_clip = 6; 24 | template 25 | struct relu6 26 | { 27 | template 28 | T operator()(T x) 29 | { 30 | return std::min(std::max(0, x), clip); 31 | } 32 | }; 33 | 34 | template 35 | struct gadget_hints> 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { }; 40 | static constexpr double interesting_points[] = { 0, clip }; 41 | static constexpr unsigned degree = 1; 42 | static constexpr bool has_canonical_representation = true; 43 | static constexpr double canonical_bounds[] = { 0, clip }; 44 | static constexpr std::array canonical_polys[] = { 0, {0,1}, clip }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_RELU6_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/sinh.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/sinh.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SINH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SINH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct sinh 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x < 0) return std::max(std::sinh(static_cast(x)), std::numeric_limits::min()); 29 | if (x >= 0) return std::min(std::sinh(static_cast(x)), std::numeric_limits::max()); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_SINH_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/rad2deg.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/rad2deg.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRY_RAD2DEG_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRY_RAD2DEG_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct rad2deg 24 | { 25 | template 26 | T operator()(T x) { 27 | double X = std::fmod(static_cast(x), 2*M_PI); 28 | if (X < 0) X += 2*M_PI; 29 | return X * M_PI / 180; 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = -M_PI; 37 | static constexpr double max = M_PI; 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 1; 41 | static constexpr bool has_canonical_representation = true; 42 | static constexpr double canonical_bounds[] = { 0 }; 43 | static constexpr std::array canonical_polys[] = { { M_PI/180, 0 } }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRY_RAD2DEG_HPP__ 51 | 52 | 53 | 54 | // radians = degrees / 180 * M_PI 55 | 56 | // degrees = radians / M_PI * 180 -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/acos.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/acos.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ACOS_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ACOS_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct acos 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (std::abs(x) >= 1) return 0; //TODO 29 | if (x >= 0) return std::max(std::acos(static_cast(x)), std::numeric_limits::min()); 30 | if (x < 0) return std::min(std::acos(static_cast(x)), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = -1; 38 | static constexpr double max = 1; 39 | static constexpr double poles[] = { -1, 1 }; 40 | static constexpr double interesting_points[] = { }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ACOS_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/asin.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/asin.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ASIN_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ASIN_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct asin 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (std::abs(x) >= 1) return 0; //TODO 29 | if (x < 0) return std::max(std::asin(static_cast(x)), std::numeric_limits::min()); 30 | if (x >= 0) return std::min(std::asin(static_cast(x)), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = -1; 38 | static constexpr double max = 1; 39 | static constexpr double poles[] = { -1, 1 }; 40 | static constexpr double interesting_points[] = { }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ASIN_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/hardelish.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/hardelish.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDELISH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDELISH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct hardelish 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x < 0) return std::expm1(x)*std::max(0, std::min(1,(x+1)/2)); 29 | if (x >= 0) return std::min(x*std::max(0,std::min(1,(x+1)/2)), std::numeric_limits::max()); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { }; 40 | static constexpr unsigned degree = 3; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDELISH_HPP__ 51 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | # How to build tests 2 | 3 | To build the existing tests, simply run the following: 4 | 5 | ``` 6 | mkdir build && cd build 7 | cmake .. 8 | cmake --build . 9 | ``` 10 | 11 | # How to run tests 12 | 13 | Specific test executables will be placed in the `bin` subdirectory of the build directory. These can be run individually. 14 | 15 | Alternatively the `all_test` executable in the build directory can be run which automatically runs all test executables. 16 | 17 | # How to generate coverage 18 | 19 | First, when building the tests, make sure `COVERAGE=ON` as follows: 20 | 21 | ``` 22 | cmake -D COVERAGE=ON .. 23 | ``` 24 | 25 | Then after running all tests, run the following for `gcovr` coverage report: 26 | 27 | ``` 28 | mkdir coverage 29 | gcovr --root '../..' --filter '\.\./\.\./include/.*' --html-details 'coverage/index.html' . 30 | ``` 31 | 32 | # Building specific binaries 33 | 34 | To build a specific binary, for example `eval_point_test`, use the following: 35 | 36 | ``` 37 | cmake --build . --target eval_point_test 38 | ``` 39 | 40 | # Running specific tests 41 | 42 | First, to list available tests use the following (using `eval_point_test` as the example executable): 43 | 44 | ``` 45 | ./bin/eval_point_test --gtest_list_tests 46 | ``` 47 | 48 | Next, using the `--gtest_filter` option, specific tests can be run using pattern matching. `?` matches a single character, `*` matches any substring, `:` seperates two patterns, and `-` at the beginning of a pattern makes it a negative pattern. Following is an example to only run `Basic` tests and ensure `BasicPathMemoizer` tests are not run: 49 | 50 | ``` 51 | ./bin/eval_point_test --gtest_filter='*Basic*:-*BasicPathMemoizer*' 52 | ``` 53 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/tan.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/tan.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_TAN_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_TAN_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct tan 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (std::abs(x) >= M_PI/2) return 0; // TODO 29 | if (x < 0) return std::max(std::tan(static_cast(x)), std::numeric_limits::min()); 30 | if (x >- 0) return std::min(std::tan(static_cast(x)), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = -M_PI/2; 38 | static constexpr double max = M_PI/2; 39 | static constexpr double poles[] = { -M_PI/2, M_PI/2 }; 40 | static constexpr double interesting_points[] = { }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_TAN_HPP__ 52 | -------------------------------------------------------------------------------- /include/dpf/prg.hpp: -------------------------------------------------------------------------------- 1 | /// @file dpf/prg.hpp 2 | /// @brief 3 | /// @details 4 | /// @author Ryan Henry 5 | /// @copyright Copyright (c) 2019-2024 Ryan Henry and [others](@ref authors) 6 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 7 | /// see [LICENSE.md](@ref license) for details. 8 | 9 | #ifndef LIBDPF_INCLUDE_DPF_PRG_HPP__ 10 | #define LIBDPF_INCLUDE_DPF_PRG_HPP__ 11 | 12 | #include 13 | 14 | #include "dpf/prg_aes.hpp" 15 | #include "dpf/prg_dummy.hpp" 16 | 17 | namespace dpf 18 | { 19 | 20 | namespace prg 21 | { 22 | 23 | template 24 | struct counter_wrapper final 25 | { 26 | using block_type = typename PRG::block_type; 27 | 28 | static block_type eval(block_type seed, psnip_uint32_t pos) 29 | { 30 | count_.fetch_add(1, std::memory_order::memory_order_relaxed); 31 | return prg_.eval(seed, pos); 32 | } 33 | 34 | static auto eval01(block_type seed) 35 | { 36 | count_.fetch_add(2, std::memory_order::memory_order_relaxed); 37 | return prg_.eval01(seed); 38 | } 39 | 40 | static void eval(block_type seed, block_type * HEDLEY_RESTRICT output, 41 | psnip_uint32_t count, psnip_uint32_t pos = 0) 42 | { 43 | count_.fetch_add(count, std::memory_order::memory_order_relaxed); 44 | prg_.eval(seed, output, count, pos); 45 | } 46 | 47 | static std::size_t count() 48 | { 49 | return count_; 50 | } 51 | 52 | private: 53 | static const PRG prg_; 54 | inline static std::atomic_size_t count_{0}; 55 | }; // struct counter_wrapper 56 | 57 | } // namespace prg 58 | 59 | } // namespace dpf 60 | 61 | #endif // LIBDPF_INCLUDE_DPF_PRG_HPP__ 62 | -------------------------------------------------------------------------------- /include/grotto/gadgets/binary/countl_zero.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/binary/countl_zero.hpp 2 | /// @author Ryan Henry 3 | /// @brief gadgetized form of `std::countl_zero` 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ZERO_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ZERO_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct countl_zero 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x == 0) return std::numeric_limits::bits(); 29 | return psnip_builtin_clz64(static_cast(static_cast(x))); 30 | } 31 | }; 32 | 33 | template <> 34 | struct gadget_hints 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr double poles[] = { }; 39 | static constexpr double interesting_points[] = { 0 }; 40 | static constexpr unsigned degree = 0; 41 | static constexpr bool has_canonical_representation = false; 42 | static constexpr double canonical_bounds[] = { }; 43 | static constexpr std::array hint_canonical_polys[] = { }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_BINARY_COUNTL_ZERO_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/elementary/clip.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/elemwntary/clip.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_CLIP_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_CLIP_HPP__ 10 | 11 | #include 12 | #include 13 | 14 | #include "grotto/gadget_hints.hpp" 15 | 16 | namespace grotto 17 | { 18 | 19 | namespace gadgets 20 | { 21 | 22 | template 24 | struct clip 25 | { 26 | static_assert(lower <= upper); 27 | template 28 | T operator()(T x) { return std::max(std::min(x, upper), lower); } 29 | }; 30 | 31 | 32 | template 34 | struct gadget_hints> 35 | { 36 | static constexpr double min = std::numeric_limits::min(); 37 | static constexpr double max = std::numeric_limits::max(); 38 | static constexpr unsigned degree = 1; 39 | static constexpr double poles[] = { }; 40 | static constexpr bool has_canonical_representation = true; 41 | static constexpr double interesting_points[] = { lower, upper }; 42 | static constexpr double canonical_bounds[] = { lower, upper }; 43 | static constexpr std::array canonical_polys[] = { { lower, 0 }, { 0, 1 }, { upper, 0 } }; 44 | }; 45 | 46 | } // namespace gadgets 47 | 48 | } // namespace grotto 49 | 50 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ELEMENTARY_CLIP_HPP__ 51 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/csch.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/csch.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_CSCH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_CSCH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct csch 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x == 0) return 0; 29 | if (x < 0) return std::max(1/std::sinh(static_cast(x)), std::numeric_limits::min()); 30 | if (x > 0) return std::min(1/std::sinh(static_cast(x)), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { 0 }; 40 | static constexpr double interesting_points[] = { 0 }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_CSCH_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/elu.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/elu.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELU_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELU_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | static constexpr double elu_default_alpha = 1; 24 | template 25 | struct elu 26 | { 27 | template 28 | T operator()(T x) 29 | { 30 | if (x <= 0) return alpha * std::expm1(x); 31 | if (x > 0) return std::min(x, std::numeric_limits::max()); 32 | } 33 | }; 34 | 35 | template 36 | struct gadget_hints> 37 | { 38 | static constexpr double min = std::numeric_limits::min(); 39 | static constexpr double max = std::numeric_limits::max(); 40 | static constexpr double poles[] = { }; 41 | static constexpr double interesting_points[] = { }; 42 | static constexpr unsigned degree = 3; 43 | static constexpr bool has_canonical_representation = false; 44 | static constexpr double canonical_bounds[] = { }; 45 | static constexpr std::array canonical_polys[] = { }; 46 | }; 47 | 48 | } // namespace gadgets 49 | 50 | } // namespace grotto 51 | 52 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_ELU_HPP__ 53 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/softminus.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/softminus.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTMINUS_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTMINUS_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "softplus.hpp" 16 | #include "grotto/gadget_hints.hpp" 17 | 18 | namespace grotto 19 | { 20 | 21 | namespace gadgets 22 | { 23 | 24 | static constexpr double softminus_default_beta = 1; 25 | template 26 | struct softminus 27 | { 28 | template 29 | T operator()(T x) 30 | { 31 | return beta*x-softplus{}(x); 32 | } 33 | }; 34 | 35 | template 36 | struct gadget_hints> 37 | { 38 | static constexpr double min = std::numeric_limits::min(); 39 | static constexpr double max = std::numeric_limits::max(); 40 | static constexpr double poles[] = { }; 41 | static constexpr double interesting_points[] = { 20 }; 42 | static constexpr unsigned degree = 3; 43 | static constexpr bool has_canonical_representation = false; 44 | static constexpr double canonical_bounds[] = { }; 45 | static constexpr std::array canonical_polys[] = { }; 46 | }; 47 | 48 | } // namespace gadgets 49 | 50 | } // namespace grotto 51 | 52 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTMINUS_HPP__ 53 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/celu.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/celu.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_CELU_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_CELU_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | static constexpr double celu_default_alpha = 1; 24 | template 25 | struct celu 26 | { 27 | template 28 | T operator()(T x) 29 | { 30 | return std::min(std::max(0, x) + std::min(0, alpha * std::expm1(x / alpha)), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template 35 | struct gadget_hints> 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { }; 40 | static constexpr double interesting_points[] = { }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_CELU_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/sec.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/sec.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_SEC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_SEC_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct sec 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (std::abs(x) == M_PI/2) return 0; // TODO 29 | if (std::abs(x) < M_PI/2) return std::min(1/std::cos(static_cast(x)), std::numeric_limits::max()); 30 | if (std::abs(x) > M_PI/2) return std::max(1/std::cos(static_cast(x)), std::numeric_limits::min()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = -M_PI; 38 | static constexpr double max = M_PI; 39 | static constexpr double poles[] = { -M_PI/2, M_PI/2 }; 40 | static constexpr double interesting_points[] = { }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_SEC_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/softplus.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/softplus.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTPLUS_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTPLUS_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | static constexpr double softplus_default_beta = 1; 24 | template 25 | struct softplus 26 | { 27 | template 28 | T operator()(T x) 29 | { 30 | if (x > 20) return x*beta; 31 | return (std::log1p(std::exp(beta*x)))/beta; 32 | } 33 | }; 34 | 35 | template 36 | struct gadget_hints> 37 | { 38 | static constexpr double min = std::numeric_limits::min(); 39 | static constexpr double max = std::numeric_limits::max(); 40 | static constexpr double poles[] = { }; 41 | static constexpr double interesting_points[] = { 20 }; 42 | static constexpr unsigned degree = 3; 43 | static constexpr bool has_canonical_representation = false; 44 | static constexpr double canonical_bounds[] = { }; 45 | static constexpr std::array canonical_polys[] = { }; 46 | }; 47 | 48 | } // namespace gadgets 49 | 50 | } // namespace grotto 51 | 52 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_SOFTPLUS_HPP__ 53 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/acsch.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/acsch.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACSCH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACSCH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct acsch 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x == 0) return 0; // TODO 29 | if (x < 0) return std::max(std::asinh(1/static_cast(x)), std::numeric_limits::min()); 30 | if (x > 0) return std::min(std::asinh(1/static_cast(x)), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { 0 }; 40 | static constexpr double interesting_points[] = { }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_ACSCH_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/powers/reciprocal.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/powers/reciprocal.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_RECIPROCAL_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_RECIPROCAL_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct reciprocal 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x == 0) return 0; // TODO 29 | if (x < 0) return std::max(1.0 / static_cast(x), std::numeric_limits::min()); 30 | if (x > 0) return std::min(1.0 / static_cast(x), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { 0 }; 40 | static constexpr double interesting_points[] = { 0 }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_POWERS_RECIPROCAL_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/csc.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/csc.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_CSC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_CSC_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct csc 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (std::abs(x) == M_PI/2) return 0; // TODO 29 | if (x == 0) return 0; // TODO 30 | if (x < 0) return std::max(1/std::sin(static_cast(x)), std::numeric_limits::min()); 31 | if (x > 0) return std::min(1/std::sin(static_cast(x)), std::numeric_limits::max()); 32 | } 33 | }; 34 | 35 | template <> 36 | struct gadget_hints 37 | { 38 | static constexpr double min = -M_PI; 39 | static constexpr double max = M_PI; 40 | static constexpr double poles[] = { -M_PI, 0, M_PI }; 41 | static constexpr double interesting_points[] = { }; 42 | static constexpr unsigned degree = 3; 43 | static constexpr bool has_canonical_representation = false; 44 | static constexpr double canonical_bounds[] = { }; 45 | static constexpr std::array canonical_polys[] = { }; 46 | }; 47 | 48 | } // namespace gadgets 49 | 50 | } // namespace grotto 51 | 52 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_CSC_HPP__ 53 | -------------------------------------------------------------------------------- /thirdparty/bsd/nlist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2009 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_NLIST_H 28 | #define LIBBSD_NLIST_H 29 | 30 | #include 31 | #include 32 | 33 | __BEGIN_DECLS 34 | extern int nlist(const char *filename, struct nlist *list); 35 | __END_DECLS 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/acsc.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/acsc.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ACSC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ACSC_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct acsc 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (std::abs(x) <= 1) return 0; //TODO 29 | if (x>0) return std::min(std::asin(1/static_cast(x)), std::numeric_limits::max()); 30 | if (x<0) return std::max(std::asin(1/static_cast(x)), std::numeric_limits::min()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { -1, 1 }; 40 | static constexpr double interesting_points[] = { -1, 1 }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ACSC_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/asec.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/asec.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ASEC_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ASEC_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct asec 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (std::abs(x) <= 1) return 0; //TODO 29 | if (x>0) return std::max(std::acos(1/static_cast(x)), std::numeric_limits::min()); 30 | if (x<0) return std::min(std::acos(1/static_cast(x)), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { -1, 1 }; 40 | static constexpr double interesting_points[] = { -1, 1 }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_ASEC_HPP__ 52 | -------------------------------------------------------------------------------- /thirdparty/bsd/sys/poll.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_SYS_POLL_H 28 | #define LIBBSD_SYS_POLL_H 29 | 30 | #ifdef LIBBSD_OVERLAY 31 | #include_next 32 | #else 33 | #include 34 | #endif 35 | 36 | #ifndef INFTIM 37 | #define INFTIM (-1) 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/grotto/gadgets/hyperbolic/coth.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/hyperbolic/coth.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COTH_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COTH_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct coth 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x == 0) return 0; 29 | if (x < 0) return std::max(std::cosh(static_cast(x))/std::sinh(static_cast(x)), std::numeric_limits::min()); 30 | if (x > 0) return std::min(std::cosh(static_cast(x))/std::sinh(static_cast(x)), std::numeric_limits::max()); 31 | } 32 | }; 33 | 34 | template <> 35 | struct gadget_hints 36 | { 37 | static constexpr double min = std::numeric_limits::min(); 38 | static constexpr double max = std::numeric_limits::max(); 39 | static constexpr double poles[] = { 0 }; 40 | static constexpr double interesting_points[] = { 0 }; 41 | static constexpr unsigned degree = 3; 42 | static constexpr bool has_canonical_representation = false; 43 | static constexpr double canonical_bounds[] = { }; 44 | static constexpr std::array canonical_polys[] = { }; 45 | }; 46 | 47 | } // namespace gadgets 48 | 49 | } // namespace grotto 50 | 51 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_HYPERBOLIC_COTH_HPP__ 52 | -------------------------------------------------------------------------------- /include/grotto/gadgets/activations/hardshrink.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/activations/hardshrink.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSHRINK_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSHRINK_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "grotto/gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | static constexpr double hardshrink_default_lambda = 0.5; 24 | template 25 | struct hardshrink 26 | { 27 | template 28 | T operator()(T x) 29 | { 30 | if (std::abs(x) <= lambda) return 0; 31 | return x; 32 | } 33 | }; 34 | 35 | template 36 | struct gadget_hints> 37 | { 38 | static constexpr double min = std::numeric_limits::min(); 39 | static constexpr double max = std::numeric_limits::max(); 40 | static constexpr double poles[] = { }; 41 | static constexpr double interesting_points[] = { -lambda, lambda }; 42 | static constexpr unsigned degree = 1; 43 | static constexpr bool has_canonical_representation = true; 44 | static constexpr double canonical_bounds[] = { -lambda, lambda }; 45 | static constexpr std::array canonical_polys[] = { {0,1}, {0}, {0,1} }; 46 | }; 47 | 48 | } // namespace gadgets 49 | 50 | } // namespace grotto 51 | 52 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_ACTIVATIONS_HARDSHRINK_HPP__ 53 | -------------------------------------------------------------------------------- /include/grotto/gadgets/trigonometric/cot.hpp: -------------------------------------------------------------------------------- 1 | /// @file grotto/gadgets/trigonometric/cot.hpp 2 | /// @author Ryan Henry 3 | /// @brief 4 | /// @copyright Copyright (c) 2019-2023 Ryan Henry and others 5 | /// @license Released under a GNU General Public v2.0 (GPLv2) license; 6 | /// see [LICENSE.md](@ref GPLv2) for details. 7 | 8 | #ifndef LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_COT_HPP__ 9 | #define LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_COT_HPP__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../gadget_hints.hpp" 16 | 17 | namespace grotto 18 | { 19 | 20 | namespace gadgets 21 | { 22 | 23 | struct csc 24 | { 25 | template 26 | T operator()(T x) 27 | { 28 | if (x == M_PI) return 0; // TODO 29 | if (x == 0) return 0; // TODO 30 | if (x < M_PI/2) return std::min(std::cos(static_cast(x))/std::sin(static_cast(x)), std::numeric_limits::max()); 31 | if (x <= M_PI/2) return std::max(std::cos(static_cast(x))/std::sin(static_cast(x)), std::numeric_limits::min()); 32 | } 33 | }; 34 | 35 | template <> 36 | struct gadget_hints 37 | { 38 | static constexpr double min = 0; 39 | static constexpr double max = M_PI; 40 | static constexpr double poles[] = { 0, M_PI }; 41 | static constexpr double interesting_points[] = { }; 42 | static constexpr unsigned degree = 3; 43 | static constexpr bool has_canonical_representation = false; 44 | static constexpr double canonical_bounds[] = { }; 45 | static constexpr std::array canonical_polys[] = { }; 46 | }; 47 | 48 | } // namespace gadgets 49 | 50 | } // namespace grotto 51 | 52 | #endif // LIBDPF_INCLUDE_GROTTO_GADGETS_TRIGONOMETRIC_COT_HPP__ 53 | --------------------------------------------------------------------------------