Commit 12f9cf44 authored by Martin Reinecke's avatar Martin Reinecke

add type I DCTs/DSTs; performance is suboptimal, but accuracy is good

parent 514e1afb
This diff is collapsed.
......@@ -97,7 +97,7 @@ template<typename T> T norm_fct(int inorm, const shape_t &shape,
if (inorm==0) return T(1);
size_t N(1);
for (auto a: axes)
N *= size_t(int64_t(shape[a]*fct)+delta);
N *= fct * size_t(int64_t(shape[a])+delta);
return norm_fct<T>(inorm, N);
}
......@@ -239,12 +239,10 @@ template<typename T> py::array r2r_dct_internal(const py::array &in,
auto d_out=reinterpret_cast<T *>(res.mutable_data());
{
py::gil_scoped_release release;
if ((type==2)||(type==3))
{
T fct = norm_fct<T>(inorm, dims, axes, 2);
pocketfft::r2r_dct(dims, s_in, s_out, axes, type, d_in, d_out, fct,
nthreads);
}
T fct = (type==1) ? norm_fct<T>(inorm, dims, axes, 2, -1)
: norm_fct<T>(inorm, dims, axes, 2);
pocketfft::r2r_dct(dims, s_in, s_out, axes, type, d_in, d_out, fct,
nthreads);
}
return res;
}
......@@ -253,7 +251,6 @@ py::array r2r_dct(const py::array &in, int type, const py::object &axes_,
int inorm, py::object &out_, size_t nthreads)
{
if ((type<1) || (type>4)) throw runtime_error("invalid DCT type");
if ((type==1) || (type==4)) throw runtime_error("DCT type not yet supported ");
DISPATCH(in, f64, f32, flong, r2r_dct_internal, (in, axes_, type, inorm,
out_, nthreads))
}
......@@ -271,12 +268,10 @@ template<typename T> py::array r2r_dst_internal(const py::array &in,
auto d_out=reinterpret_cast<T *>(res.mutable_data());
{
py::gil_scoped_release release;
if ((type==2)||(type==3))
{
T fct = norm_fct<T>(inorm, dims, axes, 2);
pocketfft::r2r_dst(dims, s_in, s_out, axes, type, d_in, d_out, fct,
nthreads);
}
T fct = (type==1) ? norm_fct<T>(inorm, dims, axes, 2, 1)
: norm_fct<T>(inorm, dims, axes, 2);
pocketfft::r2r_dst(dims, s_in, s_out, axes, type, d_in, d_out, fct,
nthreads);
}
return res;
}
......@@ -285,7 +280,6 @@ py::array r2r_dst(const py::array &in, int type, const py::object &axes_,
int inorm, py::object &out_, size_t nthreads)
{
if ((type<1) || (type>4)) throw runtime_error("invalid DST type");
if ((type==1) || (type==4)) throw runtime_error("DST type not yet supported ");
DISPATCH(in, f64, f32, flong, r2r_dst_internal, (in, axes_, type, inorm,
out_, nthreads))
}
......
......@@ -207,13 +207,17 @@ def test_genuine_hartley_2D(shp, axes):
@pmp("len", len1D)
@pmp("inorm", [0, 1, 2])
def testdcst1D(len, inorm):
@pmp("type", [1, 2, 3])
def testdcst1D(len, inorm, type):
a = np.random.rand(len)-0.5
b = a.astype(np.float32)
c = a.astype(np.float128)
_assert_close(a, pypocketfft.r2r_dct(pypocketfft.r2r_dct(c, inorm=inorm, type=2), inorm=2-inorm, type=3), 2e-18)
_assert_close(a, pypocketfft.r2r_dct(pypocketfft.r2r_dct(a, inorm=inorm, type=2), inorm=2-inorm, type=3), 1.5e-15)
_assert_close(b, pypocketfft.r2r_dct(pypocketfft.r2r_dct(b, inorm=inorm, type=2), inorm=2-inorm, type=3), 6e-7)
_assert_close(a, pypocketfft.r2r_dst(pypocketfft.r2r_dst(c, inorm=inorm, type=2), inorm=2-inorm, type=3), 2e-18)
_assert_close(a, pypocketfft.r2r_dst(pypocketfft.r2r_dst(a, inorm=inorm, type=2), inorm=2-inorm, type=3), 1.5e-15)
_assert_close(b, pypocketfft.r2r_dst(pypocketfft.r2r_dst(b, inorm=inorm, type=2), inorm=2-inorm, type=3), 6e-7)
itp = (0, 1, 3, 2, 4)
itype = itp[type]
if type != 1 or len > 1:
_assert_close(a, pypocketfft.r2r_dct(pypocketfft.r2r_dct(c, inorm=inorm, type=type), inorm=2-inorm, type=itype), 2e-18)
_assert_close(a, pypocketfft.r2r_dct(pypocketfft.r2r_dct(a, inorm=inorm, type=type), inorm=2-inorm, type=itype), 1.5e-15)
_assert_close(b, pypocketfft.r2r_dct(pypocketfft.r2r_dct(b, inorm=inorm, type=type), inorm=2-inorm, type=itype), 6e-7)
_assert_close(a, pypocketfft.r2r_dst(pypocketfft.r2r_dst(c, inorm=inorm, type=type), inorm=2-inorm, type=itype), 2e-18)
_assert_close(a, pypocketfft.r2r_dst(pypocketfft.r2r_dst(a, inorm=inorm, type=type), inorm=2-inorm, type=itype), 1.5e-15)
_assert_close(b, pypocketfft.r2r_dst(pypocketfft.r2r_dst(b, inorm=inorm, type=type), inorm=2-inorm, type=itype), 6e-7)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment