コード例 #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
ファイル: test_attrs.py プロジェクト: caglar/carray
 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")