Skip to content

Commit

Permalink
eve::abs as a demo for elementwise defautl behavior and decorator sup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
jfalcou committed Dec 17, 2023
1 parent 875a91a commit 5abea74
Show file tree
Hide file tree
Showing 49 changed files with 569 additions and 484 deletions.
4 changes: 2 additions & 2 deletions benchmarks/module/core/abs/saturated/abs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ int main()
auto arg0 = eve::bench::random_<EVE_VALUE>(lmin,lmax);

eve::bench::experiment xp;
run<EVE_VALUE> (EVE_NAME(saturated(eve::abs)) , xp, eve::saturated(eve::abs), arg0);
run<EVE_TYPE> (EVE_NAME(saturated(eve::abs)) , xp, eve::saturated(eve::abs), arg0);
run<EVE_VALUE> (EVE_NAME(eve::abs[eve::saturated]) , xp, eve::abs[eve::saturated], arg0);
run<EVE_TYPE> (EVE_NAME(eve::abs[eve::saturated]) , xp, eve::abs[eve::saturated], arg0);
}
27 changes: 11 additions & 16 deletions examples/oop/complex_numbers__declaring_an_object_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
//
// Writing custom cmplx numbers.
//
// NOTE: we will definetly have a proper `eve::complex` but we don't have one yet.
// NOTE: SIMD compatible complex numbers and beyond are available in https://github.com/jfalcou/kyosu
//
// This example will demonstrate the basics of how you can write code that looks like
// it uses objects but actally utilizes parallel arrays and simd under the hood.
// it uses objects but actually utilizes parallel arrays and simd under the hood.
//
// Related termins are: SOA (structure of arrays) and ECS - entity component system.
// Related terms are: SOA (structure of arrays) and ECS - entity component system.
//
// NOTE:
// You might also want to have a look at:
Expand Down Expand Up @@ -92,24 +92,19 @@ struct cmplx : eve::struct_support<cmplx, float, float>
return self;
}

// The ostream operator you don't need to customise for wide, it will do the right thing.
friend std::ostream& operator<<(std::ostream& out, cmplx self)
friend EVE_FORCEINLINE auto abs(eve::like<cmplx> auto self)
{
return out << '(' << re(self) << " + " << im(self) << "i)";
return eve::hypot(re(self), im(self));
}

// Custoizing eve functions ----

// All eve callables are customiseable through tagged dispatch.
// We find it useful but you do it at your own risk, we are quite likely to break you.
// Alternatively - use your own functions.

EVE_FORCEINLINE friend auto tagged_dispatch( eve::tag::abs_, eve::like<cmplx> auto self)
// The ostream operator you don't need to customise for wide, it will do the right thing.
friend std::ostream& operator<<(std::ostream& out, cmplx self)
{
return eve::hypot(re(self), im(self));
return out << '(' << re(self) << " + " << im(self) << "i)";
}
};


// ------------------
// Using

Expand Down Expand Up @@ -179,7 +174,7 @@ TTS_CASE("wide works")
{
eve::wide<cmplx> x{cmplx{3.0, 4.0}};
eve::wide<float> expected{5.0};
eve::wide<float> actual = eve::abs(x);
eve::wide<float> actual = abs(x);
TTS_RELATIVE_EQUAL(expected, actual, 0.00001);
}
};
Expand Down Expand Up @@ -219,7 +214,7 @@ TTS_CASE("scalar works")
{
cmplx x{3.0, 4.0};
float expected{5.0};
float actual = eve::abs(x);
float actual = abs(x);
TTS_RELATIVE_EQUAL(expected, actual, 0.00001);
}
};
Expand Down
52 changes: 0 additions & 52 deletions include/eve/module/core/decorator/compensated.hpp

This file was deleted.

109 changes: 106 additions & 3 deletions include/eve/module/core/decorator/core.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//==================================================================================================
//======================================================================================================================
/**
EVE - Expressive Vector Engine
Copyright : EVE Project Contributors
SPDX-License-Identifier: BSL-1.0
**/
//==================================================================================================
//======================================================================================================================
#pragma once

#include <eve/module/core/decorator/compensated.hpp>
#include <eve/module/core/decorator/cyl.hpp>
#include <eve/module/core/decorator/fuzzy.hpp>
#include <eve/module/core/decorator/kind.hpp>
Expand All @@ -22,3 +21,107 @@
#include <eve/module/core/decorator/saturated.hpp>
#include <eve/module/core/decorator/sph.hpp>
#include <eve/module/core/decorator/successor.hpp>

//======================================================================================================================
// New option style - TODO rename later without the '2'
//======================================================================================================================
#include <eve/detail/raberu.hpp>

namespace eve
{
struct almost_mode {};
struct definitely_mode {};
struct kind_1_mode {};
struct kind_2_mode {};
struct musl_mode {};
struct numeric_mode {};
struct p_kind_mode {};
struct pedantic_mode {};
struct plain_mode {};
struct promote_mode {};
struct q_kind_mode {};
struct raw_mode {};
struct regular_mode {};
struct saturated_mode {};
struct spherical_mode {};
struct successor_mode {};
struct tolerant_mode {};

struct rounding_key_t : rbr::as_keyword<rounding_key_t>
{
template<typename Value> constexpr auto operator=(Value const&) const noexcept
{
return rbr::option<rounding_key_t,Value>{};
}
};
[[maybe_unused]] inline constexpr rounding_key_t rounding_key = {};

template<int N>
[[maybe_unused]] inline constexpr auto rounding = (rounding_key = eve::index<N>);

[[maybe_unused]] inline constexpr auto almost2 = ::rbr::flag( almost_mode{} );
[[maybe_unused]] inline constexpr auto definitely2 = ::rbr::flag( definitely_mode{});
[[maybe_unused]] inline constexpr auto downward2 = rounding<(0x01 | 0x08)>;
[[maybe_unused]] inline constexpr auto kind_12 = ::rbr::flag( kind_1_mode{} );
[[maybe_unused]] inline constexpr auto kind_22 = ::rbr::flag( kind_2_mode{} );
[[maybe_unused]] inline constexpr auto musl2 = ::rbr::flag( musl_mode{} );
[[maybe_unused]] inline constexpr auto numeric2 = ::rbr::flag( numeric_mode{} );
[[maybe_unused]] inline constexpr auto p_kind2 = ::rbr::flag( p_kind_mode{} );
[[maybe_unused]] inline constexpr auto pedantic2 = ::rbr::flag( pedantic_mode{} );
[[maybe_unused]] inline constexpr auto plain2 = ::rbr::flag( plain_mode{} );
[[maybe_unused]] inline constexpr auto promote2 = ::rbr::flag( promote_mode{} );
[[maybe_unused]] inline constexpr auto q_kind2 = ::rbr::flag( q_kind_mode{} );
[[maybe_unused]] inline constexpr auto raw2 = ::rbr::flag( raw_mode{} );
[[maybe_unused]] inline constexpr auto regular2 = ::rbr::flag( regular_mode{} );
[[maybe_unused]] inline constexpr auto saturated2 = ::rbr::flag( saturated_mode{} );
[[maybe_unused]] inline constexpr auto spherical = ::rbr::flag( spherical_mode{} );
[[maybe_unused]] inline constexpr auto successor2 = ::rbr::flag( successor_mode{} );
[[maybe_unused]] inline constexpr auto to_nearest2 = rounding<(0x00 | 0x08)>;
[[maybe_unused]] inline constexpr auto tolerant2 = ::rbr::flag( tolerant_mode{} );
[[maybe_unused]] inline constexpr auto toward_zero2 = rounding<(0x03 | 0x08)>;
[[maybe_unused]] inline constexpr auto upward2 = rounding<(0x02 | 0x08)>;

struct almost_option : detail::exact_option<almost2> {};
struct definitely_option : detail::exact_option<definitely2> {};
struct kind_1_option : detail::exact_option<kind_12> {};
struct kind_2_option : detail::exact_option<kind_22> {};
struct musl_option : detail::exact_option<musl2> {};
struct numeric_option : detail::exact_option<numeric2> {};
struct p_kind_option : detail::exact_option<p_kind2> {};
struct pedantic_option : detail::exact_option<pedantic2> {};
struct plain_option : detail::exact_option<plain2> {};
struct promote_option : detail::exact_option<promote2> {};
struct q_kind_option : detail::exact_option<q_kind2> {};
struct raw_option : detail::exact_option<raw2> {};
struct regular_option : detail::exact_option<regular2> {};
struct rounding_option : detail::exact_option<rounding_key> {};
struct saturated_option : detail::exact_option<saturated2> {};
struct spherical_option : detail::exact_option<spherical> {};
struct successor_option : detail::exact_option<successor2> {};
struct tolerant_option : detail::exact_option<tolerant2> {};

// ----------------------------------------------------------------------------------
// [TEMPORARY] Will be removed when all decorator have been converted
// ----------------------------------------------------------------------------------
inline constexpr auto as_option(almost_type const&) { return almost2; }
inline constexpr auto as_option(definitely_type const&) { return definitely2; }
inline constexpr auto as_option(downward_type const&) { return downward2; }
inline constexpr auto as_option(kind_1_type const&) { return kind_12; }
inline constexpr auto as_option(kind_2_type const&) { return kind_22; }
inline constexpr auto as_option(musl_type const&) { return musl2; }
inline constexpr auto as_option(numeric_type const&) { return numeric; }
inline constexpr auto as_option(p_kind_type const&) { return p_kind2; }
inline constexpr auto as_option(pedantic_type const&) { return pedantic2; }
inline constexpr auto as_option(plain_type const&) { return plain2; }
inline constexpr auto as_option(promote_type const&) { return promote2; }
inline constexpr auto as_option(q_kind_type const&) { return q_kind2; }
inline constexpr auto as_option(raw_type const&) { return raw2; }
inline constexpr auto as_option(regular_type const&) { return regular2; }
inline constexpr auto as_option(saturated_type const&) { return saturated2; }
inline constexpr auto as_option(sph_type const&) { return spherical; }
inline constexpr auto as_option(successor_type const&) { return successor2; }
inline constexpr auto as_option(to_nearest_type const&) { return to_nearest2; }
inline constexpr auto as_option(tolerant_type const&) { return tolerant2; }
inline constexpr auto as_option(toward_zero_type const&) { return toward_zero2; }
inline constexpr auto as_option(upward_type const&) { return upward2; }
}
20 changes: 4 additions & 16 deletions include/eve/module/core/decorator/musl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,15 @@
//==================================================================================================
#pragma once

#include <eve/detail/abi.hpp>
#include <eve/detail/overload.hpp>

namespace eve
{
//================================================================================================
// Function decorators mark-up used in function overloads
struct musl_type : decorator_
struct musl_t
{
template<typename Function> constexpr EVE_FORCEINLINE auto operator()(Function f) const noexcept
{
return [f](auto&&...args) { return f(musl_type {}, EVE_FWD(args)...); };
}
template<typename D> static constexpr auto combine(D const&) noexcept = delete;
};

//================================================================================================
// Function decorator - musl mode
template<typename Function>
constexpr EVE_FORCEINLINE auto
musl_(Function f) noexcept
{
return musl_type {}(f);
}
using musl_type = decorated<musl_t()>;
inline constexpr musl_type const musl_ = {};
}
20 changes: 4 additions & 16 deletions include/eve/module/core/decorator/plain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,15 @@
//==================================================================================================
#pragma once

#include <eve/detail/abi.hpp>
#include <eve/detail/overload.hpp>

namespace eve
{
//================================================================================================
// Function decorators mark-up used in function overloads
struct plain_type : decorator_
struct plain_
{
template<typename Function> constexpr EVE_FORCEINLINE auto operator()(Function f) const noexcept
{
return [f](auto&&...args) { return f(plain_type {}, EVE_FWD(args)...); };
}
template<typename D> static constexpr auto combine(D const&) noexcept = delete;
};

//================================================================================================
// Function decorator - plain mode
template<typename Function>
constexpr EVE_FORCEINLINE auto
plain(Function f) noexcept
{
return plain_type {}(f);
}
using plain_type = decorated<plain_()>;
inline constexpr plain_type const plain = {};
}
1 change: 0 additions & 1 deletion include/eve/module/core/pedantic/impl/absmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <eve/module/core/regular/all.hpp>
#include <eve/module/core/regular/is_nan.hpp>
#include <eve/module/core/regular/is_not_greater_equal.hpp>
#include <eve/module/core/saturated/abs.hpp>
#include <eve/arch/platform.hpp>

#include <type_traits>
Expand Down
1 change: 0 additions & 1 deletion include/eve/module/core/pedantic/impl/absmin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <eve/module/core/regular/all.hpp>
#include <eve/module/core/regular/is_nan.hpp>
#include <eve/module/core/regular/is_not_greater_equal.hpp>
#include <eve/module/core/saturated/abs.hpp>
#include <eve/arch/platform.hpp>

#include <type_traits>
Expand Down
6 changes: 3 additions & 3 deletions include/eve/module/core/pedantic/impl/maxmag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <eve/module/core/regular/if_else.hpp>
#include <eve/module/core/regular/is_nan.hpp>
#include <eve/module/core/regular/is_not_greater_equal.hpp>
#include <eve/module/core/saturated/abs.hpp>
#include <eve/module/core/regular/abs.hpp>
#include <eve/arch/platform.hpp>

#include <type_traits>
Expand All @@ -39,8 +39,8 @@ template<ordered_value T>
EVE_FORCEINLINE auto
maxmag_(EVE_SUPPORTS(cpu_), pedantic_type const&, T const& a, T const& b) noexcept
{
auto aa = saturated(eve::abs)(a);
auto bb = saturated(eve::abs)(b);
auto aa = eve::abs[saturated](a);
auto bb = eve::abs[saturated](b);
if constexpr( simd_value<T> )
{
auto tmp = if_else(is_not_greater_equal(aa, bb), b, pedantic(eve::max)(a, b));
Expand Down
6 changes: 3 additions & 3 deletions include/eve/module/core/pedantic/impl/minmag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <eve/module/core/regular/if_else.hpp>
#include <eve/module/core/regular/is_nan.hpp>
#include <eve/module/core/regular/is_not_greater_equal.hpp>
#include <eve/module/core/saturated/abs.hpp>
#include <eve/module/core/regular/abs.hpp>
#include <eve/arch/platform.hpp>

#include <type_traits>
Expand All @@ -39,8 +39,8 @@ template<ordered_value T>
EVE_FORCEINLINE auto
minmag_(EVE_SUPPORTS(cpu_), pedantic_type const&, T const& a, T const& b) noexcept
{
auto aa = saturated(eve::abs)(a);
auto bb = saturated(eve::abs)(b);
auto aa = eve::abs[saturated](a);
auto bb = eve::abs[saturated](b);
if constexpr( simd_value<T> )
{
auto tmp = if_else(is_not_greater_equal(bb, aa), b, pedantic(eve::min)(a, b));
Expand Down
2 changes: 1 addition & 1 deletion include/eve/module/core/pedantic/impl/negabsmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <eve/module/core/decorator/pedantic.hpp>
#include <eve/module/core/pedantic/absmax.hpp>
#include <eve/module/core/regular/all.hpp>
#include <eve/module/core/saturated/abs.hpp>
#include <eve/module/core/regular/abs.hpp>
#include <eve/arch/platform.hpp>

#include <type_traits>
Expand Down
2 changes: 1 addition & 1 deletion include/eve/module/core/pedantic/impl/negabsmin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <eve/module/core/decorator/pedantic.hpp>
#include <eve/module/core/pedantic/absmin.hpp>
#include <eve/module/core/regular/all.hpp>
#include <eve/module/core/saturated/abs.hpp>
#include <eve/module/core/regular/abs.hpp>
#include <eve/arch/platform.hpp>

#include <type_traits>
Expand Down
2 changes: 1 addition & 1 deletion include/eve/module/core/pedantic/impl/negmaxabs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <eve/module/core/decorator/pedantic.hpp>
#include <eve/module/core/pedantic/maxabs.hpp>
#include <eve/module/core/regular/all.hpp>
#include <eve/module/core/saturated/abs.hpp>
#include <eve/module/core/regular/abs.hpp>
#include <eve/arch/platform.hpp>

#include <type_traits>
Expand Down

0 comments on commit 5abea74

Please sign in to comment.