def remove_rep(self, newdimname="AllReps"): out = DataBlock() out.comments = self.comments dims = [x for x in self.ivardata.values() if isinstance(x, DimRep)] fullshape = tuple(x.data.shape[0] for x in dims) newdim = DimRep(newdimname, np.arange(np.multiply.reduce(fullshape))) for idx, dim in enumerate(dims): data = zeros(fullshape, dtype=dims[idx].data.dtype) a = hfarray(data, dims=dims) sliceidx = ((None,) * idx + (slice(None),) + (None,) * (len(fullshape) - 1 - idx)) a[...] = dim.data[sliceidx] a = np.array(a, copy=False) a.shape = (newdim.data.shape[0],) out[dim.name] = hfarray(a, dims=(newdim,)) for x in self.vardata: out[x] = remove_rep(self[x], newdimname) return out
def remove_rep(self, newdimname="AllReps"): out = DataBlock() out.comments = self.comments dims = [x for x in self.ivardata.values() if isinstance(x, DimRep)] fullshape = tuple(x.data.shape[0] for x in dims) newdim = DimRep(newdimname, np.arange(np.multiply.reduce(fullshape))) for idx, dim in enumerate(dims): data = zeros(fullshape, dtype=dims[idx].data.dtype) a = hfarray(data, dims=dims) sliceidx = ((None, ) * idx + (slice(None), ) + (None, ) * (len(fullshape) - 1 - idx)) a[...] = dim.data[sliceidx] a = np.array(a, copy=False) a.shape = (newdim.data.shape[0], ) out[dim.name] = hfarray(a, dims=(newdim, )) for x in self.vardata: out[x] = remove_rep(self[x], newdimname) return out
def test_4(self): d = aobj.remove_rep(self.d) self.assertAllclose(d, 0) dims = (ds.DimSweep("f", 2), ds.DimRep("AllReps", 12), ds.DimMatrix_i("i", 5), ds.DimMatrix_j("j", 5),) self.assertEqual(d.dims, dims)
def test_3(self): c = aobj.remove_rep(self.c) self.assertAllclose(c, 0) dims = (ds.DimSweep("f", 2), ds.DimSweep("Vg", 3), ds.DimRep("AllReps", 4)) self.assertEqual(c.dims, dims)
def test_2(self): b = aobj.remove_rep(self.b) self.assertAllclose(b, self.b) self.assertEqual(b.dims, self.b.dims)
def test_1(self): a = aobj.remove_rep(self.a) self.assertAllclose(a, self.a) self.assertEqual(a.dims, self.a.dims)