示例#1
0
文件: test_carray.py 项目: 87/carray
 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")
示例#2
0
文件: test_carray.py 项目: 87/carray
 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")
示例#3
0
文件: test_carray.py 项目: 87/carray
 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")
示例#4
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 = 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")
示例#5
0
文件: test_carray.py 项目: 87/carray
 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")
示例#6
0
文件: test_carray.py 项目: 87/carray
 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")
示例#7
0
文件: test_ctable.py 项目: 87/carray
 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")
示例#8
0
文件: test_carray.py 项目: 87/carray
 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")
示例#9
0
文件: test_ctable.py 项目: 87/carray
 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")
示例#10
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 = 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")
示例#11
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 = 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")
示例#12
0
文件: test_ctable.py 项目: 87/carray
 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")
示例#13
0
文件: test_carray.py 项目: 87/carray
 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")
示例#14
0
文件: test_ctable.py 项目: 87/carray
 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")
示例#15
0
文件: test_carray.py 项目: 87/carray
 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")
示例#16
0
 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
示例#17
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 = 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")
示例#18
0
文件: test_ctable.py 项目: 87/carray
 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")
示例#19
0
 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")
示例#20
0
文件: ctable-query.py 项目: 87/carray
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
示例#21
0
文件: ctable-query.py 项目: 87/carray
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
示例#22
0
文件: test_carray.py 项目: 87/carray
 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")
示例#23
0
文件: fromiter.py 项目: 87/carray
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()
示例#24
0
文件: test_carray.py 项目: 87/carray
 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")
示例#25
0
文件: test_carray.py 项目: 87/carray
 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")
示例#26
0
文件: test_carray.py 项目: 87/carray
 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")
示例#27
0
文件: fromiter.py 项目: 87/carray
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()
示例#28
0
文件: test_carray.py 项目: 87/carray
 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")
示例#29
0
文件: test_carray.py 项目: 87/carray
 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")
示例#30
0
文件: test_carray.py 项目: 87/carray
 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")
示例#31
0
文件: test_carray.py 项目: 87/carray
 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")