Skip to content

Commit

Permalink
#1144 - More common_compatible suppression in polynomial and special
Browse files Browse the repository at this point in the history
* polynomial

* combinatorial

* special1

* special

* some remaining common_compatible

* logicalandnot + jacobi

* reverse_horner

* joel's remarks
  • Loading branch information
jtlap committed May 12, 2024
1 parent 91e51b8 commit dc80688
Show file tree
Hide file tree
Showing 39 changed files with 201 additions and 155 deletions.
3 changes: 1 addition & 2 deletions include/eve/module/combinatorial/regular/fibonacci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ namespace eve
//! namespace eve
//! {
//! template< eve::unsigned_value N, eve::floating_real_value T, eve::floating_real_value U>
//! requires eve::compatible<T, U>
//! eve::common_compatible_t<T, U> fibonacci(N n, T x, U y) noexcept
//! eve::common_value_t<T, U> fibonacci(N n, T x, U y) noexcept
//! }
//! @endcode
//!
Expand Down
4 changes: 2 additions & 2 deletions include/eve/module/combinatorial/regular/impl/fibonacci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
namespace eve::detail
{

template<unsigned_value N, floating_value T, value U>
template<unsigned_value N, floating_value T, floating_value U>
EVE_FORCEINLINE auto
fibonacci_(EVE_SUPPORTS(cpu_), N n, T a, U b) noexcept requires compatible_values<U, T>
fibonacci_(EVE_SUPPORTS(cpu_), N n, T a, U b) noexcept
{
return indexed_call(fibonacci, n, a, b);
}
Expand Down
4 changes: 3 additions & 1 deletion include/eve/module/combinatorial/regular/impl/gcd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#pragma once

#include <eve/module/core.hpp>
#include <eve/traits/common_value.hpp>

namespace eve::detail
{
template<value T, value U>
EVE_FORCEINLINE auto
gcd_(EVE_SUPPORTS(cpu_), T a, U b) noexcept requires compatible_values<T, U>
gcd_(EVE_SUPPORTS(cpu_), T a, U b) noexcept
->common_value_t<T, U>
{
return arithmetic_call(gcd, a, b);
}
Expand Down
4 changes: 3 additions & 1 deletion include/eve/module/combinatorial/regular/impl/lcm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@

#include <eve/module/combinatorial/regular/gcd.hpp>
#include <eve/module/core.hpp>
#include <eve/traits/common_value.hpp>

namespace eve::detail
{
// -----------------------------------------------------------------------------------------------
// regular case
template<integral_real_value T, integral_real_value U>
EVE_FORCEINLINE auto
lcm_(EVE_SUPPORTS(cpu_), T const& a, U const& b) noexcept requires compatible_values<T, U>
lcm_(EVE_SUPPORTS(cpu_), T const& a, U const& b) noexcept
->common_value_t<T, U>
{
return arithmetic_call(lcm, a, b);
}
Expand Down
3 changes: 2 additions & 1 deletion include/eve/module/core/regular/impl/ifnot_else.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ EVE_FORCEINLINE constexpr auto
ifnot_else_(EVE_SUPPORTS(cpu_),
T const& cond,
U const& t,
V const& f) noexcept requires compatible_values<U, V>
V const& f) noexcept
-> decltype(if_else(cond, f, t))
{
return if_else(cond, f, t);
}
Expand Down
3 changes: 2 additions & 1 deletion include/eve/module/core/regular/impl/is_ordered.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
//==================================================================================================
#pragma once

#include <eve/concept/compatible.hpp>
#include <eve/concept/value.hpp>
#include <eve/detail/apply_over.hpp>
#include <eve/detail/implementation.hpp>
#include <eve/module/core/constant/true.hpp>
#include <eve/module/core/regular/all.hpp>
#include <eve/traits/as_logical.hpp>
#include <eve/traits/common_value.hpp>

namespace eve::detail
{
Expand Down Expand Up @@ -42,6 +42,7 @@ is_ordered_(EVE_SUPPORTS(cpu_), T const& a, T const& b) noexcept
template<conditional_expr C, real_value U, real_value V>
EVE_FORCEINLINE auto
is_ordered_(EVE_SUPPORTS(cpu_), C const& cond, U const& u, V const& v) noexcept
-> decltype(is_ordered(u, v))
{
return logical_mask_op(cond, is_ordered, u, v);
}
Expand Down
1 change: 0 additions & 1 deletion include/eve/module/core/regular/impl/logical_andnot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//==================================================================================================
#pragma once

#include <eve/concept/compatible.hpp>
#include <eve/concept/value.hpp>
#include <eve/detail/apply_over.hpp>
#include <eve/detail/implementation.hpp>
Expand Down
1 change: 0 additions & 1 deletion include/eve/module/core/regular/impl/logical_notand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//==================================================================================================
#pragma once

#include <eve/concept/compatible.hpp>
#include <eve/concept/value.hpp>
#include <eve/detail/apply_over.hpp>
#include <eve/detail/implementation.hpp>
Expand Down
7 changes: 4 additions & 3 deletions include/eve/module/core/regular/impl/negabsmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ negabsmax_(EVE_SUPPORTS(cpu_), Ts... args) noexcept
return minus(absmax(args...));
}

template<conditional_expr C, typename ...Ts>
template<conditional_expr C, typename T0, typename ...Ts>
EVE_FORCEINLINE auto
negabsmax_(EVE_SUPPORTS(cpu_), C const & c, Ts... args) noexcept
negabsmax_(EVE_SUPPORTS(cpu_), C const & c, T0 t0, Ts... args) noexcept
-> decltype(if_else(c, negabsmax(t0, args...), t0))
{
return minus[c](absmax[c](args...));
return minus[c](absmax[c](t0, args...));
}

//================================================================================================
Expand Down
7 changes: 4 additions & 3 deletions include/eve/module/core/regular/impl/negabsmin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ negabsmin_(EVE_SUPPORTS(cpu_), Ts... args) noexcept
return minus(absmin(args...));
}

template<conditional_expr C, typename ...Ts>
template<conditional_expr C, typename T0, typename ...Ts>
EVE_FORCEINLINE auto
negabsmin_(EVE_SUPPORTS(cpu_), C const & c, Ts... args) noexcept
negabsmin_(EVE_SUPPORTS(cpu_), C const & c, T0 t0, Ts... args) noexcept
-> decltype(if_else(c, negabsmin(t0, args...), t0))
{
return minus[c](absmin[c](args...));
return minus[c](absmin[c](t0, args...));
}

//================================================================================================
Expand Down
9 changes: 6 additions & 3 deletions include/eve/module/core/regular/impl/negmaxabs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <eve/concept/value.hpp>
#include <eve/module/core/regular/maxabs.hpp>
#include <eve/module/core/regular/minus.hpp>

#include <type_traits>

Expand All @@ -18,15 +19,17 @@ namespace eve::detail
template<typename ...Ts>
EVE_FORCEINLINE auto
negmaxabs_(EVE_SUPPORTS(cpu_), Ts... args)
-> decltype(minus(maxabs(args...)))
{
return minus(maxabs(args...));
}

template<conditional_expr C, typename ...Ts>
template<conditional_expr C, typename T0, typename ...Ts>
EVE_FORCEINLINE auto
negmaxabs_(EVE_SUPPORTS(cpu_), C const & c, Ts... args)
negmaxabs_(EVE_SUPPORTS(cpu_), C const & c, T0 t0, Ts... args)
-> decltype(if_else(c, negmaxabs(t0, args...), t0))
{
return minus[c](maxabs[c](args...));
return minus[c](maxabs[c](t0, args...));
}

//================================================================================================
Expand Down
15 changes: 8 additions & 7 deletions include/eve/module/core/regular/impl/negminabs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//==================================================================================================
#pragma once

#include <eve/concept/compatible.hpp>
#include <eve/concept/value.hpp>
#include <eve/module/core/regular/minabs.hpp>
#include <eve/module/core/regular/minus.hpp>
Expand All @@ -17,24 +16,26 @@ namespace eve::detail

template<typename ...Ts>
EVE_FORCEINLINE auto
negminabs_(EVE_SUPPORTS(cpu_), Ts... args)
negminabs_(EVE_SUPPORTS(cpu_), Ts... args) noexcept
-> decltype(minus(minabs(args...)))
{
return minus(minabs(args...));
}

template<conditional_expr C, typename ...Ts>
template<conditional_expr C, typename T0, typename ...Ts>
EVE_FORCEINLINE auto
negminabs_(EVE_SUPPORTS(cpu_), C const & c, Ts... args)
negminabs_(EVE_SUPPORTS(cpu_), C const & c, T0 t0, Ts... args) noexcept
-> decltype(if_else(c, negminabs(t0, args...), t0))
{
return minus[c](minabs[c](args...));
return minus[c](minabs[c](t0, args...));
}

//================================================================================================
// tuples
//================================================================================================
template<kumi::non_empty_product_type Ts>
auto
negminabs_(EVE_SUPPORTS(cpu_), Ts tup)
negminabs_(EVE_SUPPORTS(cpu_), Ts tup) noexcept
{
if constexpr( kumi::size_v<Ts> == 1) return minus(abs(get<0>(tup)));
else return kumi::apply( [&](auto... m) { return negminabs(m...); }, tup);
Expand All @@ -43,7 +44,7 @@ negminabs_(EVE_SUPPORTS(cpu_), Ts tup)

template<decorator D, kumi::non_empty_product_type Ts>
auto
negminabs_(EVE_SUPPORTS(cpu_), D const & d , Ts tup)
negminabs_(EVE_SUPPORTS(cpu_), D const & d , Ts tup) noexcept
{
if constexpr( kumi::size_v<Ts> == 1) return minus(abs(get<0>(tup)));
else return minus(kumi::apply( [&](auto... m) { return d(minabs)(m...); }, tup));
Expand Down
12 changes: 7 additions & 5 deletions include/eve/module/polynomial/detail/horner_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <eve/concept/range.hpp>
#include <eve/module/core.hpp>
#include <eve/traits/common_value.hpp>

#include <concepts>
#include <iterator>
Expand All @@ -24,8 +25,9 @@ namespace eve::detail
template<decorator D, value T0, value... Cs>
EVE_FORCEINLINE constexpr auto
horner_impl(D const& d, T0 const& xx, Cs... cs) noexcept
-> common_value_t<T0, Cs...>
{
using r_t = common_compatible_t<T0, Cs...>;
using r_t = common_value_t<T0, Cs...>;
constexpr size_t N = sizeof...(Cs);
if constexpr( N == 0 ) return r_t(0);
else if constexpr( N == 1 ) return (r_t(cs), ...);
Expand All @@ -47,9 +49,9 @@ horner_impl(D const& d, T0 const& xx, Cs... cs) noexcept
template<decorator D, value T0, range R>
EVE_FORCEINLINE constexpr auto
horner_impl(D const& d, T0 xx, R const& r) noexcept
requires(compatible_values<T0, typename R::value_type> && (!simd_value<R>))
-> common_value_t<T0, typename R::value_type>
{
using r_t = common_compatible_t<T0, typename R::value_type>;
using r_t = common_value_t<T0, typename R::value_type>;
auto x = r_t(xx);
auto cur = std::begin(r);
auto last = std::end(r);
Expand All @@ -69,9 +71,9 @@ horner_impl(D const& d, T0 xx, R const& r) noexcept
template<value T0, range R>
EVE_FORCEINLINE constexpr auto
horner_impl(compensated_type const&, T0 xx, R const& r) noexcept
requires(compatible_values<T0, typename R::value_type> && (!simd_value<R>))
-> common_value_t<T0, typename R::value_type>
{
using r_t = common_compatible_t<T0, typename R::value_type>;
using r_t = common_value_t<T0, typename R::value_type>;
auto x = r_t(xx);
auto cur = std::begin(r);
auto last = std::end(r);
Expand Down
27 changes: 19 additions & 8 deletions include/eve/module/polynomial/detail/reverse_horner_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <eve/module/polynomial/numeric/horner.hpp>
#include <eve/module/polynomial/pedantic/horner.hpp>
#include <eve/module/polynomial/regular/horner.hpp>
#include <eve/traits/common_value.hpp>

#include <concepts>
#include <iterator>
Expand All @@ -21,14 +22,24 @@
namespace eve::detail
{

template<decorator D, value T0, value... Cs>
template<decorator D, floating_value T0, value C0, value... Cs>
EVE_FORCEINLINE constexpr auto
reverse_horner_impl(D const& d, T0 xx, Cs... cs) noexcept
reverse_horner_impl(D const& d, T0 xx, C0 c0, Cs... cs) noexcept
-> decltype(horner(xx, c0, cs...))
{
using r_t = common_compatible_t<T0, Cs...>;
auto x = r_t(xx);
std::array<r_t, sizeof...(cs)> c {r_t(cs)...};
return d(reverse_horner)(x, c);
if constexpr((scalar_value<C0> && ... && scalar_value<Cs>))
{
using e_t = element_type_t<T0>;
std::array<e_t, sizeof...(cs)+1> c {e_t(c0), e_t(cs)...};
return d(reverse_horner)(xx, c);
}
else
{
using r_t = common_value_t<T0, C0, Cs...>;
auto x = r_t(xx);
std::array<r_t, sizeof...(cs)+1> c {r_t{c0}, r_t{cs}...};
return d(reverse_horner)(x, c);
}
}

//================================================================================================
Expand All @@ -37,9 +48,9 @@ reverse_horner_impl(D const& d, T0 xx, Cs... cs) noexcept
template<decorator D, value T0, range R>
EVE_FORCEINLINE constexpr auto
reverse_horner_impl(D const& d, T0 xx, R const& r) noexcept
requires(compatible_values<T0, typename R::value_type> && (!simd_value<R>))
-> common_value_t<T0, typename R::value_type>
{
using r_t = common_compatible_t<T0, typename R::value_type>;
using r_t = common_value_t<T0, typename R::value_type>;
auto x = r_t(xx);
auto cur = std::rbegin(r);
auto first = std::rend(r);
Expand Down
8 changes: 4 additions & 4 deletions include/eve/module/polynomial/numeric/impl/horner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace eve::detail
template<value T0, std::input_iterator IT>
EVE_FORCEINLINE constexpr auto
horner_(EVE_SUPPORTS(cpu_), numeric_type const&, T0 xx, IT const& first, IT const& last) noexcept
requires((compatible_values<T0, typename std::iterator_traits<IT>::value_type>))
-> decltype(detail::horner_impl(numeric_type(), xx, first, last))
{
return detail::horner_impl(numeric_type(), xx, first, last);
}
Expand All @@ -34,7 +34,7 @@ horner_(EVE_SUPPORTS(cpu_),
callable_one_ const&,
IT const& first,
IT const& last) noexcept
requires((compatible_values<T0, typename std::iterator_traits<IT>::value_type>))
-> decltype(detail::horner_impl(numeric_type(), xx, one, first, last))
{
return detail::horner_impl(numeric_type(), xx, one, first, last);
}
Expand All @@ -45,7 +45,7 @@ horner_(EVE_SUPPORTS(cpu_),
template<value T0, range R>
EVE_FORCEINLINE constexpr auto
horner_(EVE_SUPPORTS(cpu_), numeric_type const&, T0 xx, R const& r) noexcept
requires(compatible_values<T0, typename R::value_type> && (!simd_value<R>))
-> decltype(detail::horner_impl(numeric_type(), xx, r))
{
return detail::horner_impl(numeric_type(), xx, r);
}
Expand All @@ -56,7 +56,7 @@ horner_(EVE_SUPPORTS(cpu_), numeric_type const&, T0 xx, R const& r) noexcept
template<value T0, range R>
EVE_FORCEINLINE constexpr auto
horner_(EVE_SUPPORTS(cpu_), numeric_type const&, T0 xx, callable_one_ const&, R const& r) noexcept
requires(compatible_values<T0, typename R::value_type> && (!simd_value<R>))
-> decltype(detail::horner_impl(numeric_type(), xx, one, r))
{
return detail::horner_impl(numeric_type(), xx, one, r);
}
Expand Down
10 changes: 3 additions & 7 deletions include/eve/module/polynomial/numeric/impl/newton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ newton_(EVE_SUPPORTS(cpu_),
IT0 const& firstc,
IT0 const& lastc,
IT1 const& firstn) noexcept
requires(compatible_values<T0, typename std::iterator_traits<IT0>::value_type>&&
compatible_values<T0, typename std::iterator_traits<IT1>::value_type>)
-> decltype( detail::newton_impl(numeric_type(), xx, firstc, lastc, firstn))
{
return detail::newton_impl(numeric_type(), xx, firstc, lastc, firstn);
}
Expand All @@ -34,11 +33,8 @@ newton_(EVE_SUPPORTS(cpu_),
//================================================================================================
template<value T0, range R1, range R2>
EVE_FORCEINLINE constexpr auto
newton_(EVE_SUPPORTS(cpu_), numeric_type const&, T0 xx, R1 const& rc, R2 const& rn) noexcept requires(
compatible_values<
T0,
typename R1::
value_type> && !simd_value<R1> && compatible_values<T0, typename R2::value_type> && !simd_value<R2>)
newton_(EVE_SUPPORTS(cpu_), numeric_type const&, T0 xx, R1 const& rc, R2 const& rn) noexcept
-> decltype(detail::newton_impl(numeric_type(), xx, rc, rn))
{
return detail::newton_impl(numeric_type(), xx, rc, rn);
}
Expand Down
Loading

0 comments on commit dc80688

Please sign in to comment.