Commit 9918b72b by Martin Reinecke

### tweak docstrings; simplify tests

parent ee5193a5
 ... @@ -597,11 +597,18 @@ axes : list of integers ... @@ -597,11 +597,18 @@ axes : list of integers inorm : int inorm : int Normalization type Normalization type 0 : no normalization 0 : no normalization 1 : divide by sqrt(N) 1 : make transform orthogonal and divide by sqrt(N) 2 : divide by N 2 : divide by N where N is the product of n_i for every transformed axis i. where N is the product of n_i for every transformed axis i. n_i is 2*(-1 for type 1 and 2* n_i is 2*(-1 for type 1 and 2* for types 2, 3, 4. for types 2, 3, 4. Making the transform orthogonal involves the following additional steps for every 1D sub-transform: Type 1 : multiply first and last input value by sqrt(2) divide first and last output value by sqrt(2) Type 2 : divide first output value by sqrt(2) Type 3 : multiply first input value by sqrt(2) Type 4 : nothing out : numpy.ndarray (same shape and data type as `a`) out : numpy.ndarray (same shape and data type as `a`) May be identical to `a`, but if it isn't, it must not overlap with `a`. May be identical to `a`, but if it isn't, it must not overlap with `a`. If None, a new array is allocated to store the output. If None, a new array is allocated to store the output. ... @@ -629,11 +636,17 @@ axes : list of integers ... @@ -629,11 +636,17 @@ axes : list of integers inorm : int inorm : int Normalization type Normalization type 0 : no normalization 0 : no normalization 1 : divide by sqrt(N) 1 : make transform orthogonal and divide by sqrt(N) 2 : divide by N 2 : divide by N where N is the product of n_i for every transformed axis i. where N is the product of n_i for every transformed axis i. n_i is 2*(+1 for type 1 and 2* n_i is 2*(+1 for type 1 and 2* for types 2, 3, 4. for types 2, 3, 4. Making the transform orthogonal involves the following additional steps for every 1D sub-transform: Type 1 : nothing Type 2 : divide first output value by sqrt(2) Type 3 : multiply first input value by sqrt(2) Type 4 : nothing out : numpy.ndarray (same shape and data type as `a`) out : numpy.ndarray (same shape and data type as `a`) May be identical to `a`, but if it isn't, it must not overlap with `a`. May be identical to `a`, but if it isn't, it must not overlap with `a`. If None, a new array is allocated to store the output. If None, a new array is allocated to store the output. ... ...
 ... @@ -55,36 +55,27 @@ def irfft_scipy(a, axis, inorm=0, out=None, nthreads=1): ... @@ -55,36 +55,27 @@ def irfft_scipy(a, axis, inorm=0, out=None, nthreads=1): forward=False, inorm=inorm, out=out, forward=False, inorm=inorm, out=out, nthreads=nthreads) nthreads=nthreads) tol = {np.float32: 6e-7, np.float64: 1.5e-15, np.longfloat: 1e-18} ctype = {np.float32: np.complex64, np.float64: np.complex128, np.longfloat: np.longcomplex} @pmp("len", len1D) @pmp("len", len1D) @pmp("inorm", [0, 1, 2]) @pmp("inorm", [0, 1, 2]) def test1D(len, inorm): @pmp("dtype", [np.float32, np.float64, np.longfloat]) def test1D(len, inorm, dtype): a = np.random.rand(len)-0.5 + 1j*np.random.rand(len)-0.5j a = np.random.rand(len)-0.5 + 1j*np.random.rand(len)-0.5j b = a.astype(np.complex64) a = a.astype(ctype[dtype]) c = a.astype(np.complex256) eps = tol[dtype] _assert_close(a, ifftn(fftn(c, inorm=inorm), inorm=2-inorm), 1e-18) assert_(_l2error(a, ifftn(fftn(a, inorm=inorm), inorm=2-inorm)) < eps) assert_(_l2error(a, ifftn(fftn(a, inorm=inorm), inorm=2-inorm)) < 1.5e-15) assert_(_l2error(a.real, ifftn(fftn(a.real, inorm=inorm), inorm=2-inorm)) assert_(_l2error(a.real, ifftn(fftn(a.real, inorm=inorm), inorm=2-inorm)) < 1.5e-15) < eps) assert_(_l2error(a.real, fftn(ifftn(a.real, inorm=inorm), inorm=2-inorm)) assert_(_l2error(a.real, fftn(ifftn(a.real, inorm=inorm), inorm=2-inorm)) < 1.5e-15) < eps) assert_(_l2error(a.real, irfftn(rfftn(a.real, inorm=inorm), assert_(_l2error(a.real, irfftn(rfftn(a.real, inorm=inorm), inorm=2-inorm, lastsize=len)) < 1.5e-15) inorm=2-inorm, lastsize=len)) < eps) tmp = a.copy() tmp = a.copy() assert_(ifftn(fftn(tmp, out=tmp, inorm=inorm), out=tmp, inorm=2-inorm) assert_(ifftn(fftn(tmp, out=tmp, inorm=inorm), out=tmp, inorm=2-inorm) is tmp) is tmp) assert_(_l2error(tmp, a) < 1.5e-15) assert_(_l2error(tmp, a) < eps) assert_(_l2error(b, ifftn(fftn(b, inorm=inorm), inorm=2-inorm)) < 6e-7) assert_(_l2error(b.real, ifftn(fftn(b.real, inorm=inorm), inorm=2-inorm)) < 6e-7) assert_(_l2error(b.real, fftn(ifftn(b.real, inorm=inorm), inorm=2-inorm)) < 6e-7) assert_(_l2error(b.real, irfftn(rfftn(b.real, inorm=inorm), lastsize=len, inorm=2-inorm)) < 6e-7) tmp = b.copy() assert_(ifftn(fftn(tmp, out=tmp, inorm=inorm), out=tmp, inorm=2-inorm) is tmp) assert_(_l2error(tmp, b) < 6e-7) @pmp("shp", shapes) @pmp("shp", shapes) ... @@ -206,54 +197,17 @@ def test_genuine_hartley_2D(shp, axes): ... @@ -206,54 +197,17 @@ def test_genuine_hartley_2D(shp, axes): @pmp("len", len1D) @pmp("len", len1D) @pmp("inorm", [0, 1, 2]) @pmp("inorm", [0, 1]) # inorm==2 not needed, tested via inverse @pmp("type", [1, 2, 3]) @pmp("type", [1, 2, 3, 4]) def testdcst1D(len, inorm, type): @pmp("dtype", [np.float32, np.float64, np.longfloat]) a = np.random.rand(len)-0.5 def testdcst1D(len, inorm, type, dtype): b = a.astype(np.float32) a = (np.random.rand(len)-0.5).astype(dtype) c = a.astype(np.float128) eps = tol[dtype] itp = (0, 1, 3, 2, 4) itype = itp[type] if type != 1 or len > 1: _assert_close(a, pypocketfft.dct(pypocketfft.dct(c, inorm=inorm, type=type), inorm=2-inorm, type=itype), 2e-18) _assert_close(a, pypocketfft.dct(pypocketfft.dct(a, inorm=inorm, type=type), inorm=2-inorm, type=itype), 1.5e-15) _assert_close(b, pypocketfft.dct(pypocketfft.dct(b, inorm=inorm, type=type), inorm=2-inorm, type=itype), 6e-7) _assert_close(a, pypocketfft.dst(pypocketfft.dst(c, inorm=inorm, type=type), inorm=2-inorm, type=itype), 2e-18) _assert_close(a, pypocketfft.dst(pypocketfft.dst(a, inorm=inorm, type=type), inorm=2-inorm, type=itype), 1.5e-15) _assert_close(b, pypocketfft.dst(pypocketfft.dst(b, inorm=inorm, type=type), inorm=2-inorm, type=itype), 6e-7) @pmp("len", len1D) @pmp("type", [1, 2, 3]) def testdcst1Dortho(len, type): a = np.random.rand(len)-0.5 b = a.astype(np.float32) c = a.astype(np.float128) itp = (0, 1, 3, 2, 4) itype = itp[type] if type != 1 or len > 1: _assert_close(a, pypocketfft.dct(pypocketfft.dct(c, inorm=1, type=type), inorm=1, type=itype), 2e-18) _assert_close(a, pypocketfft.dct(pypocketfft.dct(a, inorm=1, type=type), inorm=1, type=itype), 1.5e-15) _assert_close(b, pypocketfft.dct(pypocketfft.dct(b, inorm=1, type=type), inorm=1, type=itype), 6e-7) if type != 1: _assert_close(a, pypocketfft.dst(pypocketfft.dst(c, inorm=1, type=type), inorm=1, type=itype), 2e-18) _assert_close(a, pypocketfft.dst(pypocketfft.dst(a, inorm=1, type=type), inorm=1, type=itype), 1.5e-15) _assert_close(b, pypocketfft.dst(pypocketfft.dst(b, inorm=1, type=type), inorm=1, type=itype), 6e-7) # TEMPORARY: separate test for DCT/DST IV, since they are less accurate @pmp("len", len1D) @pmp("inorm", [0, 1, 2]) @pmp("type", [4]) def testdcst1D4(len, inorm, type): a = np.random.rand(len)-0.5 b = a.astype(np.float32) c = a.astype(np.float128) itp = (0, 1, 3, 2, 4) itp = (0, 1, 3, 2, 4) if type==4 and len%2 == 1: # relaxed accuracies for odd-length type 4 transforms special_tol = {np.float32: 4e-5, np.float64: 6e-14, np.longfloat: 4e-17} eps = special_tol[dtype] itype = itp[type] itype = itp[type] if type != 1 or len > 1: if type != 1 or len > 1: # there are no length-1 type 1 DCTs _assert_close(a, pypocketfft.dct(pypocketfft.dct(c, inorm=inorm, type=type), inorm=2-inorm, type=itype), 2e-16) _assert_close(a, pypocketfft.dct(pypocketfft.dct(a, inorm=inorm, type=type), inorm=2-inorm, type=itype), eps) _assert_close(a, pypocketfft.dct(pypocketfft.dct(a, inorm=inorm, type=type), inorm=2-inorm, type=itype), 1.5e-13) _assert_close(a, pypocketfft.dst(pypocketfft.dst(a, inorm=inorm, type=type), inorm=2-inorm, type=itype), eps) _assert_close(b, pypocketfft.dct(pypocketfft.dct(b, inorm=inorm, type=type), inorm=2-inorm, type=itype), 6e-5) _assert_close(a, pypocketfft.dst(pypocketfft.dst(c, inorm=inorm, type=type), inorm=2-inorm, type=itype), 2e-16) _assert_close(a, pypocketfft.dst(pypocketfft.dst(a, inorm=inorm, type=type), inorm=2-inorm, type=itype), 1.5e-13) _assert_close(b, pypocketfft.dst(pypocketfft.dst(b, inorm=inorm, type=type), inorm=2-inorm, type=itype), 6e-5)
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