def iterchunks(self, blen=None, start=None, stop=None): """Return chunks of size `blen` (in leading dimension). Parameters ---------- blen : int The length, in rows, of the buffers that are returned. start : int Where the iterator starts. The default is to start at the beginning. stop : int Where the iterator stops. The default is to stop at the end. Returns ------- out : iterable This iterable returns buffers as NumPy arays of homogeneous or structured types, depending on whether `self.original` is a barray or a btable object. See Also -------- wherechunks """ # Return the iterable return blz.iterblocks(self.blzarr, blen, start, stop)
def test03(self): """Testing `iterchunks` method with all parameters set""" N, blen = int(1e4), 100 a = blz.fromiter(xrange(N), dtype=np.float64, count=N) l, s = 0, 0 for block in blz.iterblocks(a, blen, blen-1, 3*blen+2): l += len(block) s += block.sum() self.assert_(l == 2*blen + 3) self.assert_(s == np.arange(blen-1, 3*blen+2).sum())
def test02(self): """Testing `iterchunks` method with no stop""" N, blen = int(1e4), 100 a = blz.fromiter(xrange(N), dtype=np.float64, count=N) l, s = 0, 0 for block in blz.iterblocks(a, blen, blen-1): l += len(block) s += block.sum() self.assert_(l == (N - (blen - 1))) self.assert_(s == np.arange(blen-1, N).sum())
def test01(self): """Testing `iterchunks` method with no start, no stop""" N, blen = int(1e4), 100 a = blz.fromiter(xrange(N), dtype=np.float64, count=N) l, s = 0, 0 for block in blz.iterblocks(a, blen): self.assert_(len(block) == blen) l += len(block) s += block.sum() self.assert_(l == N)
def test00(self): """Testing `iterchunks` method with no blen, no start, no stop""" N = int(1e4) a = blz.fromiter(xrange(N), dtype=np.float64, count=N) l, s = 0, 0 for block in blz.iterblocks(a): l += len(block) s += block.sum() self.assert_(l == N) self.assert_(s == (N - 1) * (N / 2)) # as per Gauss summation formula
def test03(self): """Testing `iterchunks` method with all parameters set""" N, blen = int(1e4), 100 ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8') t = blz.btable(ra) l, s = 0, 0 for block in blz.iterblocks(t, blen, blen-1, 3*blen+2): l += len(block) s += block['f2'].sum() self.assert_(l == 2*blen + 3) self.assert_(s == (np.arange(blen-1, 3*blen+2)*3).sum())
def test02(self): """Testing `iterchunks` method with no stop""" N, blen = int(1e4), 100 ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8') t = blz.btable(ra) l, s = 0, 0. for block in blz.iterblocks(t, blen, blen-1): l += len(block) s += block['f1'].sum() self.assert_(l == (N - (blen - 1))) self.assert_(s == (np.arange(blen-1, N, dtype='f8')*2).sum())
def test00(self): """Testing `iterchunks` method with no blen, no start, no stop""" N = int(1e4) ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8') t = blz.btable(ra) l, s = 0, 0 for block in blz.iterblocks(t): l += len(block) s += block['f0'].sum() self.assert_(l == N) self.assert_(s == (N - 1) * (N / 2)) # as per Gauss summation formula