Esempio n. 1
0
    def test01b(self):
        """Testing btable creation in "w" mode"""
        N = 1e1
        a = blz.barray(np.arange(N, dtype="i4"))
        b = blz.barray(np.arange(N, dtype="f8") + 1)
        t = blz.btable((a, b), ("f0", "f1"), rootdir=self.rootdir)
        # Overwrite the last btable
        t = blz.btable((a, b), ("f0", "f1"), rootdir=self.rootdir, mode="w")
        # print "t->", `t`
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        # print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "btable values are not correct")

        # Now check some accesses
        t.append((10, 11.0))
        t.append((10, 11.0))
        t[11] = (11, 12.0)

        # Check values
        N = 12
        a = blz.barray(np.arange(N, dtype="i4"))
        b = blz.barray(np.arange(N, dtype="f8") + 1)
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        # print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "btable values are not correct")
Esempio n. 2
0
    def test00c(self):
        """Testing btable opening in "a" mode"""
        N = 1e1
        a = blz.barray(np.arange(N, dtype="i4"))
        b = blz.barray(np.arange(N, dtype="f8") + 1)
        t = blz.btable((a, b), ("f0", "f1"), rootdir=self.rootdir)
        # Open t
        t = blz.open(rootdir=self.rootdir, mode="a")
        # print "t->", `t`

        # Check values
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        # print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "btable values are not correct")

        # Now check some accesses
        t.append((10, 11.0))
        t.append((10, 11.0))
        t[-1] = (11, 12.0)

        # Check values
        N = 12
        a = blz.barray(np.arange(N, dtype="i4"))
        b = blz.barray(np.arange(N, dtype="f8") + 1)
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        # print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "btable values are not correct")
Esempio n. 3
0
 def test01c(self):
     """Testing btable creation in "a" mode"""
     N = 1e1
     a = blz.barray(np.arange(N, dtype="i4"))
     b = blz.barray(np.arange(N, dtype="f8") + 1)
     t = blz.btable((a, b), ("f0", "f1"), rootdir=self.rootdir)
     # Overwrite the last btable
     self.assertRaises(RuntimeError, blz.btable, (a, b), ("f0", "f1"), rootdir=self.rootdir, mode="a")
Esempio n. 4
0
 def test06(self):
     """Testing `where()` iterator (using array bool in fancy indexing)"""
     a = np.arange(1, 110)
     b = blz.barray(a, chunklen=10)
     wt = a[(a<5)|(a>9)]
     cwt = b[blz.barray((a<5)|(a>9))]
     #print "numpy ->", a[(a<5)|(a>9)]
     #print "where ->", b[blz.barray((a<5)|(a>9))]
     assert_array_equal(wt, cwt, "where() does not work correctly")
Esempio n. 5
0
 def test03(self):
     """Testing `where()` iterator (using a boolean array)"""
     a = np.arange(1, 11)
     b = blz.barray(a)
     wt = [v for v in a if v<=5]
     cwt = [v for v in b.where(blz.barray(a<=5))]
     #print "numpy ->", [v for v in a if v<=5]
     #print "where ->", [v for v in b.where(blz.barray(a<=5))]
     self.assert_(wt == cwt, "where() does not work correctly")
Esempio n. 6
0
 def test05(self):
     """Testing `where()` iterator using `skip`"""
     a = np.arange(1, 11)
     b = blz.barray(a)
     wt = [v for v in a if v<=5][2:]
     cwt = [v for v in b.where(blz.barray(a<=5), skip=2)]
     #print "numpy ->", [v for v in a if v<=5][2:]
     #print "where ->", [v for v in b.where(blz.barray(a<=5), skip=2)]
     self.assert_(wt == cwt, "where() does not work correctly")
Esempio n. 7
0
 def test00a(self):
     """Testing btable creation from a tuple of barrays"""
     N = 1e1
     a = blz.barray(np.arange(N, dtype="i4"))
     b = blz.barray(np.arange(N, dtype="f8") + 1)
     t = blz.btable((a, b), ("f0", "f1"), rootdir=self.rootdir)
     # print "t->", `t`
     ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
     # print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "btable values are not correct")
Esempio n. 8
0
 def test02(self):
     """Testing append() with barrays"""
     N = 10
     ra = np.fromiter(((i, i * 2.0) for i in xrange(N)), dtype="i4,f8")
     t = blz.btable(ra, rootdir=self.rootdir)
     a = np.arange(N, N + 10, dtype="i4")
     b = np.arange(N, N + 10, dtype="f8") * 2.0
     t.append((blz.barray(a), blz.barray(b)))
     ra = np.fromiter(((i, i * 2.0) for i in xrange(N + 10)), dtype="i4,f8")
     assert_array_equal(t[:], ra, "btable values are not correct")
Esempio n. 9
0
 def test06(self):
     """Testing `where()` iterator using `limit` and `skip`"""
     a = np.arange(1, 11)
     b = blz.barray(a)
     wt = [v for v in a if v<=5][1:4]
     cwt = [v for v in b.where(blz.barray(a<=5), limit=3, skip=1)]
     #print "numpy ->", [v for v in a if v<=5][1:4]
     #print "where ->", [v for v in b.where(blz.barray(a<=5),
     #                                      limit=3, skip=1)]
     self.assert_(wt == cwt, "where() does not work correctly")
Esempio n. 10
0
 def test04(self):
     """Testing fancy indexing with __setitem__ (bool barray)"""
     a = np.arange(1,1e2)
     b = blz.barray(a, chunklen=10)
     bc = (a > 5) & (a < 40)
     sl = blz.barray(bc)
     b[sl] = 3.
     a[bc] = 3.
     #print "b[%s] -> %r" % (sl, b)
     assert_array_equal(b[:], a, "fancy indexing does not work correctly")
Esempio n. 11
0
 def test07(self):
     """Testing `where()` iterator using `limit` and `skip` (zeros)"""
     a = np.arange(10000)
     b = blz.barray(a,)
     wt = [v for v in a if v<=5000][1010:2020]
     cwt = [v for v in b.where(blz.barray(a<=5000, chunklen=100),
                               limit=1010, skip=1010)]
     # print "numpy ->", [v for v in a if v>=5000][1010:2020]
     # print "where ->", [v for v in b.where(blz.barray(a>=5000,chunklen=100),
     #                                       limit=1010, skip=1010)]
     self.assert_(wt == cwt, "where() does not work correctly")
Esempio n. 12
0
 def test02(self):
     """Testing fancy indexing (empty list)"""
     a = np.arange(101)
     b = blz.barray(a)
     c = b[[]]
     r = a[[]]
     assert_array_equal(c, r, "fancy indexing does not work correctly")
Esempio n. 13
0
 def test00(self):
     """Testing fancy indexing (short list)"""
     a = np.arange(1,111)
     b = blz.barray(a)
     c = b[[3,1]]
     r = a[[3,1]]
     assert_array_equal(c, r, "fancy indexing does not work correctly")
Esempio n. 14
0
 def test05(self):
     """Testing `__getitem()__` method with negative steps"""
     a = np.arange(1e3)
     b = blz.barray(a, chunklen=10, rootdir=self.rootdir)
     sl = slice(None, None, -3)
     #print "b[sl]->", `b[sl]`
     self.assertRaises(NotImplementedError, b.__getitem__, sl)
Esempio n. 15
0
 def test03d(self):
     """Testing `__getitem()__` method with ranges and steps (IV)"""
     a = np.arange(1e3)
     b = blz.barray(a, chunklen=10, rootdir=self.rootdir)
     sl = slice(4, 80, 3000)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 16
0
    def test00a(self):
        """Testing btable opening in "r" mode"""
        N = 1e1
        a = blz.barray(np.arange(N, dtype="i4"))
        b = blz.barray(np.arange(N, dtype="f8") + 1)
        t = blz.btable((a, b), ("f0", "f1"), rootdir=self.rootdir)
        # Open t
        t = blz.open(rootdir=self.rootdir, mode="r")
        # print "t->", `t`
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        # print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "btable values are not correct")

        # Now check some accesses
        self.assertRaises(RuntimeError, t.__setitem__, 1, (0, 0.0))
        self.assertRaises(RuntimeError, t.append, (0, 0.0))
Esempio n. 17
0
 def test01d(self):
     """Testing `__getitem()__` method with only a (large) start"""
     a = np.arange(1e4)
     b = blz.barray(a, rootdir=self.rootdir)
     sl = -2   # second last element
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 18
0
 def test02b(self):
     """Testing `__getitem()__` method with ranges (negative start)"""
     a = np.arange(1e2)
     b = blz.barray(a, chunklen=10, rootdir=self.rootdir)
     sl = slice(-3)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 19
0
 def test03b(self):
     """Testing `iter()` method with start, stop, step"""
     a = np.arange(101)
     b = blz.barray(a, chunklen=2, rootdir=self.rootdir)
     #print "sum iter->", sum(b.iter(3, 24, 4))
     self.assert_(sum(a[3:24:4]) == sum(b.iter(3, 24, 4)),
                  "Sums are not equal")
Esempio n. 20
0
 def test02c(self):
     """Testing `iter()` method with positive start, negative stop"""
     a = np.arange(101)
     b = blz.barray(a, chunklen=2, rootdir=self.rootdir)
     #print "sum iter->", sum(b.iter(24, -3))
     self.assert_(sum(a[24:-3]) == sum(b.iter(24, -3)),
                  "Sums are not equal")
Esempio n. 21
0
 def test03(self):
     """Testing copy() with no shuffle"""
     a = np.linspace(-1., 1., 1e4)
     b = blz.barray(a, rootdir=self.rootdir)
     c = b.copy(bparams=blz.bparams(shuffle=False))
     #print "b.cbytes, c.cbytes:", b.cbytes, c.cbytes
     self.assert_(b.cbytes < c.cbytes, "shuffle not changed")
Esempio n. 22
0
 def test02(self):
     """Testing copy() with lesser compression"""
     a = np.linspace(-1., 1., 1e4)
     b = blz.barray(a, rootdir=self.rootdir)
     c = b.copy(bparams=blz.bparams(clevel=1))
     #print "b.cbytes, c.cbytes:", b.cbytes, c.cbytes
     self.assert_(b.cbytes < c.cbytes, "clevel not changed")
Esempio n. 23
0
 def test03(self):
     """Testing fancy indexing (list of floats)"""
     a = np.arange(1,101)
     b = blz.barray(a)
     c = b[[1.1, 3.3]]
     r = a[[1.1, 3.3]]
     assert_array_equal(c, r, "fancy indexing does not work correctly")
Esempio n. 24
0
 def test04a(self):
     """Testing `__getitem()__` method with long ranges"""
     a = np.arange(1e3)
     b = blz.barray(a, chunklen=100, rootdir=self.rootdir)
     sl = slice(1, 8000)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 25
0
 def test03a(self):
     """Testing `iter()` method with only step"""
     a = np.arange(101)
     b = blz.barray(a, chunklen=2, rootdir=self.rootdir)
     #print "sum iter->", sum(b.iter(step=4))
     self.assert_(sum(a[::4]) == sum(b.iter(step=4)),
                  "Sums are not equal")
Esempio n. 26
0
 def test04d(self):
     """Testing `__getitem()__` method with no start and no stop"""
     a = np.arange(1e3)
     b = blz.barray(a, chunklen=100, rootdir=self.rootdir)
     sl = slice(None, None, 2)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 27
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")
Esempio n. 28
0
 def test00(self):
     """Testing string types (creation)"""
     a = np.array([["ale", "ene"], ["aco", "ieie"]], dtype="S4")
     b = blz.barray(a)
     #print "b.dtype-->", b.dtype
     #print "b->", `b`
     self.assert_(a.dtype == b.dtype.base)
     assert_array_equal(a, b[:], "Arrays are not equal")
Esempio n. 29
0
 def test00(self):
     """Testing unicode types (creation)"""
     a = np.array([[u"aŀle", u"eñe"], [u"açò", u"áèâë"]], dtype="U4")
     b = blz.barray(a)
     #print "b.dtype-->", b.dtype
     #print "b->", `b`
     self.assert_(a.dtype == b.dtype.base)
     assert_array_equal(a, b[:], "Arrays are not equal")
Esempio n. 30
0
 def test01(self):
     """Testing fancy indexing (large list, numpy)"""
     a = np.arange(1,1e4)
     b = blz.barray(a)
     idx = np.random.randint(1000, size=1000)
     c = b[idx]
     r = a[idx]
     assert_array_equal(c, r, "fancy indexing does not work correctly")