Skip to content

Commit

Permalink
Fix #1662 - Implements eve::as_element
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcou authored Sep 5, 2023
1 parent c8686c4 commit 64441ad
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/eve/as.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace eve
//! **Required header:** `#include <eve/as.hpp>`
//!
//! 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
//!
Expand Down
36 changes: 36 additions & 0 deletions include/eve/as_element.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//==================================================================================================
/*
EVE - Expressive Vector Engine
Copyright : EVE Project Contributors
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once

#include <eve/as.hpp>
#include <eve/traits/element_type.hpp>

namespace eve
{
//================================================================================================
//! @addtogroup traits
//! @{
//! @struct as_element
//! @brief Lightweight type-wrapper over element type
//!
//! **Required header:** `#include <eve/as.hpp>`
//!
//! eve::as_element<T> is a short-cut for eve::as<eve::element_type_t<T>> designed to work with
//! automatic type deduction.
//!
//! @tparam T Type to wrap
//!
//! @}
//================================================================================================
template<typename T>
struct as_element : as<element_type_t<T>>
{
constexpr as_element() noexcept {}
constexpr as_element(T const&) noexcept {}
};
}
3 changes: 2 additions & 1 deletion include/eve/module/algo/algo/transform_reduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <eve/module/algo/algo/views/convert.hpp>
#include <eve/module/core.hpp>
#include <eve/traits.hpp>
#include <eve/as_element.hpp>

#include <utility>

Expand Down Expand Up @@ -49,7 +50,7 @@ template<typename TraitsSupport> 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<element_type_t<SumWide>> {});
auto cvt = eve::convert(mapped, eve::as_element<SumWide>{});
sums[idx()] = add_op(sums[idx()], if_else(ignore, cvt, zero));
}
return false;
Expand Down
3 changes: 2 additions & 1 deletion include/eve/module/bessel/detail/kernel_bessel_j.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <eve/module/bessel/detail/kernel_bessel_jy_large.hpp>
#include <eve/module/core.hpp>
#include <eve/module/math.hpp>
#include <eve/as_element.hpp>

/////////////////////////////////////////////////////////////////////////////////
// These routines are detail of the computation of cylindrical bessel functions
Expand Down Expand Up @@ -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<I> )
return kernel_bessel_j_int_forward(convert(nn, as<element_type_t<T>>()), 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);
}

Expand Down
3 changes: 2 additions & 1 deletion include/eve/module/bessel/detail/kernel_bessel_k.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <eve/module/bessel/regular/cyl_bessel_k1.hpp>
#include <eve/module/core.hpp>
#include <eve/module/math.hpp>
#include <eve/as_element.hpp>

/////////////////////////////////////////////////////////////////////////////////
// These routines are detail of the computation of modifiesd cylindrical bessel
Expand All @@ -30,7 +31,7 @@ kernel_bessel_k_int_forward(I nn, T x, T k0, T k1) noexcept
if constexpr(integral_value<I>)
{
if constexpr( simd_value<I> )
return kernel_bessel_k_int_forward(convert(nn, as<element_type_t<T>>()), 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);
}
Expand Down
3 changes: 2 additions & 1 deletion include/eve/module/bessel/detail/kernel_bessel_y.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <eve/module/core.hpp>
#include <eve/module/math.hpp>
#include <eve/module/special.hpp>
#include <eve/as_element.hpp>

/////////////////////////////////////////////////////////////////////////////////
// These routines are detail of the computation of cylindrical bessel functions
Expand Down Expand Up @@ -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<I> )
return kernel_bessel_y_int_forward(convert(nn, as<element_type_t<T>>()), 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);
}

Expand Down
3 changes: 2 additions & 1 deletion include/eve/module/bessel/regular/impl/cyl_bessel_jn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <eve/module/bessel/detail/kernel_bessel_j.hpp>
#include <eve/module/core.hpp>
#include <eve/module/math.hpp>
#include <eve/as_element.hpp>

namespace eve::detail
{
Expand Down Expand Up @@ -75,7 +76,7 @@ cyl_bessel_jn_(EVE_SUPPORTS(cpu_), I nu, T x) noexcept
{
if constexpr( has_native_abi_v<T> )
{
auto n = convert(nu, as<element_type_t<T>>());
auto n = convert(nu, as_element(x));
return kernel_bessel_j_int(n, x);
}
else return apply_over(cyl_bessel_jn, nu, x);
Expand Down
3 changes: 2 additions & 1 deletion include/eve/module/bessel/regular/impl/cyl_bessel_kn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <eve/module/bessel/detail/kernel_bessel_k.hpp>
#include <eve/as_element.hpp>

namespace eve::detail
{
Expand Down Expand Up @@ -78,7 +79,7 @@ cyl_bessel_kn_(EVE_SUPPORTS(cpu_), I nu, T x) noexcept
{
if constexpr( has_native_abi_v<T> )
{
auto n = convert(nu, as<element_type_t<T>>());
auto n = convert(nu, as_element(x));
return kernel_bessel_k_int(n, x);
}
else return apply_over(cyl_bessel_kn, nu, x);
Expand Down
3 changes: 2 additions & 1 deletion include/eve/module/bessel/regular/impl/cyl_bessel_yn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <eve/module/bessel/detail/kernel_bessel_y.hpp>
#include <eve/module/core.hpp>
#include <eve/module/math.hpp>
#include <eve/as_element.hpp>

namespace eve::detail
{
Expand Down Expand Up @@ -78,7 +79,7 @@ cyl_bessel_yn_(EVE_SUPPORTS(cpu_), I nu, T x) noexcept
{
if constexpr( has_native_abi_v<T> )
{
auto n = convert(nu, as<element_type_t<T>>());
auto n = convert(nu, as_element(x));
return kernel_bessel_y_int(n, x);
}
else return apply_over(cyl_bessel_yn, nu, x);
Expand Down
5 changes: 3 additions & 2 deletions include/eve/module/combinatorial/regular/impl/lcm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <eve/module/combinatorial/regular/gcd.hpp>
#include <eve/module/core.hpp>
#include <eve/traits/common_value.hpp>
#include <eve/as_element.hpp>

namespace eve::detail
{
Expand Down Expand Up @@ -55,12 +56,12 @@ lcm_(EVE_SUPPORTS(cpu_), upgrade_converter const&, T a, T b) noexcept
if constexpr( std::is_same_v<efup_t, float> )
{
auto r = lcm(to_<fup_t>(a), to_<fup_t>(b));
return convert(r, as<element_type_t<up_t>>());
return convert(r, as_element<up_t>());
}
else // double element
{
auto r = lcm(to_<fup_t>(a), to_<fup_t>(b));
return convert(r, as<element_type_t<up_t>>());
return convert(r, as_element<up_t>());
}
}
}
7 changes: 4 additions & 3 deletions include/eve/module/core/regular/impl/binarize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <eve/module/core/constant/one.hpp>
#include <eve/module/core/regular/bit_and.hpp>
#include <eve/module/core/regular/if_else.hpp>
#include <eve/as_element.hpp>

#include <type_traits>

Expand All @@ -25,7 +26,7 @@ EVE_FORCEINLINE auto
binarize_(EVE_SUPPORTS(cpu_), logical<T> const& cond) noexcept
{
if constexpr( has_native_abi_v<T> )
return bit_and(one(eve::as<T>()), cond.bits());
return bit_and(one(eve::as<T>()), cond.bits());
else
return apply_over(binarize, cond);
}
Expand All @@ -35,7 +36,7 @@ EVE_FORCEINLINE auto
binarize_(EVE_SUPPORTS(cpu_), logical<T> const& cond, U const& val) noexcept
{
if constexpr( has_native_abi_v<T> )
return if_else(cond, val, zero);
return if_else(cond, val, zero);
else
return apply_over(binarize, cond, val);
}
Expand Down Expand Up @@ -70,6 +71,6 @@ binarize_(EVE_SUPPORTS(cpu_), logical<T> const& cond, callable_mone_ const&) noe
if constexpr( integral_value<T> )
return cond.mask();
else
return eve::binarize(cond, mone(eve::as<element_type_t<T>>()));
return eve::binarize(cond, mone(eve::as_element<T>()));
}
}
3 changes: 2 additions & 1 deletion include/eve/module/core/regular/impl/binarize_not.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <eve/module/core/regular/bit_andnot.hpp>
#include <eve/module/core/regular/bit_not.hpp>
#include <eve/module/core/regular/if_else.hpp>
#include <eve/as_element.hpp>

#include <type_traits>

Expand Down Expand Up @@ -64,7 +65,7 @@ binarize_not_(EVE_SUPPORTS(cpu_), logical<T> const& cond, callable_mone_ const&)
if constexpr( integral_value<T> )
return bit_not(cond.mask());
else
return eve::binarize_not(cond, mone(eve::as<element_type_t<T>>()));
return eve::binarize_not(cond, mone(eve::as_element<T>()));
}

}
3 changes: 2 additions & 1 deletion include/eve/module/core/regular/impl/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <eve/module/core/regular/shuffle.hpp>
#include <eve/traits/product_type.hpp>
#include <eve/traits/as_wide.hpp>
#include <eve/as_element.hpp>

#include <bit>

Expand Down Expand Up @@ -50,7 +51,7 @@ struct convert_lambda
template<typename T, typename M>
EVE_FORCEINLINE constexpr void operator()(T const& in, M *res_m) const noexcept
{
*res_m = eve::convert(in, eve::as<element_type_t<M>> {});
*res_m = eve::convert(in, eve::as_element<M>{});
}
};

Expand Down
4 changes: 2 additions & 2 deletions include/eve/module/polynomial/regular/impl/legendre.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<element_type_t<T>>());
auto mm = convert(m, as<element_type_t<T>>());
auto ll = convert(l, as_element(theta));
auto mm = convert(m, as_element(theta));
using r_t = eve::common_value_t<T, decltype(ll), decltype(mm)>;
r_t p0(theta);
p0 = eve::legendre(l, m, cos(p0));
Expand Down
3 changes: 2 additions & 1 deletion include/eve/module/polynomial/regular/impl/tchebytchev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <eve/module/core.hpp>
#include <eve/module/math.hpp>
#include <eve/as_element.hpp>

namespace eve::detail
{
Expand Down Expand Up @@ -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<element_type_t<T>>()));
auto nn = inc(convert(n, as_element(x)));
auto z = eve::abs(x);
auto acx = acos(x);

Expand Down

0 comments on commit 64441ad

Please sign in to comment.