-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements manhattan, lpnorm and hypot
- Loading branch information
Showing
11 changed files
with
534 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//====================================================================================================================== | ||
/* | ||
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_hypot : eve::elementwise | ||
{ | ||
using callable_tag_type = callable_hypot; | ||
|
||
KYOSU_DEFERS_CALLABLE(hypot_); | ||
|
||
static KYOSU_FORCEINLINE auto deferred_call(auto | ||
, eve::ordered_value auto const&... vs) noexcept | ||
{ | ||
return eve::hypot(vs...); | ||
} | ||
|
||
KYOSU_FORCEINLINE auto operator()(auto const&... targets ) const noexcept | ||
-> decltype(eve::tag_invoke(*this, targets...)) | ||
{ | ||
return eve::tag_invoke(*this, targets...); | ||
} | ||
|
||
// template<typename... T> | ||
// eve::unsupported_call<callable_hypot(T&&...)> operator()(T&&... x) const | ||
// requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; | ||
}; | ||
} | ||
|
||
namespace kyosu | ||
{ | ||
//====================================================================================================================== | ||
//! @addtogroup functions | ||
//! @{ | ||
//! @var hypot | ||
//! @brief Callable object computing the hypot operation. | ||
//! | ||
//! **Defined in Header** | ||
//! | ||
//! @code | ||
//! #include <kyosu/functions.hpp> | ||
//! @endcode | ||
//! | ||
//! @groupheader{Callable Signatures} | ||
//! | ||
//! @code | ||
//! namespace kyosu | ||
//! { | ||
//! template< floating_value P, typename ... Ts> | ||
//! auto operator()(Ts ... zi ) const noexcept | ||
///! } | ||
//! @endcode | ||
//! | ||
//! **Parameters** | ||
//! | ||
//! * ` zi...` : Values to process. | ||
//! | ||
//! **Return value** | ||
//! | ||
//! Returns \f$ \sqrt\sum_{i = 0}^n//! |z_i|^2} \f$. | ||
//! | ||
//! @groupheader{Example} | ||
//! | ||
//! @godbolt{doc/hypot.cpp} | ||
//! @} | ||
//====================================================================================================================== | ||
inline constexpr tags::callable_hypot hypot = {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_lpnorm : eve::elementwise | ||
{ | ||
using callable_tag_type = callable_lpnorm; | ||
|
||
KYOSU_DEFERS_CALLABLE(lpnorm_); | ||
|
||
static KYOSU_FORCEINLINE auto deferred_call(auto | ||
, eve::floating_value auto const& p | ||
, eve::floating_ordered_value auto const&... vs) noexcept | ||
{ | ||
return eve::lpnorm(p, vs...); | ||
} | ||
|
||
KYOSU_FORCEINLINE auto operator()(auto const&... targets ) const noexcept | ||
-> decltype(eve::tag_invoke(*this, targets...)) | ||
{ | ||
return eve::tag_invoke(*this, targets...); | ||
} | ||
|
||
template<typename... T> | ||
eve::unsupported_call<callable_lpnorm(T&&...)> operator()(T&&... x) const | ||
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; | ||
}; | ||
} | ||
|
||
namespace kyosu | ||
{ | ||
//====================================================================================================================== | ||
//! @addtogroup functions | ||
//! @{ | ||
//! @var lpnorm | ||
//! @brief Callable object computing the lpnorm operation \f$ \left(\sum_{i = 0}^n | ||
//! |x_i|^p\right)^{\frac1p} \f$. | ||
//! | ||
//! **Defined in Header** | ||
//! | ||
//! @code | ||
//! #include <kyosu/functions.hpp> | ||
//! @endcode | ||
//! | ||
//! @groupheader{Callable Signatures} | ||
//! | ||
//! @code | ||
//! namespace kyosu | ||
//! { | ||
//! template< floating_value P, typename T, typename ... Ts> | ||
//! auto operator()(P p, T z,Ts ... zs ) const noexcept | ||
///! } | ||
//! @endcode | ||
//! | ||
//! **Parameters** | ||
//! | ||
//! * `z, zs...` : Values to process. | ||
//! | ||
//! **Return value** | ||
//! | ||
//! Returns \f$ \left(\sum_{i = 0}^n//! |x_i|^p\right)^{\frac1p} \f$. | ||
//! | ||
//! @groupheader{Example} | ||
//! | ||
//! @godbolt{doc/lpnorm.cpp} | ||
//! @} | ||
//====================================================================================================================== | ||
inline constexpr tags::callable_lpnorm lpnorm = {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//====================================================================================================================== | ||
/* | ||
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_manhattan : eve::elementwise | ||
{ | ||
using callable_tag_type = callable_manhattan; | ||
|
||
KYOSU_DEFERS_CALLABLE(manhattan_); | ||
|
||
static KYOSU_FORCEINLINE auto deferred_call(auto | ||
, eve::ordered_value auto const&... vs) noexcept | ||
{ | ||
return eve::manhattan(vs...); | ||
} | ||
|
||
KYOSU_FORCEINLINE auto operator()(auto const&... targets ) const noexcept | ||
-> decltype(eve::tag_invoke(*this, targets...)) | ||
{ | ||
return eve::tag_invoke(*this, targets...); | ||
} | ||
|
||
// template<typename... T> | ||
// eve::unsupported_call<callable_manhattan(T&&...)> operator()(T&&... x) const | ||
// requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; | ||
}; | ||
} | ||
|
||
namespace kyosu | ||
{ | ||
//====================================================================================================================== | ||
//! @addtogroup functions | ||
//! @{ | ||
//! @var manhattan | ||
//! @brief Callable object computing the manhattan operation. | ||
//! | ||
//! **Defined in Header** | ||
//! | ||
//! @code | ||
//! #include <kyosu/functions.hpp> | ||
//! @endcode | ||
//! | ||
//! @groupheader{Callable Signatures} | ||
//! | ||
//! @code | ||
//! namespace kyosu | ||
//! { | ||
//! template< floating_value P, typename ... Ts> | ||
//! auto operator()(Ts ... zi ) const noexcept | ||
///! } | ||
//! @endcode | ||
//! | ||
//! **Parameters** | ||
//! | ||
//! * ` zi...` : Values to process. | ||
//! | ||
//! **Return value** | ||
//! | ||
//! Returns the sum of the absolute values of all elements of all zi. | ||
//! | ||
//! @groupheader{Example} | ||
//! | ||
//! @godbolt{doc/manhattan.cpp} | ||
//! @} | ||
//====================================================================================================================== | ||
inline constexpr tags::callable_manhattan manhattan = {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <kyosu/kyosu.hpp> | ||
#include <eve/wide.hpp> | ||
#include <iostream> | ||
|
||
int main() | ||
{ | ||
using kyosu::hypot; | ||
using kyosu::complex; | ||
using kyosu::quaternion; | ||
using e_t = float; | ||
using c_t = complex<float>; | ||
using q_t = quaternion<float>; | ||
using we_t = eve::wide<float, eve::fixed<2>>; | ||
using wc_t = eve::wide<complex<float>, eve::fixed<2>>; | ||
using wq_t = eve::wide<quaternion<float>, eve::fixed<2>>; | ||
|
||
std::cout << "Real: "<< "\n"; | ||
e_t e0(1); | ||
e_t e1(2); | ||
std::cout << e0 << ", " << e1 << " -> " << hypot(e0, e1) << "\n"; | ||
we_t we0(e0); | ||
we_t we1(e1); | ||
std::cout << we0 << ", " << we1 << " -> " << hypot(we0, we1) << "\n"; | ||
|
||
std::cout << "Complex: "<< "\n"; | ||
c_t c0(5); | ||
c_t c1(5, 9); | ||
std::cout << c0 << ", " << c1 << " -> " << hypot(c0, c1) << "\n"; | ||
wc_t wc0(c0); | ||
wc_t wc1(c1); | ||
std::cout << wc0 << ", " << wc1 << " -> " << hypot(wc0, wc1) << "\n"; | ||
|
||
std::cout << "Quaternion: "<< "\n"; | ||
q_t q0(5, 2, 3); | ||
q_t q1(5, 9, 6, 7); | ||
std::cout << q0 << ", " << q1 << " -> " << hypot(q0, q1) << "\n"; | ||
wq_t wq0(q0); | ||
wq_t wq1(q1); | ||
std::cout << wq0 << ", " << wq1 << " -> " << hypot(wq0, wq1) << "\n"; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <kyosu/kyosu.hpp> | ||
#include <eve/wide.hpp> | ||
#include <iostream> | ||
|
||
int main() | ||
{ | ||
using kyosu::lpnorm; | ||
using kyosu::complex; | ||
using kyosu::quaternion; | ||
using e_t = float; | ||
using c_t = complex<float>; | ||
using q_t = quaternion<float>; | ||
using we_t = eve::wide<float, eve::fixed<2>>; | ||
using wc_t = eve::wide<complex<float>, eve::fixed<2>>; | ||
using wq_t = eve::wide<quaternion<float>, eve::fixed<2>>; | ||
|
||
std::cout << "Real: "<< "\n"; | ||
e_t e0(1); | ||
e_t e1(2); | ||
std::cout << e0 << ", " << e1 << " -> " << lpnorm(e_t(1), e0, e1) << "\n"; | ||
we_t we0(e0); | ||
we_t we1(e1); | ||
std::cout << we0 << ", " << we1 << " -> " << lpnorm(e_t(1), we0, we1) << "\n"; | ||
|
||
std::cout << "Complex: "<< "\n"; | ||
c_t c0(e_t(1), 5); | ||
c_t c1(5, 9); | ||
std::cout << c0 << ", " << c1 << " -> " << lpnorm(e_t(1), c0, c1) << "\n"; | ||
wc_t wc0(c0); | ||
wc_t wc1(c1); | ||
std::cout << wc0 << ", " << wc1 << " -> " << lpnorm(e_t(1), wc0, wc1) << "\n"; | ||
|
||
std::cout << "Quaternion: "<< "\n"; | ||
q_t q0(e_t(1), 5, 2, 3); | ||
q_t q1(5, 9, 6, 7); | ||
std::cout << q0 << ", " << q1 << " -> " << lpnorm(e_t(1), q0, q1) << "\n"; | ||
wq_t wq0(q0); | ||
wq_t wq1(q1); | ||
std::cout << wq0 << ", " << wq1 << " -> " << lpnorm(e_t(1), wq0, wq1) << "\n"; | ||
|
||
return 0; | ||
} |
Oops, something went wrong.