From 64441adba94992ffe68e453df08b07e593216a98 Mon Sep 17 00:00:00 2001 From: Joel Falcou Date: Tue, 5 Sep 2023 17:31:29 +0200 Subject: [PATCH] Fix #1662 - Implements eve::as_element --- include/eve/as.hpp | 2 +- include/eve/as_element.hpp | 36 +++++++++++++++++++ .../eve/module/algo/algo/transform_reduce.hpp | 3 +- .../module/bessel/detail/kernel_bessel_j.hpp | 3 +- .../module/bessel/detail/kernel_bessel_k.hpp | 3 +- .../module/bessel/detail/kernel_bessel_y.hpp | 3 +- .../bessel/regular/impl/cyl_bessel_jn.hpp | 3 +- .../bessel/regular/impl/cyl_bessel_kn.hpp | 3 +- .../bessel/regular/impl/cyl_bessel_yn.hpp | 3 +- .../module/combinatorial/regular/impl/lcm.hpp | 5 +-- .../eve/module/core/regular/impl/binarize.hpp | 7 ++-- .../module/core/regular/impl/binarize_not.hpp | 3 +- .../eve/module/core/regular/impl/convert.hpp | 3 +- .../polynomial/regular/impl/legendre.hpp | 4 +-- .../polynomial/regular/impl/tchebytchev.hpp | 3 +- 15 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 include/eve/as_element.hpp diff --git a/include/eve/as.hpp b/include/eve/as.hpp index 99a383fbdd..2c9e447494 100644 --- a/include/eve/as.hpp +++ b/include/eve/as.hpp @@ -18,7 +18,7 @@ namespace eve //! **Required header:** `#include ` //! //! Wraps type into a constexpr, trivially constructible empty class to optimize passing type - //! parameters via object instead of via template parameters + //! parameters via object instead of via template parameters. //! //! @tparam T Type to wrap //! diff --git a/include/eve/as_element.hpp b/include/eve/as_element.hpp new file mode 100644 index 0000000000..830448dc61 --- /dev/null +++ b/include/eve/as_element.hpp @@ -0,0 +1,36 @@ +//================================================================================================== +/* + EVE - Expressive Vector Engine + Copyright : EVE Project Contributors + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#include +#include + +namespace eve +{ + //================================================================================================ + //! @addtogroup traits + //! @{ + //! @struct as_element + //! @brief Lightweight type-wrapper over element type + //! + //! **Required header:** `#include ` + //! + //! eve::as_element is a short-cut for eve::as> designed to work with + //! automatic type deduction. + //! + //! @tparam T Type to wrap + //! + //! @} + //================================================================================================ + template + struct as_element : as> + { + constexpr as_element() noexcept {} + constexpr as_element(T const&) noexcept {} + }; +} diff --git a/include/eve/module/algo/algo/transform_reduce.hpp b/include/eve/module/algo/algo/transform_reduce.hpp index 233a588dd3..5d6a62e9f1 100644 --- a/include/eve/module/algo/algo/transform_reduce.hpp +++ b/include/eve/module/algo/algo/transform_reduce.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -49,7 +50,7 @@ template struct transform_reduce_ : TraitsSupport sums[idx()] = if_else(ignore, map_op(loaded, sums[idx()]), sums[idx()]); } else { auto mapped = map_op(loaded); - auto cvt = eve::convert(mapped, eve::as> {}); + auto cvt = eve::convert(mapped, eve::as_element{}); sums[idx()] = add_op(sums[idx()], if_else(ignore, cvt, zero)); } return false; diff --git a/include/eve/module/bessel/detail/kernel_bessel_j.hpp b/include/eve/module/bessel/detail/kernel_bessel_j.hpp index b149e63b5e..b1832c5b2d 100644 --- a/include/eve/module/bessel/detail/kernel_bessel_j.hpp +++ b/include/eve/module/bessel/detail/kernel_bessel_j.hpp @@ -12,6 +12,7 @@ #include #include #include +#include ///////////////////////////////////////////////////////////////////////////////// // These routines are detail of the computation of cylindrical bessel functions @@ -63,7 +64,7 @@ EVE_FORCEINLINE auto kernel_bessel_j_int_forward(I nn, T x, T j0, T j1) noexcept { if constexpr( simd_value ) - return kernel_bessel_j_int_forward(convert(nn, as>()), x, j0, j1); + return kernel_bessel_j_int_forward(convert(nn, as_element(j0)), x, j0, j1); else return kernel_bessel_j_int_forward(T(nn), x, j0, j1); } diff --git a/include/eve/module/bessel/detail/kernel_bessel_k.hpp b/include/eve/module/bessel/detail/kernel_bessel_k.hpp index b4e5826a89..26f36ae2ef 100644 --- a/include/eve/module/bessel/detail/kernel_bessel_k.hpp +++ b/include/eve/module/bessel/detail/kernel_bessel_k.hpp @@ -12,6 +12,7 @@ #include #include #include +#include ///////////////////////////////////////////////////////////////////////////////// // These routines are detail of the computation of modifiesd cylindrical bessel @@ -30,7 +31,7 @@ kernel_bessel_k_int_forward(I nn, T x, T k0, T k1) noexcept if constexpr(integral_value) { if constexpr( simd_value ) - return kernel_bessel_k_int_forward(convert(nn, as>()), x, k0, k1); + return kernel_bessel_k_int_forward(convert(nn, as_element(k0)), x, k0, k1); else return kernel_bessel_k_int_forward(T(nn), x, k0, k1); } diff --git a/include/eve/module/bessel/detail/kernel_bessel_y.hpp b/include/eve/module/bessel/detail/kernel_bessel_y.hpp index 6bd4bc2f07..5b6996bd6e 100644 --- a/include/eve/module/bessel/detail/kernel_bessel_y.hpp +++ b/include/eve/module/bessel/detail/kernel_bessel_y.hpp @@ -16,6 +16,7 @@ #include #include #include +#include ///////////////////////////////////////////////////////////////////////////////// // These routines are detail of the computation of cylindrical bessel functions @@ -73,7 +74,7 @@ EVE_FORCEINLINE auto kernel_bessel_y_int_forward(I nn, T x, T y0, T y1) noexcept { if constexpr( simd_value ) - return kernel_bessel_y_int_forward(convert(nn, as>()), x, y0, y1); + return kernel_bessel_y_int_forward(convert(nn, as_element(y0)), x, y0, y1); else return kernel_bessel_y_int_forward(T(nn), x, y0, y1); } diff --git a/include/eve/module/bessel/regular/impl/cyl_bessel_jn.hpp b/include/eve/module/bessel/regular/impl/cyl_bessel_jn.hpp index 23c8178450..dbb08b7689 100644 --- a/include/eve/module/bessel/regular/impl/cyl_bessel_jn.hpp +++ b/include/eve/module/bessel/regular/impl/cyl_bessel_jn.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace eve::detail { @@ -75,7 +76,7 @@ cyl_bessel_jn_(EVE_SUPPORTS(cpu_), I nu, T x) noexcept { if constexpr( has_native_abi_v ) { - auto n = convert(nu, as>()); + auto n = convert(nu, as_element(x)); return kernel_bessel_j_int(n, x); } else return apply_over(cyl_bessel_jn, nu, x); diff --git a/include/eve/module/bessel/regular/impl/cyl_bessel_kn.hpp b/include/eve/module/bessel/regular/impl/cyl_bessel_kn.hpp index 39f7e17373..607ba518aa 100644 --- a/include/eve/module/bessel/regular/impl/cyl_bessel_kn.hpp +++ b/include/eve/module/bessel/regular/impl/cyl_bessel_kn.hpp @@ -8,6 +8,7 @@ #pragma once #include +#include namespace eve::detail { @@ -78,7 +79,7 @@ cyl_bessel_kn_(EVE_SUPPORTS(cpu_), I nu, T x) noexcept { if constexpr( has_native_abi_v ) { - auto n = convert(nu, as>()); + auto n = convert(nu, as_element(x)); return kernel_bessel_k_int(n, x); } else return apply_over(cyl_bessel_kn, nu, x); diff --git a/include/eve/module/bessel/regular/impl/cyl_bessel_yn.hpp b/include/eve/module/bessel/regular/impl/cyl_bessel_yn.hpp index 54c15d4164..965287fbf4 100644 --- a/include/eve/module/bessel/regular/impl/cyl_bessel_yn.hpp +++ b/include/eve/module/bessel/regular/impl/cyl_bessel_yn.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace eve::detail { @@ -78,7 +79,7 @@ cyl_bessel_yn_(EVE_SUPPORTS(cpu_), I nu, T x) noexcept { if constexpr( has_native_abi_v ) { - auto n = convert(nu, as>()); + auto n = convert(nu, as_element(x)); return kernel_bessel_y_int(n, x); } else return apply_over(cyl_bessel_yn, nu, x); diff --git a/include/eve/module/combinatorial/regular/impl/lcm.hpp b/include/eve/module/combinatorial/regular/impl/lcm.hpp index 0d557a719e..a9981d5b67 100644 --- a/include/eve/module/combinatorial/regular/impl/lcm.hpp +++ b/include/eve/module/combinatorial/regular/impl/lcm.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace eve::detail { @@ -55,12 +56,12 @@ lcm_(EVE_SUPPORTS(cpu_), upgrade_converter const&, T a, T b) noexcept if constexpr( std::is_same_v ) { auto r = lcm(to_(a), to_(b)); - return convert(r, as>()); + return convert(r, as_element()); } else // double element { auto r = lcm(to_(a), to_(b)); - return convert(r, as>()); + return convert(r, as_element()); } } } diff --git a/include/eve/module/core/regular/impl/binarize.hpp b/include/eve/module/core/regular/impl/binarize.hpp index 0dbaef0295..87c4bed2b0 100644 --- a/include/eve/module/core/regular/impl/binarize.hpp +++ b/include/eve/module/core/regular/impl/binarize.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -25,7 +26,7 @@ EVE_FORCEINLINE auto binarize_(EVE_SUPPORTS(cpu_), logical const& cond) noexcept { if constexpr( has_native_abi_v ) - return bit_and(one(eve::as()), cond.bits()); + return bit_and(one(eve::as()), cond.bits()); else return apply_over(binarize, cond); } @@ -35,7 +36,7 @@ EVE_FORCEINLINE auto binarize_(EVE_SUPPORTS(cpu_), logical const& cond, U const& val) noexcept { if constexpr( has_native_abi_v ) - return if_else(cond, val, zero); + return if_else(cond, val, zero); else return apply_over(binarize, cond, val); } @@ -70,6 +71,6 @@ binarize_(EVE_SUPPORTS(cpu_), logical const& cond, callable_mone_ const&) noe if constexpr( integral_value ) return cond.mask(); else - return eve::binarize(cond, mone(eve::as>())); + return eve::binarize(cond, mone(eve::as_element())); } } diff --git a/include/eve/module/core/regular/impl/binarize_not.hpp b/include/eve/module/core/regular/impl/binarize_not.hpp index 0a07c4070f..2ffedcd170 100644 --- a/include/eve/module/core/regular/impl/binarize_not.hpp +++ b/include/eve/module/core/regular/impl/binarize_not.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -64,7 +65,7 @@ binarize_not_(EVE_SUPPORTS(cpu_), logical const& cond, callable_mone_ const&) if constexpr( integral_value ) return bit_not(cond.mask()); else - return eve::binarize_not(cond, mone(eve::as>())); + return eve::binarize_not(cond, mone(eve::as_element())); } } diff --git a/include/eve/module/core/regular/impl/convert.hpp b/include/eve/module/core/regular/impl/convert.hpp index a7f6a36ebd..69c5369538 100644 --- a/include/eve/module/core/regular/impl/convert.hpp +++ b/include/eve/module/core/regular/impl/convert.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -50,7 +51,7 @@ struct convert_lambda template EVE_FORCEINLINE constexpr void operator()(T const& in, M *res_m) const noexcept { - *res_m = eve::convert(in, eve::as> {}); + *res_m = eve::convert(in, eve::as_element{}); } }; diff --git a/include/eve/module/polynomial/regular/impl/legendre.hpp b/include/eve/module/polynomial/regular/impl/legendre.hpp index 87d19c22b4..3b94eda6a9 100644 --- a/include/eve/module/polynomial/regular/impl/legendre.hpp +++ b/include/eve/module/polynomial/regular/impl/legendre.hpp @@ -263,8 +263,8 @@ namespace detail EVE_ASSERT(eve::all(m >= 0 && is_flint(m)), "sph(legendre)(l, m, theta): m is negative or not integral"); EVE_ASSERT(eve::all(m <= l), "sph(legendre)(l, m, theta): some m are greater than l"); - auto ll = convert(l, as>()); - auto mm = convert(m, as>()); + auto ll = convert(l, as_element(theta)); + auto mm = convert(m, as_element(theta)); using r_t = eve::common_value_t; r_t p0(theta); p0 = eve::legendre(l, m, cos(p0)); diff --git a/include/eve/module/polynomial/regular/impl/tchebytchev.hpp b/include/eve/module/polynomial/regular/impl/tchebytchev.hpp index bb05c3627a..8b509e40da 100644 --- a/include/eve/module/polynomial/regular/impl/tchebytchev.hpp +++ b/include/eve/module/polynomial/regular/impl/tchebytchev.hpp @@ -9,6 +9,7 @@ #include #include +#include namespace eve::detail { @@ -118,7 +119,7 @@ EVE_FORCEINLINE auto tchebytchev_(EVE_SUPPORTS(cpu_), kind_2_type const&, I n, T x) noexcept { EVE_ASSERT(eve::all(is_gez(n)), "some elements of n are not positive"); - auto nn = inc(convert(n, as>())); + auto nn = inc(convert(n, as_element(x))); auto z = eve::abs(x); auto acx = acos(x);