Skip to content

Commit

Permalink
some cleaning and retblishing ASSERTS with an with_alloca modif
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlap committed Dec 13, 2023
1 parent a37b011 commit 901fffc
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 685 deletions.
20 changes: 13 additions & 7 deletions include/kyosu/details/with_alloca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@
namespace kyosu::_
{

template<typename T, std::invocable<T*> F>
template<typename T, std::invocable<std::span<T>> F>
decltype(auto) with_alloca(auto size, F f)
{
T* p = (T*)(__builtin_alloca_with_align(size*sizeof(T), 8*alignof(T)));
return f(p);
auto s = std::span(p, size);
return f(s);
}

template<typename T, typename F>
requires(std::invocable<F, T*, T*>)
decltype(auto) with_alloca(auto size, F f)

template<typename T, std::invocable<std::span<T>, std::span<T>> F>
decltype(auto) with_alloca(auto size, F f)
{
T* p1 = (T*)(__builtin_alloca_with_align(size*sizeof(T), 8*alignof(T)));
T* p2 = (T*)(__builtin_alloca_with_align(size*sizeof(T), 8*alignof(T)));
return f(p1, p2);
auto s1 = std::span(p1, size);
auto s2 = std::span(p2, size);
return f(s1, s2);
}




}
5 changes: 4 additions & 1 deletion include/kyosu/types/impl/bessel/cb_hn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ namespace kyosu::_
template<eve::integral_scalar_value N, typename Z, typename R> KYOSU_FORCEINLINE
auto cb_h12n(N n, Z z, R & h1s, R& h2s) noexcept
{
auto an = abs(n);
EVE_ASSERT(std::size(cjv) > size_t(an), "not room enough in js");
EVE_ASSERT(std::size(cyv) > size_t(an), "not room enough in ys");
cb_jyn(n, z, h1s, h2s);
for(int i=0; i <= eve::abs(n+1); ++i)
for(int i=0; i <= an; ++i)
{
auto miyst = muli(h2s[i]);
h2s[i] = h1s[i]-miyst;
Expand Down
18 changes: 11 additions & 7 deletions include/kyosu/types/impl/bessel/cb_ikn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,18 @@ namespace kyosu::_
//===-------------------------------------------------------------------------------------------
// cb_ikn
//===-------------------------------------------------------------------------------------------
template<eve::integral_scalar_value N, typename Z, typename R> KYOSU_FORCEINLINE
auto cb_ikn(N n, Z z, R& is, R& ks) noexcept
template<eve::integral_scalar_value N, typename Z, typename R1, typename R2> KYOSU_FORCEINLINE
auto cb_ikn(N n, Z z, R1& is, R2& ks) noexcept
requires(concepts::complex<Z> || eve::floating_ordered_value<Z>)
{
using u_t = eve::underlying_type_t<Z>;
auto nn = eve::abs(n);
EVE_ASSERT(N(size(is)) > nn, "not room enough in is");
EVE_ASSERT(N(size(ks)) > nn, "not room enough in ks");

for(int j=0; j <= nn; ++j)
for(N j=0; j <= nn; ++j)
{
is[j] = cb_in(j, z);
is[j] = cb_in(j, z);
ks[j] = cb_kn(j, z);
}
return kumi::tuple{is[n], ks[n]};
Expand Down Expand Up @@ -250,10 +252,12 @@ namespace kyosu::_
//===-------------------------------------------------------------------------------------------
// cyl_bessel_ikn
//===-------------------------------------------------------------------------------------------
template<eve::integral_scalar_value N, kyosu::concepts::complex Z, typename R>
auto dispatch(eve::tag_of<kyosu::cyl_bessel_ikn>, N n, Z z, R& js, R& ys) noexcept
template<eve::integral_scalar_value N, kyosu::concepts::complex Z, typename R1, typename R2>
auto dispatch(eve::tag_of<kyosu::cyl_bessel_ikn>, N n, Z z, R1& is, R2& ks) noexcept
requires(concepts::complex<Z>)
{
return cb_ikn(n, z, js, ys);
EVE_ASSERT(N(size(is)) > abs(n), "not room enough in is");
EVE_ASSERT(N(size(ks)) > abs(n), "not room enough in ks");
return cb_ikn(n, z, is, ks);
}
}
6 changes: 3 additions & 3 deletions include/kyosu/types/impl/bessel/cb_jyn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@ namespace kyosu::_
auto cb_jyn(N nn, Z z, R1& cjv, R2& cyv) noexcept
requires(concepts::complex<Z> || eve::floating_ordered_value<Z>)
{
// EVE_ASSERT(size(cjv) > nn, "not room enough in js");
// EVE_ASSERT(size(cyv) > nn, "not room enough in ys");
using u_t = eve::underlying_type_t<Z>;
auto n = eve::abs(nn);
EVE_ASSERT(N(size(cjv)) > n, "not room enough in cjv");
EVE_ASSERT(N(size(cyv)) > n, "not room enough in cyv");
using u_t = eve::underlying_type_t<Z>;
if (n <= 1)
{
cjv[0] = cyl_bessel_j0(z);
Expand Down
8 changes: 6 additions & 2 deletions include/kyosu/types/impl/bessel/sb_ikn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace kyosu::_
template<eve::integral_scalar_value N, typename Z, typename R> KYOSU_FORCEINLINE
auto sb_i1n(N n, Z z, R & sys) noexcept
{
EVE_ASSERT(N(size(sys)) > n, "not enough room in sys");
using e_t = as_real_type_t<Z>;
return riton<e_t>(n)*sph_bessel_yn(n,muli(z), sys);
}
Expand All @@ -115,9 +116,10 @@ namespace kyosu::_
return -eve::pio_2(eve::as<u_t>())*iton(n)*sph_bessel_h1n(n, complex(-imag(z), real(z)));
}

template<typename Z, typename R> KYOSU_FORCEINLINE
auto sb_kn(int n, Z z, R& sks) noexcept
template<eve::integral_scalar_value N, typename Z, typename R> KYOSU_FORCEINLINE
auto sb_kn(N n, Z z, R& sks) noexcept
{
EVE_ASSERT(N(size(sks)) > n, "not enough room in sks");
using u_t = eve::underlying_type_t<Z>;
auto iton = [](int n){
if (n%4 == 0) return complex(eve::one(eve::as<u_t>()));
Expand All @@ -132,6 +134,8 @@ namespace kyosu::_
template<typename Z, typename R1, typename R2> KYOSU_FORCEINLINE
auto sb_ikn(int n, Z z, R1& sis, R2& sks) noexcept
{
EVE_ASSERT(N(size(sis)) > n, "not enough room in sis");
EVE_ASSERT(N(size(sks)) > n, "not enough room in sks");
sb_i1n(n, z, sis);
sb_kn(n, z, sks);
return kumi::tuple{sis[n], sks[n]};
Expand Down
3 changes: 2 additions & 1 deletion include/kyosu/types/impl/bessel/sb_jyn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ namespace kyosu::_
return if_else(is_eqz(z), eve::zero, res);
}

template<eve::integral_scalar_value N, typename Z, typename R> KYOSU_FORCEINLINE
template<eve::integral_scalar_value N, typename Z, typename R>
auto sb_jn(N n, Z z, R & sjs) noexcept
{
EVE_ASSERT(N(size(sjs)) > n, "not enough room in js");
using u_t = eve::underlying_type_t<Z>;
auto bd = [z](int n){
auto st = eve::abs(eve::sin(eve::abs(arg(z))));
Expand Down
13 changes: 8 additions & 5 deletions include/kyosu/types/impl/besselr/cb_h.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ namespace kyosu::_
//===-------------------------------------------------------------------------------------------
// cb_h12
//===-------------------------------------------------------------------------------------------
template<eve::floating_scalar_value N, typename Z, typename R> KYOSU_FORCEINLINE
auto cb_h12(N n, Z z, R & h1s, R& h2s) noexcept
template<eve::floating_scalar_value N, typename Z, typename R1, typename R2> KYOSU_FORCEINLINE
auto cb_h12(N n, Z z, R1 & h1s, R2 & h2s) noexcept
{
auto an = int(eve::abs(n));
EVE_ASSERT(int(size(h1s)) > an, "not enough room in h1s");
EVE_ASSERT(int(size(h2s)) > an, "not enough room in h2s");
cb_jy(n, z, h1s, h2s);
for(int i=0; i <= eve::abs(n+1); ++i)
for(int i=0; i <= an; ++i)
{
auto miyst = muli(h2s[i]);
h2s[i] = h1s[i]-miyst;
Expand Down Expand Up @@ -72,8 +75,8 @@ namespace kyosu::_
//===-------------------------------------------------------------------------------------------
// cyl_bessel_h12
//===-------------------------------------------------------------------------------------------
template<eve::floating_scalar_value N, kyosu::concepts::complex Z, typename R>
auto dispatch(eve::tag_of<kyosu::cyl_bessel_h12>, N n, Z z, R& h1s, R& h2s) noexcept
template<eve::floating_scalar_value N, kyosu::concepts::complex Z, typename R1, typename R2>
auto dispatch(eve::tag_of<kyosu::cyl_bessel_h12>, N n, Z z, R1& h1s, R2& h2s) noexcept
requires(concepts::complex<Z>)
{
return cb_h12(n, z, h1s, h2s);
Expand Down
1 change: 1 addition & 0 deletions include/kyosu/types/impl/besselr/cb_ikr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace kyosu::_
v = eve::abs(v); //k(-v, z) == K(v, z) DLMF 10.27.1
using u_t = eve::underlying_type_t<Z>;
auto n = int(v); //n>= 0
EVE_ASSERT(int(size(ks)) > n, "not enough room in h1s");
auto v0 = v-n;
auto vi = v0;
for(int j=0; j <= n; ++j)
Expand Down
14 changes: 7 additions & 7 deletions include/kyosu/types/impl/besselr/cb_jyr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace kyosu::_
{
int n = int(v);
int an = eve::abs(n);
// EVE_ASSERT(size(cjv) > an, "not enough room in js");
// EVE_ASSERT(size(cyv) > an, "not enough room in ys");
EVE_ASSERT(int(size(cjv)) > an, "not enough room in cjv");
EVE_ASSERT(int(size(cyv)) > an, "not enough room in cyv");
if (eve::is_flint(v))
{
return cb_jyn(int(v), z, cjv, cyv);
Expand Down Expand Up @@ -100,7 +100,7 @@ namespace kyosu::_
}
return cjv[n];
};

// compute j_{v+i} i = 2...n
Z r;
auto notdone = eve::true_(as<Z>());
Expand All @@ -109,7 +109,7 @@ namespace kyosu::_
{
last_interval(backward, notdone, r);
}

// compute y_{v+i} i = 2...n
auto twoopiz = twoopi*rz;
auto fouropisqz = 2*twoopiz*rz;
Expand Down Expand Up @@ -142,8 +142,8 @@ namespace kyosu::_
//===-------------------------------------------------------------------------------------------
// cyl_bessel_jy
//===-------------------------------------------------------------------------------------------
template<eve::floating_scalar_value N, kyosu::concepts::complex Z, typename R>
auto dispatch(eve::tag_of<kyosu::cyl_bessel_jy>, N v, Z z, R& js, R& ys) noexcept
template<eve::floating_scalar_value N, kyosu::concepts::complex Z, typename R1, typename R2>
auto dispatch(eve::tag_of<kyosu::cyl_bessel_jy>, N v, Z z, R1& js, R2& ys) noexcept
{
return cb_jy(v, z, js, ys);
}
Expand Down Expand Up @@ -200,7 +200,7 @@ namespace kyosu::_
//===-------------------------------------------------------------------------------------------
// cyl_bessel_y
//===-------------------------------------------------------------------------------------------
template<eve::floating_scalar_value N, typename Z>
template<eve::floating_scalar_value N, typename Z>
auto dispatch(eve::tag_of<kyosu::cyl_bessel_y>, N v, Z z) noexcept
{
auto n = int(abs(v))+1;
Expand Down
60 changes: 0 additions & 60 deletions include/kyosu/types/impl/detail/bessel_jr.hpp

This file was deleted.

Loading

0 comments on commit 901fffc

Please sign in to comment.