Skip to content

Commit

Permalink
gd agd revision + doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlap committed Nov 27, 2024
1 parent a150744 commit c631d03
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 20 deletions.
10 changes: 3 additions & 7 deletions include/kyosu/functions/agd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#pragma once
#include "eve/traits/as_logical.hpp"
#include <kyosu/details/callable.hpp>
#include <kyosu/functions/rec.hpp>
#include <kyosu/functions/log.hpp>
#include <kyosu/functions/tan.hpp>
#include <kyosu/constants/wrapped.hpp>

namespace kyosu
{
Expand All @@ -20,14 +21,9 @@ namespace kyosu
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{
if constexpr(concepts::complex<Z> )
{
auto [rz, iz] = z;
return complex(eve::atanh(eve::sin(rz)/eve::cosh(iz)), eve::atanh(eve::sinh(iz)/eve::cos(rz)));
}
return kyosu::log(kyosu::tan(z*kyosu::half(as(z))+kyosu::pio_4(as(z))));
else
{
return kyosu::_::cayley_extend(*this, z);
}
}

template<concepts::real V>
Expand Down
16 changes: 6 additions & 10 deletions include/kyosu/functions/gd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#pragma once
#include "eve/traits/as_logical.hpp"
#include <kyosu/details/callable.hpp>
#include <kyosu/functions/rec.hpp>
#include <kyosu/functions/tan.hpp>
#include <kyosu/constants/wrapped.hpp>
#include <kyosu/functions/tanh.hpp>
#include <kyosu/functions/atan.hpp>

namespace kyosu
{
Expand All @@ -20,19 +21,14 @@ namespace kyosu
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{
if constexpr(concepts::complex<Z> )
{
auto [rz, iz] = z;
return complex(atan(sinh(rz)/cos(iz)), atan(sin(iz)/cosh(rz)));
}
return 2*kyosu::atan(tanh(z*kyosu::half(as(z))));
else
{
return kyosu::_::cayley_extend(*this, z);
}
}

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

KYOSU_CALLABLE_OBJECT(gd_t, gd_);
};
Expand Down
25 changes: 25 additions & 0 deletions test/doc/agd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <kyosu/kyosu.hpp>
#include <eve/wide.hpp>
#include <iostream>

int main()
{
using kyosu::agd;
using kyosu::complex_t;
using kyosu::quaternion_t;

std::cout << "Real: ";
std::cout << 72.9f << " -> " << agd(72.9f) << "\n";

std::cout << "Complex: ";
std::cout << kyosu::complex_t<float>(3.5f,-2.9f) << " -> " << agd(kyosu::complex_t<float>(3.5f,-2.9f)) << "\n";

std::cout << "Quaternion: ";
std::cout << kyosu::quaternion_t<double>(1.,2.,3.,4.) << " -> " << agd(kyosu::quaternion_t<double>(1.,2.,3.,4.)) << "\n";

std::cout << "SIMD: ";
using wc_t = eve::wide<kyosu::complex_t<double>, eve::fixed<2>>;
std::cout << wc_t(kyosu::complex_t<double>(1.3,-3.7)) << " -> " << agd(wc_t(kyosu::complex_t<double>(1.3,-3.7))) << "\n";

return 0;
}
25 changes: 25 additions & 0 deletions test/doc/gd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <kyosu/kyosu.hpp>
#include <eve/wide.hpp>
#include <iostream>

int main()
{
using kyosu::gd;
using kyosu::complex_t;
using kyosu::quaternion_t;

std::cout << "Real: ";
std::cout << 72.9f << " -> " << gd(72.9f) << "\n";

std::cout << "Complex: ";
std::cout << kyosu::complex_t<float>(3.5f,-2.9f) << " -> " << gd(kyosu::complex_t<float>(3.5f,-2.9f)) << "\n";

std::cout << "Quaternion: ";
std::cout << kyosu::quaternion_t<double>(1.,2.,3.,4.) << " -> " << gd(kyosu::quaternion_t<double>(1.,2.,3.,4.)) << "\n";

std::cout << "SIMD: ";
using wc_t = eve::wide<kyosu::complex_t<double>, eve::fixed<2>>;
std::cout << wc_t(kyosu::complex_t<double>(1.3,-3.7)) << " -> " << gd(wc_t(kyosu::complex_t<double>(1.3,-3.7))) << "\n";

return 0;
}
2 changes: 1 addition & 1 deletion test/unit/function/agd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ TTS_CASE_WITH ( "Check kyosu::agd over real"
<typename T>(T a0, T a1)
{
kyosu::complex_t<T> data(a0, a1);
TTS_RELATIVE_EQUAL(kyosu::gd( kyosu::agd(data)), data, tts::prec<T>(3.e-3, 1.e-6));
TTS_RELATIVE_EQUAL(kyosu::gd( kyosu::agd(data)), data, tts::prec<T>());
};
4 changes: 2 additions & 2 deletions test/unit/function/gd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TTS_CASE_WITH ( "Check kyosu::gd over real"
)
<typename T>(T data)
{
TTS_RELATIVE_EQUAL(kyosu::gd(data), kyosu::complex(eve::gd(data)), tts::prec<T>());
TTS_RELATIVE_EQUAL(kyosu::gd(data), eve::gd(data), tts::prec<T>());
};

TTS_CASE_WITH ( "Check kyosu::gd over real"
Expand All @@ -24,5 +24,5 @@ TTS_CASE_WITH ( "Check kyosu::gd over real"
<typename T>(T a0, T a1)
{
kyosu::complex_t<T> data(a0, a1);
TTS_RELATIVE_EQUAL(kyosu::tanh(kyosu::gd(data/2)), kyosu::tan(kyosu::gd(data)/2), tts::prec<T>(1.0e-1, 1.0e-2));
TTS_RELATIVE_EQUAL(kyosu::tanh(kyosu::gd(data/2)), kyosu::tan(kyosu::gd(data)/2), tts::prec<T>(1.0e-2, 3.0e-4));
};

0 comments on commit c631d03

Please sign in to comment.