Example #1
0
 def test00(self):
     """Testing vtable creation from a tuple of btables (single row)"""
     N = int(1e1)
     t1 = blz.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8',
                       count=N, rootdir=self.rootdir)
     t2 = blz.fromiter(((i, i*3.) for i in xrange(N*2)), dtype='i4,f8',
                       count=N*2, rootdir=self.rootdir)
     vt = blz.vtable((t1, t2), rootdir=self.rootdir)
     r = np.array([(1, 3.)], dtype='i4,f8')[0]
     assert_array_equal(vt[N+1], r, "vtable values are not correct")
Example #2
0
 def test01b(self):
     """vtable from a collection of differently sized btables"""
     N = int(1e1)
     t1 = blz.fromiter(((i, i*2.) for i in xrange(N+1)),
                       dtype='i4,f8', count=N+1, rootdir=self.rootdir)
     t2 = blz.fromiter(((i, i*2.) for i in xrange(N+1, N*2)),
                       dtype='i4,f8', count=N-1, rootdir=self.rootdir)
     vt = blz.vtable((t1, t2), rootdir=self.rootdir)
     ra = np.fromiter(((i, i*2.) for i in xrange(N*2)), dtype='i4,f8')
     assert_array_equal(vt[:], ra, "vtable values are not correct")
Example #3
0
 def test02a(self):
     """vtable with start"""
     N = int(1e1)
     t1 = blz.fromiter(((i, i*2.) for i in xrange(N+1)),
                       dtype='i4,f8', count=N+1, rootdir=self.rootdir)
     t2 = blz.fromiter(((i, i*2.) for i in xrange(N+1, N*2)),
                       dtype='i4,f8', count=N-1, rootdir=self.rootdir)
     t3 = blz.fromiter(((i, i*2.) for i in xrange(N*2, N*3)),
                       dtype='i4,f8', count=N, rootdir=self.rootdir)
     vt = blz.vtable((t1, t2, t3), rootdir=self.rootdir)
     ra = np.fromiter(((i, i*2.) for i in xrange(N*3)), dtype='i4,f8')
     assert_array_equal(vt[2:], ra[2:], "vtable values are not correct")
Example #4
0
 def test04(self):
     """Testing `iter()` method with large zero arrays"""
     a = np.zeros(1e4, dtype='f8')
     b = blz.barray(a, chunklen=100, rootdir=self.rootdir)
     c = blz.fromiter((v for v in b), dtype='f8', count=len(a))
     #print "c ->", repr(c)
     assert_array_equal(a, c[:], "iterator fails on zeros")
Example #5
0
 def test01b(self):
     """Testing fromiter (long iter, chunk is multiple of iter length)"""
     N = 1e4
     a = (i for i in xrange(int(N)))
     b = blz.fromiter(a, dtype='f8', chunklen=1000, count=int(N))
     c = np.arange(N)
     assert_array_equal(b[:], c, "fromiter does not work correctly")
Example #6
0
 def test01a(self):
     """Testing fromiter (long iter)"""
     N = 1e4
     a = (i for i in xrange(int(N)))
     b = blz.fromiter(a, dtype='f8', count=int(N))
     c = np.arange(N)
     assert_array_equal(b[:], c, "fromiter does not work correctly")
Example #7
0
 def test07(self):
     """Testing `iter()` method with `limit` and `skip`"""
     a = np.arange(1e4, dtype='f8')
     b = blz.barray(a, chunklen=100, rootdir=self.rootdir)
     c = blz.fromiter((v for v in b.iter(limit=1010, skip=1010)), dtype='f8',
                     count=1010)
     #print "c ->", repr(c)
     assert_array_equal(a[1010:2020], c, "iterator fails on zeros")
Example #8
0
 def test01(self):
     """Testing trim() with NumPy scalar values"""
     N = 10000
     ra = np.fromiter(((i, i*2.) for i in xrange(N-200)), dtype='i4,f8')
     t = blz.fromiter(((i, i*2.) for i in xrange(N)), 'i4,f8', N,
                     rootdir=self.rootdir)
     t.trim(np.int(200))
     assert_array_equal(t[:], ra, "btable values are not correct")
Example #9
0
 def test02(self):
     """Testing trim() with a complete trim"""
     N = 100
     ra = np.fromiter(((i, i*2.) for i in xrange(0)), dtype='i4,f8')
     t = blz.fromiter(((i, i*2.) for i in xrange(N)), 'i4,f8', N,
                     rootdir=self.rootdir)
     t.trim(N)
     self.assert_(len(ra) == len(t), "Lengths are not equal")
Example #10
0
 def test00(self):
     """Testing resize() (decreasing)"""
     N = 100
     ra = np.fromiter(((i, i*2.) for i in xrange(N-2)), dtype='i4,f8')
     t = blz.fromiter(((i, i*2.) for i in xrange(N)), 'i4,f8', N,
                     rootdir=self.rootdir)
     t.resize(N-2)
     assert_array_equal(t[:], ra, "btable values are not correct")
Example #11
0
 def getobject(self):
     if self.flavor == 'barray':
         obj = blz.zeros(10, dtype="i1", rootdir=self.rootdir)
         self.assertEqual(type(obj), blz.barray)
     elif self.flavor == 'btable':
         obj = blz.fromiter(((i,i*2) for i in range(10)), dtype='i2,f4',
                           count=10, rootdir=self.rootdir)
         self.assertEqual(type(obj), blz.btable)
     return obj
Example #12
0
 def test03a(self):
     """Testing btable creation from large iterator"""
     N = 10*1000
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = blz.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8',
                     count=N, rootdir=self.rootdir)
     #print "t->", `t`
     #print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "btable values are not correct")
Example #13
0
 def test01(self):
     """Testing resize() (increasing)"""
     N = 100
     ra = np.fromiter(((i, i*2.) for i in xrange(N+4)), dtype='i4,f8')
     t = blz.fromiter(((i, i*2.) for i in xrange(N)), 'i4,f8', N,
                     rootdir=self.rootdir)
     t.resize(N+4)
     ra['f0'][N:] = np.zeros(4)
     ra['f1'][N:] = np.zeros(4)
     assert_array_equal(t[:], ra, "btable values are not correct")
Example #14
0
 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
Example #15
0
 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)
Example #16
0
 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())
Example #17
0
 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())
Example #18
0
 def test02(self):
     """Testing fromiter (empty iter)"""
     a = np.array([], dtype="f8")
     b = blz.fromiter(iter(a), dtype='f8', count=-1)
     assert_array_equal(b[:], a, "fromiter does not work correctly")
Example #19
0
 def test04b(self):
     """Testing fromiter method with large iterator with a hint"""
     N = 10*1000
     a = np.fromiter((i*2 for i in xrange(N)), dtype='f8', count=N)
     b = blz.fromiter((i*2 for i in xrange(N)), dtype='f8', count=N)
     assert_array_equal(b[:], a, "iterator with a hint fails")
Example #20
0
 def test00(self):
     """Testing fromiter (short iter)"""
     a = np.arange(1,111)
     b = blz.fromiter(iter(a), dtype='i4', count=len(a))
     assert_array_equal(b[:], a, "fromiter does not work correctly")
Example #21
0
 def test03(self):
     """Testing fromiter (dtype conversion)"""
     a = np.arange(101, dtype="f8")
     b = blz.fromiter(iter(a), dtype='f4', count=len(a))
     assert_array_equal(b[:], a, "fromiter does not work correctly")