Skip to content

Commit

Permalink
Cayley/complex only is_imag + updated average dist reldist
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlap committed Sep 2, 2023
1 parent 8c700d5 commit cfa3239
Show file tree
Hide file tree
Showing 14 changed files with 481 additions and 15 deletions.
80 changes: 80 additions & 0 deletions include/kyosu/cayley.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

//======================================================================================================================
//! @defgroup functions cayley Functions
//! @brief Functions performing computations over all cayley-dicson types, complex, quaternions and octonions...
//======================================================================================================================
#include <kyosu/cayley/abs.hpp>
#include <kyosu/cayley/ceil.hpp>
#include <kyosu/cayley/conj.hpp>
#include <kyosu/cayley/cos.hpp>
#include <kyosu/cayley/cosh.hpp>
#include <kyosu/cayley/cot.hpp>
#include <kyosu/cayley/coth.hpp>
#include <kyosu/cayley/convert.hpp>
#include <kyosu/cayley/csc.hpp>
#include <kyosu/cayley/csch.hpp>
#include <kyosu/cayley/dec.hpp>
#include <kyosu/cayley/dist.hpp>
#include <kyosu/cayley/exp.hpp>
#include <kyosu/cayley/exp2.hpp>
#include <kyosu/cayley/exp10.hpp>
#include <kyosu/cayley/expm1.hpp>
#include <kyosu/cayley/expmx2.hpp>
#include <kyosu/cayley/expx2.hpp>
#include <kyosu/cayley/exp_i.hpp>
#include <kyosu/cayley/exp_ipi.hpp>
#include <kyosu/cayley/floor.hpp>
#include <kyosu/cayley/frac.hpp>
#include <kyosu/cayley/if_else.hpp>
#include <kyosu/cayley/inc.hpp>
#include <kyosu/cayley/ipart.hpp>
#include <kyosu/cayley/is_denormal.hpp>
#include <kyosu/cayley/is_equal.hpp>
#include <kyosu/cayley/is_eqz.hpp>
#include <kyosu/cayley/is_finite.hpp>
#include <kyosu/cayley/is_infinite.hpp>
#include <kyosu/cayley/is_nan.hpp>
#include <kyosu/cayley/is_nez.hpp>
#include <kyosu/cayley/is_not_denormal.hpp>
#include <kyosu/cayley/is_not_equal.hpp>
#include <kyosu/cayley/is_not_finite.hpp>
#include <kyosu/cayley/is_not_infinite.hpp>
#include <kyosu/cayley/is_not_nan.hpp>
#include <kyosu/cayley/is_not_real.hpp>
#include <kyosu/cayley/is_real.hpp>
#include <kyosu/cayley/jpart.hpp>
#include <kyosu/cayley/kpart.hpp>
#include <kyosu/cayley/lerp.hpp>
#include <kyosu/cayley/log.hpp>
#include <kyosu/cayley/log1p.hpp>
#include <kyosu/cayley/log10.hpp>
#include <kyosu/cayley/log2.hpp>
#include <kyosu/cayley/minus.hpp>
#include <kyosu/cayley/nearest.hpp>
#include <kyosu/cayley/oneminus.hpp>
#include <kyosu/cayley/pure.hpp>
#include <kyosu/cayley/purepart.hpp>
#include <kyosu/cayley/real.hpp>
#include <kyosu/cayley/rec.hpp>
#include <kyosu/cayley/reldist.hpp>
#include <kyosu/cayley/sec.hpp>
#include <kyosu/cayley/sech.hpp>
#include <kyosu/cayley/sign.hpp>
#include <kyosu/cayley/sin.hpp>
#include <kyosu/cayley/sincos.hpp>
#include <kyosu/cayley/sinh.hpp>
#include <kyosu/cayley/sinhcosh.hpp>
#include <kyosu/cayley/sqr_abs.hpp>
#include <kyosu/cayley/sqr.hpp>
#include <kyosu/cayley/sqrt.hpp>
#include <kyosu/cayley/tan.hpp>
#include <kyosu/cayley/tanh.hpp>
#include <kyosu/cayley/trunc.hpp>
19 changes: 19 additions & 0 deletions include/kyosu/complex/impl/predicates.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once
#include <eve/module/core.hpp>

namespace kyosu::_
{
template<kyosu::concepts::complex C>
KYOSU_FORCEINLINE constexpr
auto dispatch(eve::tag_of<kyosu::conj> const&, C const& c) noexcept
{
return is_eqz(kyosu::real(c));
}
}
74 changes: 74 additions & 0 deletions include/kyosu/complex/is_imag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>

namespace kyosu::tags
{
struct callable_is_imag : eve::elementwise
{
using callable_tag_type = callable_is_imag;

KYOSU_DEFERS_CALLABLE(is_imag_);

template<eve::ordered_value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, T const& v) noexcept { return eve::is_eqz(v); }

template<typename T>
KYOSU_FORCEINLINE auto operator()(T const& target) const noexcept -> decltype(eve::tag_invoke(*this, target))
{
return eve::tag_invoke(*this, target);
}

template<typename... T>
eve::unsupported_call<callable_is_imag(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var is_imag
//! @brief test if the parameter is imag.
//!
//! **Defined in Header**
//!
//! @code
//! #include <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::complex T> constexpr auto is_imag(T z) noexcept;
//! template<eve::ordered_value T> constexpr auto is_imag(T z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z` : Value to process.
//!
//! **Return value**
//!
//! Returns elementwise true the real part of the argument is zero.
//! For Caley-Dickson types of dimension greater than 2 use is_pure.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/is_imag.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_is_imag is_imag = {};
}
2 changes: 2 additions & 0 deletions include/kyosu/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! @brief Functions performing computations over complex, quaternions and octonions.
//======================================================================================================================
#include <kyosu/functions/abs.hpp>
#include <kyosu/functions/average.hpp>
#include <kyosu/functions/ceil.hpp>
#include <kyosu/functions/conj.hpp>
#include <kyosu/functions/cos.hpp>
Expand Down Expand Up @@ -40,6 +41,7 @@
#include <kyosu/functions/is_equal.hpp>
#include <kyosu/functions/is_eqz.hpp>
#include <kyosu/functions/is_finite.hpp>
#include <kyosu/functions/is_imag.hpp>
#include <kyosu/functions/is_infinite.hpp>
#include <kyosu/functions/is_nan.hpp>
#include <kyosu/functions/is_nez.hpp>
Expand Down
78 changes: 78 additions & 0 deletions include/kyosu/functions/average.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>
namespace kyosu::tags
{
struct callable_average : eve::elementwise
{
using callable_tag_type = callable_average;

KYOSU_DEFERS_CALLABLE(average_);

static KYOSU_FORCEINLINE auto deferred_call(auto
, eve::ordered_value auto const& v0
, eve::ordered_value auto const& v1) noexcept
{
return eve::average(v0, v1);
}

KYOSU_FORCEINLINE auto operator()(auto const& target0, auto const& target1) const noexcept
-> decltype(eve::tag_invoke(*this, target0, target1))
{
return eve::tag_invoke(*this, target0, target1);
}

template<typename... T>
eve::unsupported_call<callable_average(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var average
//! @brief Computes the average of the two parameters.
//!
//! **Defined in Header**
//!
//! @code
//! #include <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::cayley_dickson T0, kyosu::concepts::cayley_dickson T1 > constexpr auto average(T0 z0, T1, z1) noexcept;
//! template<eve::ordered_value T0, kyosu::concepts::cayley_dickson T1> > constexpr auto average(T0 z0, T1, z1) noexcept;
//! template<kyosu::concepts::cayley_dickson T0, eve::ordered_value T1 > constexpr auto average(T0 z0, T1, z1) noexcept;
//! template<eve::ordered_value T0, ordered_value T1> > constexpr auto average(T0 z0, T1, z1) noexcept;
///! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z0, z1` : Value to process.
//!
//! **Return value**
//!
//! Returns the average of the two arguments .
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/average.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_average average = {};
}
73 changes: 73 additions & 0 deletions include/kyosu/functions/is_imag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>

namespace kyosu::tags
{
struct callable_is_imag : eve::elementwise
{
using callable_tag_type = callable_is_imag;

KYOSU_DEFERS_CALLABLE(is_imag_);

template<eve::ordered_value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, T const& v) noexcept { return eve::is_eqz(v); }

template<typename T>
KYOSU_FORCEINLINE auto operator()(T const& target) const noexcept -> decltype(eve::tag_invoke(*this, target))
{
return eve::tag_invoke(*this, target);
}

template<typename... T>
eve::unsupported_call<callable_is_imag(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var is_imag
//! @brief test if the complex parameter is pure imaginary.
//!
//! **Defined in Header**
//!
//! @code
//! #include <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::cayley_dickson T> constexpr auto is_imag(T z) noexcept;
//! template<eve::ordered_value T> constexpr auto is_imag(T z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z` : Value to process.
//!
//! **Return value**
//!
//! Returns the value of real(z) == 0.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/is_imag.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_is_imag is_imag = {};
}
23 changes: 12 additions & 11 deletions include/kyosu/types/cayley_dickson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <kyosu/types/impl/predicates.hpp>
#include <kyosu/types/impl/math.hpp>
#include <kyosu/types/impl/trigo.hpp>
#include <kyosu/types/impl/complex/predicates.hpp>
#include <bit>

namespace kyosu
Expand Down Expand Up @@ -99,16 +100,6 @@ namespace kyosu
return that;
}

//==================================================================================================================
// Main function dispatchers
//==================================================================================================================
KYOSU_FORCEINLINE
friend constexpr auto tag_invoke(eve::callable auto const& f, auto, eve::like<cayley_dickson> auto&&... c) noexcept
-> decltype(_::dispatch(f, KYOSU_FWD(c)...))
{
return _::dispatch(f, KYOSU_FWD(c)...);
}

//==================================================================================================================
// Tuple-like behavior
//==================================================================================================================
Expand All @@ -126,6 +117,17 @@ namespace kyosu
template<std::size_t I, typename T, unsigned int N>
constexpr auto get(cayley_dickson<T,N> const& c) noexcept { return kumi::get<I>(c.contents); }

//==================================================================================================================
// Main function dispatchers
//==================================================================================================================
template<typename... T>
requires(concepts::cayley_dickson<T> || ... )
KYOSU_FORCEINLINE constexpr auto tag_invoke(eve::callable auto const& f, auto, T&&... c) noexcept
-> decltype(_::dispatch(f, KYOSU_FWD(c)...))
{
return _::dispatch(f, KYOSU_FWD(c)...);
}

//==================================================================================================================
// Tag invoke override for if_else - Outside so it can properly deals with the complicated parameters of if_else
//==================================================================================================================
Expand All @@ -148,7 +150,6 @@ namespace kyosu
return _::dispatch(f, c, tgt);
}


//==================================================================================================================
// Tag invoke override for parts extraction - Outside so they can see get<I>(c)
//==================================================================================================================
Expand Down
Loading

0 comments on commit cfa3239

Please sign in to comment.