Esempio n. 1
0
 def test02(self):
     """Testing `append()` method (several rows)"""
     a = np.ones((4, 3), dtype="i4") * 3
     b = blz.fill((1, 3), 3, dtype="i4", rootdir=self.rootdir)
     b.append([(3, 3, 3)] * 3)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 2
0
 def test00b(self):
     """Testing `append()` method (correct shape, single row)"""
     a = np.ones((2, 300), dtype="i4") * 3
     b = blz.fill((1, 300), 3, dtype="i4", rootdir=self.rootdir)
     b.append((3, ) * 300)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 3
0
 def test00b(self):
     """Testing `append()` method (correct shape, single row)"""
     a = np.ones((2,300), dtype="i4")*3
     b = blz.fill((1,300), 3, dtype="i4", rootdir=self.rootdir)
     b.append((3,)*300)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 4
0
 def test02(self):
     """Testing `append()` method (several rows)"""
     a = np.ones((4,3), dtype="i4")*3
     b = blz.fill((1,3), 3, dtype="i4", rootdir=self.rootdir)
     b.append([(3,3,3)]*3)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 5
0
 def test03a(self):
     """Testing `fill` constructor (scalar default)"""
     a = np.ones((2, 200), dtype='(4,)i4') * 3
     b = blz.fill((2, 200), 3, dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 6
0
 def test03b(self):
     """Testing `fill` constructor (array default)"""
     a = np.ones((2,2), dtype='(4,)i4')*3
     b = blz.fill((2,2), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 7
0
 def test00b(self):
     """Testing `__getitem()__` method with only a start (slice)"""
     a = np.ones((27, 2700), dtype="i4") * 3
     b = blz.fill((27, 2700), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     sl = slice(1)
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 8
0
 def test00b(self):
     """Testing `__getitem()__` method with only a start (slice)"""
     a = np.ones((27,2700), dtype="i4")*3
     b = blz.fill((27,2700), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     sl = slice(1)
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 9
0
 def test00a(self):
     """Testing `__getitem()__` method with only a start (scalar)"""
     a = np.ones((2,3), dtype="i4")*3
     b = blz.fill((2,3), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     sl = 1
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 10
0
 def test02(self):
     """Testing `__getitem()__` method with a start, stop, step"""
     a = np.ones((10,2), dtype="i4")*3
     b = blz.fill((10,2), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     sl = slice(1,9,2)
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 11
0
 def test02(self):
     """Testing `__getitem()__` method with a start, stop, step"""
     a = np.ones((10, 2), dtype="i4") * 3
     b = blz.fill((10, 2), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     sl = slice(1, 9, 2)
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 12
0
 def test00a(self):
     """Testing `__getitem()__` method with only a start (scalar)"""
     a = np.ones((2, 3), dtype="i4") * 3
     b = blz.fill((2, 3), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     sl = 1
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 13
0
 def test04(self):
     """Testing `fill` constructor with open and resize (array default)"""
     a = np.ones((3,200), dtype='(4,)i4')*3
     b = blz.fill((2,200), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     c = np.ones((1,200), dtype='(4,)i4')*3
     b.append(c)
     #print "b->", `b`, len(b), b[1]
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 14
0
 def test05(self):
     """Testing `fill` constructor with open and resize (nchunks>1)"""
     a = np.ones((3,2000), dtype='(4,)i4')*3
     b = blz.fill((2,2000), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     c = np.ones((1,2000), dtype='(4,)i4')*3
     b.append(c)
     #print "b->", `b`
     # We need to use the b[:] here to overcome a problem with the
     # assert_array_equal() function
     assert_array_equal(a, b[:], "Arrays are not equal")
Esempio n. 15
0
 def test02b(self):
     """Testing `__setitem()__` method with start,stop,step (scalar)"""
     a = np.ones((10, 2), dtype="i4") * 3
     b = blz.fill((10, 2), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(1, 8, 3)
     a[sl, :] = range(2)
     b[sl] = range(2)
     if self.open:
         b.flush()
         b = blz.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`, `b`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 16
0
 def test00b(self):
     """Testing `__setitem()__` method with only a start (vector)"""
     a = np.ones((200, 300), dtype="i4") * 3
     b = blz.fill((200, 300), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(1)
     a[sl, :] = range(300)
     b[sl] = range(300)
     if self.open:
         b.flush()
         b = blz.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 17
0
 def test04(self):
     """Testing `fill` constructor with open and resize (array default)"""
     a = np.ones((3, 200), dtype='(4,)i4') * 3
     b = blz.fill((2, 200), [3, 3, 3, 3],
                  dtype='(4,)i4',
                  rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     c = np.ones((1, 200), dtype='(4,)i4') * 3
     b.append(c)
     #print "b->", `b`, len(b), b[1]
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 18
0
 def test02b(self):
     """Testing `__setitem()__` method with start,stop,step (scalar)"""
     a = np.ones((10,2), dtype="i4")*3
     b = blz.fill((10,2), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(1,8,3)
     a[sl,:] = range(2)
     b[sl] = range(2)
     if self.open:
         b.flush()
         b = blz.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`, `b`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 19
0
 def test00b(self):
     """Testing `__setitem()__` method with only a start (vector)"""
     a = np.ones((200,300), dtype="i4")*3
     b = blz.fill((200,300), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(1)
     a[sl,:] = range(300)
     b[sl] = range(300)
     if self.open:
         b.flush()
         b = blz.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 20
0
 def test01a(self):
     """Testing `__setitem()__` method with start,stop (scalar)"""
     a = np.ones((500,200), dtype="i4")*3
     b = blz.fill((500,200), 3, dtype="i4", rootdir=self.rootdir,
                 bparams=blz.bparams())
     sl = slice(100,400)
     a[sl,:] = 0
     b[sl] = 0
     if self.open:
         b.flush()
         b = blz.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 21
0
 def test05(self):
     """Testing `fill` constructor with open and resize (nchunks>1)"""
     a = np.ones((3, 2000), dtype='(4,)i4') * 3
     b = blz.fill((2, 2000), [3, 3, 3, 3],
                  dtype='(4,)i4',
                  rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     c = np.ones((1, 2000), dtype='(4,)i4') * 3
     b.append(c)
     #print "b->", `b`
     # We need to use the b[:] here to overcome a problem with the
     # assert_array_equal() function
     assert_array_equal(a, b[:], "Arrays are not equal")
Esempio n. 22
0
 def test01a(self):
     """Testing `__setitem()__` method with start,stop (scalar)"""
     a = np.ones((500, 200), dtype="i4") * 3
     b = blz.fill((500, 200),
                  3,
                  dtype="i4",
                  rootdir=self.rootdir,
                  bparams=blz.bparams())
     sl = slice(100, 400)
     a[sl, :] = 0
     b[sl] = 0
     if self.open:
         b.flush()
         b = blz.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 23
0
File: fill.py Progetto: pombreda/blz
import numpy as np
import blz
from time import time

N = 1e8
dtype = 'i4'

t0 = time()
a = np.ones(N, dtype=dtype)
print "Time numpy.ones() --> %.4f" % (time()-t0)

t0 = time()
ac = blz.fill(N, dtype=dtype, dflt=1)
#ac = blz.barray(a)
print "Time blz.fill(dflt=1) --> %.4f" % (time()-t0)

print "ac-->", `ac`

t0 = time()
sa = a.sum()
print "Time a.sum() --> %.4f" % (time()-t0)

t0 = time()
sac = ac.sum()
print "Time ac.sum() --> %.4f" % (time()-t0)


assert(sa == sac)
Esempio n. 24
0
 def test01(self):
     """Testing `append()` method (incorrect shape)"""
     a = np.ones((2,3), dtype="i4")*3
     b = blz.fill((1,3), 3, dtype="i4", rootdir=self.rootdir)
     self.assertRaises(ValueError, b.append, [(3,3)])
Esempio n. 25
0
 def test01(self):
     """Testing `append()` method (incorrect shape)"""
     a = np.ones((2, 3), dtype="i4") * 3
     b = blz.fill((1, 3), 3, dtype="i4", rootdir=self.rootdir)
     self.assertRaises(ValueError, b.append, [(3, 3)])
Esempio n. 26
0
import numpy as np
import blz
from time import time

N = 1e8
dtype = "i4"

t0 = time()
a = np.ones(N, dtype=dtype)
print "Time numpy.ones() --> %.4f" % (time() - t0)

t0 = time()
ac = blz.fill(N, dtype=dtype, dflt=1)
# ac = blz.barray(a)
print "Time blz.fill(dflt=1) --> %.4f" % (time() - t0)

print "ac-->", ` ac `

t0 = time()
sa = a.sum()
print "Time a.sum() --> %.4f" % (time() - t0)

t0 = time()
sac = ac.sum()
print "Time ac.sum() --> %.4f" % (time() - t0)


assert sa == sac