def test_dct3_definition_ortho(mdata_x, rdt): # Test orthornomal mode. x = np.array(mdata_x, dtype=rdt) dt = np.result_type(np.float32, rdt) y = dct(x, norm='ortho', type=2) xi = dct(y, norm="ortho", type=3) dec = dec_map[(dct, rdt, 3)] assert_equal(xi.dtype, dt) assert_array_almost_equal(xi, x, decimal=dec)
def test_definition_ortho(self): # Test orthornomal mode. for i in range(len(X)): x = np.array(X[i], dtype=self.rdt) dt = np.result_type(np.float32, self.rdt) y = dct(x, norm='ortho', type=2) xi = dct(y, norm="ortho", type=3) assert_equal(xi.dtype, dt) assert_array_almost_equal(xi, x, decimal=self.dec)
def test_axis(self, rdt, type, size): nt = 2 dec = dec_map[(dct, rdt, type)] x = np.random.randn(nt, size) y = dct(x, type=type) for j in range(nt): assert_array_almost_equal(y[j], dct(x[j], type=type), decimal=dec) x = x.T y = dct(x, axis=0, type=type) for j in range(nt): assert_array_almost_equal(y[:,j], dct(x[:,j], type=type), decimal=dec)
def test_axis(self): nt = 2 for i in [7, 8, 9, 16, 32, 64]: x = np.random.randn(nt, i) y = dct(x, type=self.type) for j in range(nt): assert_array_almost_equal(y[j], dct(x[j], type=self.type), decimal=self.dec) x = x.T y = dct(x, axis=0, type=self.type) for j in range(nt): assert_array_almost_equal(y[:,j], dct(x[:,j], type=self.type), decimal=self.dec)
def test_dct4_definition_ortho(mdata_x, rdt): # Test orthornomal mode. x = np.array(mdata_x, dtype=rdt) dt = np.result_type(np.float32, rdt) y = dct(x, norm='ortho', type=4) y2 = naive_dct4(x, norm='ortho') dec = dec_map[(dct, rdt, 4)] assert_equal(y.dtype, dt) assert_allclose(y, y2, rtol=0., atol=np.max(y2)*10**(-dec))
def test_definition_ortho(self): # Test orthornomal mode. for i in range(len(X)): x = np.array(X[i], dtype=self.rdt) dt = np.result_type(np.float32, self.rdt) y = dct(x, norm='ortho', type=4) y2 = naive_dct4(x, norm='ortho') assert_equal(y.dtype, dt) assert_array_almost_equal(y / np.max(y), y2 / np.max(y), decimal=self.dec)
def test_dct2_definition_matlab(mdata_xy, rdt): # Test correspondence with matlab (orthornomal mode). dt = np.result_type(np.float32, rdt) x = np.array(mdata_xy[0], dtype=dt) yr = mdata_xy[1] y = dct(x, norm="ortho", type=2) dec = dec_map[(dct, rdt, 2)] assert_equal(y.dtype, dt) assert_array_almost_equal(y, yr, decimal=dec)
def test_definition_matlab(self): # Test correspondence with matlab (orthornomal mode). for i in range(len(X)): dt = np.result_type(np.float32, self.rdt) x = np.array(X[i], dtype=dt) yr = Y[i] y = dct(x, norm="ortho", type=2) assert_equal(y.dtype, dt) assert_array_almost_equal(y, yr, decimal=self.dec)
def test_definition(self): for i in FFTWDATA_SIZES: x, yr, dt = fftw_dct_ref(self.type, i, self.rdt) y = dct(x, type=self.type) assert_equal(y.dtype, dt) # XXX: we divide by np.max(y) because the tests fail otherwise. We # should really use something like assert_array_approx_equal. The # difference is due to fftw using a better algorithm w.r.t error # propagation compared to the ones from fftpack. assert_array_almost_equal(y / np.max(y), yr / np.max(y), decimal=self.dec, err_msg="Size %d failed" % i)
def test_definition(self, rdt, type, fftwdata_size): x, yr, dt = fftw_dct_ref(type, fftwdata_size, rdt) y = dct(x, type=type) assert_equal(y.dtype, dt) dec = dec_map[(dct, rdt, type)] assert_allclose(y, yr, rtol=0., atol=np.max(yr)*10**(-dec))
def test_dct_complex(self): y = dct(np.arange(5)*1j) x = 1j*dct(np.arange(5)) assert_array_almost_equal(x, y)
def test_dct_complex64(self): y = dct(1j*np.arange(5, dtype=np.complex64)) x = 1j*dct(np.arange(5)) assert_array_almost_equal(x, y)