def test_bunquantize(self): """Test function for bunquantize() 1/3""" yr = ds.bquantize(self.x) yv = [] y = [] for yi in yr: y += [yi.csd] yv += [yi.val] yv = np.asarray(yv) xres = ds.bunquantize(y) self.assertTrue(np.allclose(xres, yv, atol=1e-8, rtol=1e-5))
def test_bquantize(self): """Test function for bquantize() """ x = np.linspace(-10, 10, 101) y = ds.bquantize(x) yval = [yi.val for yi in y] ycsd = [yi.csd for yi in y] fname = pkg_resources.resource_filename(__name__, "test_data/test_bquantize.mat") s = scipy.io.loadmat(fname)['s'] mval = [] mcsd = [] for i in range(s.shape[1]): mval.append(float(s[0, i][0])) mcsd.append(s[0, i][1]) for i in range(len(mval)): self.assertTrue(np.allclose(mval[i], yval[i], atol=1e-8, rtol=1e-5)) self.assertTrue(np.prod(mcsd[i].shape) + np.prod(ycsd[i].shape) == 0 or \ mcsd[i].shape == ycsd[i].shape) if 0 not in ycsd[i].shape: self.assertTrue(np.allclose(mcsd[i], ycsd[i], atol=1e-8, rtol=1e-5))