def test00b(self): """Testing `append()` method (correct shape, single row)""" a = np.ones((2,300), dtype="i4")*3 b = ca.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")
def test03c(self): """Testing fill() constructor, with a string type""" a = np.ones(self.N, dtype='S3') ac = ca.fill(self.N, "1", dtype='S3') #print "a-->", a, ac self.assert_(a.dtype == ac.dtype) self.assert_(np.all(a == ac))
def test00b(self): """Testing `append()` method (correct shape, single row)""" a = np.ones((2, 3), dtype="i4") * 3 b = ca.fill((1, 3), 3, dtype="i4") b.append((3, 3, 3)) #print "b->", `b` assert_array_equal(a, b, "Arrays are not equal")
def test00(self): """Testing `__getitem()__` method with only a start""" a = np.ones((2, 3), dtype="i4") * 3 b = ca.fill((2, 3), 3, dtype="i4") sl = slice(1) # print "b[sl]->", `b[sl]` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test02(self): """Testing `append()` method (several rows)""" a = np.ones((4,3), dtype="i4")*3 b = ca.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")
def test02(self): """Testing `__getitem()__` method with a start, stop, step""" a = np.ones((10, 2), dtype="i4") * 3 b = ca.fill((10, 2), 3, dtype="i4") sl = slice(1, 9, 2) # print "b[sl]->", `b[sl]` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test00a(self): """Testing `append()` method (correct shape)""" a = np.ones((2, 3), dtype="i4") * 3 b = ca.fill((1, 3), 3, dtype="i4") b.append([(3, 3, 3)]) # print "b->", `b` assert_array_equal(a, b, "Arrays are not equal")
def test02(self): """Testing `append()` method (several rows)""" a = np.ones((4, 3), dtype="i4") * 3 b = ca.fill((1, 3), 3, dtype="i4") b.append([(3, 3, 3)] * 3) #print "b->", `b` assert_array_equal(a, b, "Arrays are not equal")
def test02(self): """Testing `__getitem()__` method with a start, stop, step""" a = np.ones((10, 2), dtype="i4") * 3 b = ca.fill((10, 2), 3, dtype="i4") sl = slice(1, 9, 2) #print "b[sl]->", `b[sl]` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test00(self): """Testing `__getitem()__` method with only a start""" a = np.ones((2, 3), dtype="i4") * 3 b = ca.fill((2, 3), 3, dtype="i4") sl = slice(1) #print "b[sl]->", `b[sl]` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test03b(self): """Testing `fill` constructor (array default)""" a = np.ones((2,2), dtype='(4,)i4')*3 b = ca.fill((2,2), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir) if self.open: b = ca.open(rootdir=self.rootdir) #print "b->", `b` assert_array_equal(a, b, "Arrays are not equal")
def test01a(self): """Testing `__setitem()__` method with start,stop (scalar)""" a = np.ones((5, 2), dtype="i4") * 3 b = ca.fill((5, 2), 3, dtype="i4") sl = slice(1, 4) a[sl, :] = 0 b[sl] = 0 #print "b[sl]->", `b[sl]` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test02b(self): """Testing `__setitem()__` method with start,stop,step (scalar)""" a = np.ones((10, 2), dtype="i4") * 3 b = ca.fill((10, 2), 3, dtype="i4") sl = slice(1, 8, 3) a[sl, :] = range(2) b[sl] = range(2) # print "b[sl]->", `b[sl]`, `b` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test01a(self): """Testing `__setitem()__` method with start,stop (scalar)""" a = np.ones((5, 2), dtype="i4") * 3 b = ca.fill((5, 2), 3, dtype="i4") sl = slice(1, 4) a[sl, :] = 0 b[sl] = 0 # print "b[sl]->", `b[sl]` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test00b(self): """Testing `__setitem()__` method with only a start (vector)""" a = np.ones((2, 3), dtype="i4") * 3 b = ca.fill((2, 3), 3, dtype="i4") sl = slice(1) a[sl, :] = range(3) b[sl] = range(3) # print "b[sl]->", `b[sl]` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test00b(self): """Testing `__setitem()__` method with only a start (vector)""" a = np.ones((2, 3), dtype="i4") * 3 b = ca.fill((2, 3), 3, dtype="i4") sl = slice(1) a[sl, :] = range(3) b[sl] = range(3) #print "b[sl]->", `b[sl]` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test02b(self): """Testing `__setitem()__` method with start,stop,step (scalar)""" a = np.ones((10, 2), dtype="i4") * 3 b = ca.fill((10, 2), 3, dtype="i4") sl = slice(1, 8, 3) a[sl, :] = range(2) b[sl] = range(2) #print "b[sl]->", `b[sl]`, `b` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test00b(self): """Testing `__getitem()__` method with only a start (slice)""" a = np.ones((27,2700), dtype="i4")*3 b = ca.fill((27,2700), 3, dtype="i4", rootdir=self.rootdir) if self.open: b = ca.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")
def test04(self): """Testing `fill` constructor with open and resize (array default)""" a = np.ones((3,200), dtype='(4,)i4')*3 b = ca.fill((2,200), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir) if self.open: b = ca.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")
def test00a(self): """Testing `__getitem()__` method with only a start (scalar)""" a = np.ones((2,3), dtype="i4")*3 b = ca.fill((2,3), 3, dtype="i4", rootdir=self.rootdir) if self.open: b = ca.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")
def test02(self): """Testing `__getitem()__` method with a start, stop, step""" a = np.ones((10,2), dtype="i4")*3 b = ca.fill((10,2), 3, dtype="i4", rootdir=self.rootdir) if self.open: b = ca.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")
def test05(self): """Testing `fill` constructor with open and resize (nchunks>1)""" a = np.ones((3,2000), dtype='(4,)i4')*3 b = ca.fill((2,2000), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir) if self.open: b = ca.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")
def test01b(self): """Testing `__setitem()__` method with start,stop (vector)""" a = np.ones((5,2), dtype="i4")*3 b = ca.fill((5,2), 3, dtype="i4", rootdir=self.rootdir) sl = slice(1,4) a[sl,:] = range(2) b[sl] = range(2) if self.open: b.flush() b = ca.open(rootdir=self.rootdir) #print "b[sl]->", `b[sl]` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test02a(self): """Testing `__setitem()__` method with start,stop,step (scalar)""" a = np.ones((1000,200), dtype="i4")*3 b = ca.fill((1000,200), 3, dtype="i4", rootdir=self.rootdir) sl = slice(100,800,3) a[sl,:] = 0 b[sl] = 0 if self.open: b.flush() b = ca.open(rootdir=self.rootdir) #print "b[sl]->", `b[sl]` assert_array_equal(a[sl], b[sl], "Arrays are not equal")
def test03a(self): """Testing fill() constructor.""" a = np.ones(self.N) ac = ca.fill(self.N, 1) self.assert_(a.dtype == ac.dtype) self.assert_(np.all(a == ac))
def test03b(self): """Testing `fill` constructor (array default)""" a = np.ones((2, 2), dtype='(4,)i4') * 3 b = ca.fill((2, 2), [3, 3, 3, 3], dtype='(4,)i4') #print "b->", `b` assert_array_equal(a, b, "Arrays are not equal")
def test03b(self): """Testing `fill` constructor (array default)""" a = np.ones((2, 2), dtype="(4,)i4") * 3 b = ca.fill((2, 2), [3, 3, 3, 3], dtype="(4,)i4") # print "b->", `b` assert_array_equal(a, b, "Arrays are not equal")
def test01(self): """Testing `append()` method (incorrect shape)""" a = np.ones((2, 3), dtype="i4") * 3 b = ca.fill((1, 3), 3, dtype="i4") self.assertRaises(ValueError, b.append, [(3, 3)])
def test03b(self): """Testing fill() constructor, with a `dtype`.""" a = np.ones(self.N, dtype='i4') * 3 ac = ca.fill(self.N, 3, dtype='i4') self.assert_(a.dtype == ac.dtype) self.assert_(np.all(a == ac))
import numpy as np import carray as ca 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 = ca.fill(N, dtype=dtype, dflt=1) #ac = ca.carray(a) print "Time carray.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)
def test01(self): """Testing `append()` method (incorrect shape)""" a = np.ones((2,3), dtype="i4")*3 b = ca.fill((1,3), 3, dtype="i4", rootdir=self.rootdir) self.assertRaises(ValueError, b.append, [(3,3)])
import numpy as np import carray as ca 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 = ca.fill(N, dtype=dtype, dflt=1) #ac = ca.carray(a) print "Time carray.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)
def test03b(self): """Testing fill() constructor, with a `dtype`.""" a = np.ones(self.N, dtype='i4')*3 ac = ca.fill(self.N, 3, dtype='i4') self.assert_(a.dtype == ac.dtype) self.assert_(np.all(a == ac))