Skip to content

Commit

Permalink
Simplify callable
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlap authored Nov 24, 2024
1 parent a17ada0 commit 7c1dbe5
Show file tree
Hide file tree
Showing 150 changed files with 953 additions and 1,919 deletions.
1 change: 1 addition & 0 deletions include/kyosu/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#include <kyosu/functions/rec.hpp>
#include <kyosu/functions/reldist.hpp>
#include <kyosu/functions/sign.hpp>
#include <kyosu/functions/signnz.hpp>
#include <kyosu/functions/slerp.hpp>
#include <kyosu/functions/sqr.hpp>
#include <kyosu/functions/sqr_abs.hpp>
Expand Down
29 changes: 11 additions & 18 deletions include/kyosu/functions/abs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ namespace kyosu
struct abs_t : eve::elementwise_callable<abs_t, Options, eve::raw_option>
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr as_real_type_t<Z> operator()(Z z) const noexcept { return KYOSU_CALL(z); }
KYOSU_FORCEINLINE constexpr as_real_type_t<Z> operator()(Z v) const noexcept
{
if constexpr(Options::contains(eve::raw))
return eve::hypot(v);
else
return eve::hypot[eve::pedantic](v);
}

template<concepts::real V>
KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept { return KYOSU_CALL(v); }
KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept
{
return eve::abs(v);
}

KYOSU_CALLABLE_OBJECT(abs_t, abs_);
};
Expand Down Expand Up @@ -68,19 +77,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto abs_(KYOSU_DELAY(), O const&, Z const& v) noexcept
{
if constexpr(concepts::cayley_dickson<Z>){
if constexpr(O::contains(eve::raw))
return eve::hypot(v);
else
return eve::hypot[eve::pedantic](v);
}
else
return eve::abs(v);
}
}
2 changes: 1 addition & 1 deletion include/kyosu/functions/acos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace kyosu

template<concepts::real V>
KYOSU_FORCEINLINE constexpr complex_t<V> operator()(V v) const noexcept
{ return KYOSU_CALL(complex(v)); }
{ return (*this)(complex(v)); }

KYOSU_CALLABLE_OBJECT(acos_t, acos_);
};
Expand Down
2 changes: 1 addition & 1 deletion include/kyosu/functions/acosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace kyosu

template<concepts::real V>
KYOSU_FORCEINLINE constexpr complex_t<V> operator()(V v) const noexcept
{ return KYOSU_CALL(complex(v)); }
{ return (*this)(complex(v)); }

KYOSU_CALLABLE_OBJECT(acosh_t, acosh_);
};
Expand Down
13 changes: 2 additions & 11 deletions include/kyosu/functions/acospi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }
{ return radinpi(kyosu::acos(z)); }

template<concepts::real V>
KYOSU_FORCEINLINE constexpr complex_t<V> operator()(V v) const noexcept
{ return KYOSU_CALL(complex(v)); }
{ return (*this)(complex(v)); }

KYOSU_CALLABLE_OBJECT(acospi_t, acospi_);
};
Expand Down Expand Up @@ -69,12 +69,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto acospi_(KYOSU_DELAY(), O const&, Z z) noexcept
{
return radinpi(kyosu::acos(z));
}
}
11 changes: 1 addition & 10 deletions include/kyosu/functions/acot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }
{ return kyosu::atan(kyosu::rec(z)); }

template<concepts::real V>
KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept
Expand Down Expand Up @@ -78,12 +78,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto acot_(KYOSU_DELAY(), O const&, Z z) noexcept
{
return kyosu::atan(kyosu::rec(z));
}
}
12 changes: 2 additions & 10 deletions include/kyosu/functions/acoth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }
{ return kyosu::atanh(kyosu::rec(z)); }

template<concepts::real V>
KYOSU_FORCEINLINE constexpr complex_t<V> operator()(V v) const noexcept
{ return KYOSU_CALL(complex(v)); }
{ return (*this)(complex(v)); }

KYOSU_CALLABLE_OBJECT(acoth_t, acoth_);
};
Expand Down Expand Up @@ -79,11 +79,3 @@ namespace kyosu
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto acoth_(KYOSU_DELAY(), O const&, Z z) noexcept
{
return kyosu::atanh(kyosu::rec(z));
}
}
13 changes: 2 additions & 11 deletions include/kyosu/functions/acotpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }
{ return radinpi(kyosu::acot(z)); }

template<concepts::real V>
KYOSU_FORCEINLINE constexpr complex_t<V> operator()(V v) const noexcept
{ return KYOSU_CALL(complex(v)); }
{ return (*this)(complex(v)); }

KYOSU_CALLABLE_OBJECT(acotpi_t, acotpi_);
};
Expand Down Expand Up @@ -69,12 +69,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto acotpi_(KYOSU_DELAY(), O const&, Z z) noexcept
{
return radinpi(kyosu::acot(z));
}
}
13 changes: 2 additions & 11 deletions include/kyosu/functions/acsc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }
{ return kyosu::asin(kyosu::rec(z)); }

template<concepts::real V>
KYOSU_FORCEINLINE constexpr complex_t<V> operator()(V v) const noexcept
{ return KYOSU_CALL(complex(v)); }
{ return (*this)(complex(v)); }

KYOSU_CALLABLE_OBJECT(acsc_t, acsc_);
};
Expand Down Expand Up @@ -73,12 +73,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto acsc_(KYOSU_DELAY(), O const&, Z z) noexcept
{
return kyosu::asin(kyosu::rec(z));
}
}
13 changes: 2 additions & 11 deletions include/kyosu/functions/acsch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }
{ return asinh(rec(z)); }

template<concepts::real V>
KYOSU_FORCEINLINE constexpr complex_t<V> operator()(V v) const noexcept
{ return KYOSU_CALL(complex(v)); }
{ return (*this)(complex(v)); }

KYOSU_CALLABLE_OBJECT(acsch_t, acsch_);
};
Expand Down Expand Up @@ -69,12 +69,3 @@ namespace kyosu
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto acsch_(KYOSU_DELAY(), O const&, Z z) noexcept
{
Z r = kyosu::rec(z);
return kyosu::asinh(r);
}
}
13 changes: 2 additions & 11 deletions include/kyosu/functions/acscpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }
{ return radinpi(kyosu::acsc(z)); }

template<concepts::real V>
KYOSU_FORCEINLINE constexpr complex_t<V> operator()(V v) const noexcept
{ return KYOSU_CALL(complex(v)); }
{ return (*this)(complex(v)); }

KYOSU_CALLABLE_OBJECT(acscpi_t, acscpi_);
};
Expand Down Expand Up @@ -69,12 +69,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto acscpi_(KYOSU_DELAY(), O const&, Z z) noexcept
{
return radinpi(kyosu::acsc(z));
}
}
23 changes: 6 additions & 17 deletions include/kyosu/functions/airy_ai.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }
{
if constexpr(kyosu::concepts::complex<Z> )
return _::ai(z);
else
return kyosu::_::cayley_extend(*this, z);
}

template<concepts::real V>
KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept
Expand Down Expand Up @@ -64,19 +69,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto airy_ai_(KYOSU_DELAY(), O const&, Z z) noexcept
{
if constexpr(kyosu::concepts::complex<Z> )
{
return ai(z);
}
else
{
return cayley_extend(airy_ai, z);
}
}
}
23 changes: 6 additions & 17 deletions include/kyosu/functions/airy_bi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }
{
if constexpr(kyosu::concepts::complex<Z> )
return _::bi(z);
else
return kyosu::_::cayley_extend(*this, z);
}

template<concepts::real V>
KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept
Expand Down Expand Up @@ -68,19 +73,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto airy_bi_(KYOSU_DELAY(), O const&, Z z) noexcept
{
if constexpr(concepts::complex<Z> )
{
return bi(z);
}
else
{
return cayley_extend(airy_bi, z);
}
}
}
20 changes: 8 additions & 12 deletions include/kyosu/functions/arg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ namespace kyosu
struct arg_t : eve::elementwise_callable<arg_t, Options>
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr as_real_type_t<Z> operator()(Z z) const noexcept { return KYOSU_CALL(z); }
KYOSU_FORCEINLINE constexpr as_real_type_t<Z> operator()(Z v) const noexcept
{
if constexpr(concepts::complex<Z>) return eve::atan2[ eve::pedantic](imag(v), real(v));
else return eve::atan2[ eve::pedantic](eve::sign(imag(v))*abs(pure(v)), real(v));
}

template<concepts::real V>
KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept { return KYOSU_CALL(v); }
KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept {
return eve::if_else(eve::is_positive(v), eve::zero, eve::pi(eve::as(v)));
}

KYOSU_CALLABLE_OBJECT(arg_t, arg_);
};
Expand Down Expand Up @@ -66,13 +72,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}
namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto arg_(KYOSU_DELAY(), O const&, Z const& v) noexcept
{
if constexpr(concepts::complex<Z>) return eve::atan2[ eve::pedantic]( imag(v), real(v));
else if constexpr(concepts::cayley_dickson<Z>) return eve::atan2[ eve::pedantic]( eve::sign(imag(v))*abs(pure(v)), real(v));
else return eve::if_else( eve::is_positive(v), eve::zero, eve::pi(eve::as(v)));
}
}
13 changes: 2 additions & 11 deletions include/kyosu/functions/asec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }
{ return kyosu::acos(kyosu::rec(z)); }

template<concepts::real V>
KYOSU_FORCEINLINE constexpr complex_t<V> operator()(V v) const noexcept
{ return KYOSU_CALL(complex(v)); }
{ return (*this)(complex(v)); }

KYOSU_CALLABLE_OBJECT(asec_t, asec_);
};
Expand Down Expand Up @@ -72,12 +72,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto asec_(KYOSU_DELAY(), O const&, Z z) noexcept
{
return kyosu::acos(kyosu::rec(z));
}
}
Loading

0 comments on commit 7c1dbe5

Please sign in to comment.