def test04(self): """Testing `iter()` method with large zero arrays""" a = np.zeros(1e4, dtype='f8') b = ca.carray(a, chunklen=100) c = ca.fromiter((v for v in b), dtype='f8', count=len(a)) #print "c ->", repr(c) assert_array_equal(a, c[:], "iterator fails on zeros")
def test01b(self): """Testing fromiter (long iter, chunk is multiple of iter length)""" N = 1e4 a = (i for i in xrange(int(N))) b = ca.fromiter(a, dtype='f8', chunklen=1000, count=int(N)) c = np.arange(N) assert_array_equal(b[:], c, "fromiter does not work correctly")
def test00(self): """Testing resize() (decreasing)""" N = 100 ra = np.fromiter(((i, i * 2.) for i in xrange(N - 2)), dtype='i4,f8') t = ca.fromiter(((i, i * 2.) for i in xrange(N)), 'i4,f8', N) t.resize(N - 2) assert_array_equal(t[:], ra, "ctable values are not correct")
def test01a(self): """Testing fromiter (long iter)""" N = 1e4 a = (i for i in xrange(int(N))) b = ca.fromiter(a, dtype='f8', count=int(N)) c = np.arange(N) assert_array_equal(b[:], c, "fromiter does not work correctly")
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 = ca.fromiter(((i, i*2.) for i in xrange(N)), 'i4,f8', N) t.trim(np.int(200)) assert_array_equal(t[:], ra, "ctable values are not correct")
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 = ca.fromiter(((i, i*2.) for i in xrange(N)), 'i4,f8', N) t.trim(N) self.assert_(len(ra) == len(t), "Lengths are not equal")
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 = ca.fromiter(((i, i * 2.) for i in xrange(N)), 'i4,f8', N) t.trim(N) self.assert_(len(ra) == len(t), "Lengths are not equal")
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 = ca.fromiter(((i, i * 2.) for i in xrange(N)), 'i4,f8', N) t.trim(np.int(200)) assert_array_equal(t[:], ra, "ctable values are not correct")
def test00(self): """Testing resize() (decreasing)""" N = 100 ra = np.fromiter(((i, i*2.) for i in xrange(N-2)), dtype='i4,f8') t = ca.fromiter(((i, i*2.) for i in xrange(N)), 'i4,f8', N) t.resize(N-2) assert_array_equal(t[:], ra, "ctable values are not correct")
def test07(self): """Testing `iter()` method with `limit` and `skip`""" a = np.arange(1e4, dtype='f8') b = ca.carray(a, chunklen=100) c = ca.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")
def test03a(self): """Testing ctable creation from large iterator""" N = 10*1000 ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8') t = ca.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8', count=N) #print "t->", `t` #print "ra[:]", ra[:] assert_array_equal(t[:], ra, "ctable values are not correct")
def getobject(self): if self.flavor == 'carray': obj = ca.zeros(10, dtype="i1", rootdir=self.rootdir) assert type(obj) == ca.carray elif self.flavor == 'ctable': obj = ca.fromiter(((i,i*2) for i in range(10)), dtype='i2,f4', count=10, rootdir=self.rootdir) assert type(obj) == ca.ctable return obj
def test01(self): """Testing resize() (increasing)""" N = 100 ra = np.fromiter(((i, i * 2.) for i in xrange(N + 4)), dtype='i4,f8') t = ca.fromiter(((i, i * 2.) for i in xrange(N)), 'i4,f8', N) t.resize(N + 4) ra['f0'][N:] = np.zeros(4) ra['f1'][N:] = np.zeros(4) assert_array_equal(t[:], ra, "ctable values are not correct")
def test01(self): """Testing resize() (increasing)""" N = 100 ra = np.fromiter(((i, i*2.) for i in xrange(N+4)), dtype='i4,f8') t = ca.fromiter(((i, i*2.) for i in xrange(N)), 'i4,f8', N) t.resize(N+4) ra['f0'][N:] = np.zeros(4) ra['f1'][N:] = np.zeros(4) assert_array_equal(t[:], ra, "ctable values are not correct")
def test03a(self): """Testing ctable creation from large iterator""" N = 10 * 1000 ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8') t = ca.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8', count=N) #print "t->", `t` #print "ra[:]", ra[:] assert_array_equal(t[:], ra, "ctable values are not correct")
def test_ctable(clevel): enter() tc = ca.fromiter((mv+np.random.rand(NC)-mv for i in xrange(int(NR))), dtype=dt, cparams=ca.cparams(clevel), count=int(NR)) after_create() out = np.fromiter((row for row in tc.where(squery, 'f1,f3')), dtype="f8,f8") after_query() return out
def test_ctable(clevel): enter() tc = ca.fromiter((mv + np.random.rand(NC) - mv for i in xrange(int(NR))), dtype=dt, cparams=ca.cparams(clevel), count=int(NR)) after_create() out = np.fromiter((row for row in tc.where(squery, 'f1,f3')), dtype="f8,f8") after_query() return out
def test00(self): """Testing fromiter (short iter)""" a = np.arange(1,111) b = ca.fromiter(iter(a), dtype='i4', count=len(a)) assert_array_equal(b[:], a, "fromiter does not work correctly")
z = xrange(2, N + 2) print "Starting benchmark now for creating arrays..." # Create a ndarray #x = (i for i in xrange(N)) # true iterable t0 = time() out = np.fromiter(x, dtype='f8', count=N) print "Time for array--> %.3f" % (time() - t0, ) print "out-->", len(out) #ca.set_num_threads(ca.ncores//2) # Create a carray #x = (i for i in xrange(N)) # true iterable t0 = time() cout = ca.fromiter(x, dtype='f8', count=N, cparams=ca.cparams(clevel)) print "Time for carray--> %.3f" % (time() - t0, ) print "cout-->", len(cout) assert_array_equal(out, cout, "Arrays are not equal") # Create a carray (with unknown size) #x = (i for i in xrange(N)) # true iterable t0 = time() cout = ca.fromiter(x, dtype='f8', count=-1, cparams=ca.cparams(clevel)) print "Time for carray (count=-1)--> %.3f" % (time() - t0, ) print "cout-->", len(cout) assert_array_equal(out, cout, "Arrays are not equal") # Retrieve from a structured ndarray gen = ((i, j, k) for i, j, k in it.izip(x, y, z)) t0 = time()
def test02(self): """Testing fromiter (empty iter)""" a = np.array([], dtype="f8") b = ca.fromiter(iter(a), dtype='f8', count=-1) assert_array_equal(b[:], a, "fromiter does not work correctly")
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 = ca.fromiter((i*2 for i in xrange(N)), dtype='f8', count=N) assert_array_equal(b[:], a, "iterator with a hint fails")
def test03(self): """Testing fromiter (dtype conversion)""" a = np.arange(101, dtype="f8") b = ca.fromiter(iter(a), dtype='f4', count=len(a)) assert_array_equal(b[:], a, "fromiter does not work correctly")
z = xrange(2,N+2) print "Starting benchmark now for creating arrays..." # Create a ndarray #x = (i for i in xrange(N)) # true iterable t0 = time() out = np.fromiter(x, dtype='f8', count=N) print "Time for array--> %.3f" % (time()-t0,) print "out-->", len(out) #ca.set_num_threads(ca.ncores//2) # Create a carray #x = (i for i in xrange(N)) # true iterable t0 = time() cout = ca.fromiter(x, dtype='f8', count=N, cparams=ca.cparams(clevel)) print "Time for carray--> %.3f" % (time()-t0,) print "cout-->", len(cout) assert_array_equal(out, cout, "Arrays are not equal") # Create a carray (with unknown size) #x = (i for i in xrange(N)) # true iterable t0 = time() cout = ca.fromiter(x, dtype='f8', count=-1, cparams=ca.cparams(clevel)) print "Time for carray (count=-1)--> %.3f" % (time()-t0,) print "cout-->", len(cout) assert_array_equal(out, cout, "Arrays are not equal") # Retrieve from a structured ndarray gen = ((i,j,k) for i,j,k in it.izip(x,y,z)) t0 = time()
def test00(self): """Testing fromiter (short iter)""" a = np.arange(1, 111) b = ca.fromiter(iter(a), dtype='i4', count=len(a)) assert_array_equal(b[:], a, "fromiter does not work correctly")
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 = ca.fromiter((i * 2 for i in xrange(N)), dtype='f8', count=N) assert_array_equal(b[:], a, "iterator with a hint fails")