示例#1
0
文件: test_carray.py 项目: 87/carray
 def test01a(self):
     """Testing `resize()` method (decrease, large variation)"""
     b = ca.arange(self.N)
     b.resize(3)
     a = np.arange(3)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#2
0
文件: test_carray.py 项目: 87/carray
 def test01(self):
     """Testing `trim()` method (small chunklen)"""
     b = ca.arange(1e2, chunklen=2)
     b.trim(5)
     a = np.arange(1e2 - 5)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#3
0
文件: test_carray.py 项目: 87/carray
 def test02(self):
     """Testing `resize()` method (zero size)"""
     b = ca.arange(self.N)
     b.resize(0)
     a = np.arange(0)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#4
0
文件: test_carray.py 项目: 87/carray
 def test03(self):
     """Testing `trim()` method (complete trim)"""
     a = np.arange(0.)
     b = ca.arange(1e4)
     b.trim(1e4)
     #print "b->", `b`
     self.assert_(len(a) == len(b), "Lengths are not equal")
示例#5
0
文件: test_carray.py 项目: 87/carray
 def test02(self):
     """Testing `trim()` method (large trim)"""
     a = np.arange(2)
     b = ca.arange(1e4)
     b.trim(1e4-2)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#6
0
文件: test_carray.py 项目: 87/carray
 def test01(self):
     """Testing `trim()` method (small chunklen)"""
     b = ca.arange(1e2, chunklen=2)
     b.trim(5)
     a = np.arange(1e2-5)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#7
0
文件: test_carray.py 项目: 87/carray
 def test05(self):
     """Testing `trim()` method (trimming zero items)"""
     a = np.arange(1e1)
     b = ca.arange(1e1)
     b.trim(0)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#8
0
文件: test_carray.py 项目: 87/carray
 def test00(self):
     """Testing `trim()` method"""
     b = ca.arange(1e3)
     b.trim(3)
     a = np.arange(1e3 - 3)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#9
0
 def test01(self):
     """Testing evaluation of ndcarrays (int out)"""
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     outa = eval("a*2.+1")
     outb = ca.eval("b*2.+1")
     assert_array_equal(outa, outb, "Arrays are not equal")
示例#10
0
 def test01(self):
     """Testing evaluation of ndcarrays (int out)"""
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     outa = eval("a*2.+1")
     outb = ca.eval("b*2.+1")
     assert_array_equal(outa, outb, "Arrays are not equal")
示例#11
0
文件: test_carray.py 项目: 87/carray
 def test02(self):
     """Testing `trim()` method (large trim)"""
     a = np.arange(2)
     b = ca.arange(1e4)
     b.trim(1e4 - 2)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#12
0
 def test02b(self):
     """Testing `reshape()` (ndim -> ndim, II)"""
     a = np.arange(24, dtype="i4").reshape((2,3,4))
     c = ca.arange(24, dtype="i4").reshape((4,3,2))
     b = c.reshape((2,3,4))
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
示例#13
0
 def test00b(self):
     """Testing evaluation of ndcarrays (bool out, NumPy)"""
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     outa = eval("a>0")
     outb = ca.eval("b>0", out_flavor='numpy')
     assert_array_equal(outa, outb, "Arrays are not equal")
示例#14
0
文件: test_carray.py 项目: 87/carray
 def test00(self):
     """Testing `trim()` method"""
     b = ca.arange(1e3)
     b.trim(3)
     a = np.arange(1e3-3)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#15
0
 def test02b(self):
     """Testing `reshape()` (ndim -> ndim, II)"""
     a = np.arange(24, dtype="i4").reshape((2, 3, 4))
     c = ca.arange(24, dtype="i4").reshape((4, 3, 2))
     b = c.reshape((2, 3, 4))
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
示例#16
0
文件: test_carray.py 项目: 87/carray
 def test02(self):
     """Testing `resize()` method (zero size)"""
     b = ca.arange(self.N)
     b.resize(0)
     a = np.arange(0)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#17
0
文件: test_carray.py 项目: 87/carray
 def test03(self):
     """Testing `trim()` method (complete trim)"""
     a = np.arange(0.)
     b = ca.arange(1e4)
     b.trim(1e4)
     #print "b->", `b`
     self.assert_(len(a) == len(b), "Lengths are not equal")
示例#18
0
文件: test_carray.py 项目: 87/carray
 def test01a(self):
     """Testing `resize()` method (decrease, large variation)"""
     b = ca.arange(self.N)
     b.resize(3)
     a = np.arange(3)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#19
0
文件: test_carray.py 项目: 87/carray
 def test05(self):
     """Testing `trim()` method (trimming zero items)"""
     a = np.arange(1e1)
     b = ca.arange(1e1)
     b.trim(0)
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#20
0
 def test00b(self):
     """Testing `carray` reshape (large shape)"""
     a = np.arange(16000).reshape((20,20,40))
     b = ca.arange(16000, rootdir=self.rootdir).reshape((20,20,40))
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
示例#21
0
文件: test_carray.py 项目: 87/carray
 def test00b(self):
     """Testing `resize()` method (increase)"""
     b = ca.arange(self.N)
     b.resize(self.N+3)
     a = np.arange(self.N+3)
     a[self.N:] = 0
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#22
0
文件: test_carray.py 项目: 87/carray
 def test01b(self):
     """Testing `resize()` method (increase, large variation)"""
     b = ca.arange(self.N, dflt=1)
     b.resize(self.N * 3)
     a = np.arange(self.N * 3)
     a[self.N:] = 1
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#23
0
文件: test_carray.py 项目: 87/carray
 def test01b(self):
     """Testing `resize()` method (increase, large variation)"""
     b = ca.arange(self.N, dflt=1)
     b.resize(self.N*3)
     a = np.arange(self.N*3)
     a[self.N:] = 1
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#24
0
文件: test_carray.py 项目: 87/carray
 def test06(self):
     """Testing `trim()` method (negative number of items)"""
     a = np.arange(2e1)
     b = ca.arange(1e1)
     b.trim(-10)
     a[10:] = 0
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#25
0
文件: test_carray.py 项目: 87/carray
 def test00b(self):
     """Testing `resize()` method (increase)"""
     b = ca.arange(self.N)
     b.resize(self.N + 3)
     a = np.arange(self.N + 3)
     a[self.N:] = 0
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#26
0
 def test00a(self):
     """Testing `carray` reshape"""
     a = np.arange(16).reshape((2,2,4))
     b = ca.arange(16, rootdir=self.rootdir).reshape((2,2,4))
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
示例#27
0
 def test02(self):
     """Testing iter() in combination with a list constructor"""
     b = ca.arange(self.N, dtype="f4")
     blist = list(b)
     blist1 = [r for r in b.iter(3,10)]
     self.assert_(blist1 == range(3,10))
     blist2 = list(b)
     self.assert_(blist == blist2, "iter() not working correctly")
示例#28
0
文件: test_carray.py 项目: 87/carray
 def test06(self):
     """Testing `trim()` method (negative number of items)"""
     a = np.arange(2e1)
     b = ca.arange(1e1)
     b.trim(-10)
     a[10:] = 0
     #print "b->", `b`
     assert_array_equal(a, b[:], "Arrays are not equal")
示例#29
0
文件: test_queries.py 项目: 87/carray
 def test02(self):
     """Testing iter() in combination with a list constructor"""
     b = ca.arange(self.N, dtype="f4")
     blist = list(b)
     blist1 = [r for r in b.iter(3, 10)]
     self.assert_(blist1 == range(3, 10))
     blist2 = list(b)
     self.assert_(blist == blist2, "where() not working correctly")
示例#30
0
 def test02(self):
     """Testing evaluation of ndcarrays (reduction)"""
     # Reduction ops are not supported yet
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     if ca.defaults.eval_vm:
         self.assertRaises(NotImplementedError, ca.eval, "sum(b)", depth=3)
     else:
         self.assertRaises(NotImplementedError, ca.eval, "b.sum(axis=0)", depth=3)
示例#31
0
 def test02(self):
     """Testing evaluation of ndcarrays (reduction, no axis)"""
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     if ca.defaults.eval_vm == "python":
         assert_array_equal(sum(a), ca.eval("sum(b)"),
                            "Arrays are not equal")
     else:
         self.assertEqual(a.sum(), ca.eval("sum(b)"))
示例#32
0
 def test01a(self):
     """Testing where() in combination with a list constructor"""
     a = ca.zeros(self.N, dtype="bool")
     a[30:40] = ca.ones(10, dtype="bool")
     b = ca.arange(self.N, dtype="f4")
     blist = list(b)
     blist1 = [r for r in b.where(a)]
     self.assert_(blist1 == range(30,40))
     blist2 = list(b)
     self.assert_(blist == blist2, "where() not working correctly")
示例#33
0
文件: test_queries.py 项目: 87/carray
 def test01(self):
     """Testing where() in combination with a list constructor"""
     a = ca.zeros(self.N, dtype="bool")
     a[30:40] = ca.ones(10, dtype="bool")
     b = ca.arange(self.N, dtype="f4")
     blist = list(b)
     blist1 = [r for r in b.where(a)]
     self.assert_(blist1 == range(30, 40))
     blist2 = list(b)
     self.assert_(blist == blist2, "where() not working correctly")
示例#34
0
 def test02b(self):
     """Testing evaluation of ndcarrays (reduction, with axis)"""
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     if ca.defaults.eval_vm == "python":
         # The Python VM does not have support for `axis` param
         assert_array_equal(sum(a), ca.eval("sum(b)"),
                            "Arrays are not equal")
     else:
         assert_array_equal(a.sum(axis=1), ca.eval("sum(b, axis=1)"),
                            "Arrays are not equal")
示例#35
0
文件: test_ctable.py 项目: 87/carray
 def test06(self):
     """Testing eval() with a mix of columns, numpy arrays and carrays"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     a = np.arange(N)
     b = ca.arange(N)
     ctr = t.eval("f0 + f1 - a + b")
     rar = ra['f0'] + ra['f1'] - a + b
     #print "ctable ->", ctr
     #print "numpy  ->", rar
     assert_array_equal(ctr[:], rar, "ctable values are not correct")
示例#36
0
 def test02(self):
     """Testing evaluation of ndcarrays (reduction)"""
     # Reduction ops are not supported yet
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     if ca.defaults.eval_vm:
         self.assertRaises(NotImplementedError, ca.eval, "sum(b)", depth=3)
     else:
         self.assertRaises(NotImplementedError,
                           ca.eval,
                           "b.sum(axis=0)",
                           depth=3)
示例#37
0
 def test06(self):
     """Testing eval() with a mix of columns, numpy arrays and carrays"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     a = np.arange(N)
     b = ca.arange(N)
     ctr = t.eval("f0 + f1 - a + b")
     rar = ra['f0'] + ra['f1'] - a + b
     #print "ctable ->", ctr
     #print "numpy  ->", rar
     assert_array_equal(ctr[:], rar, "ctable values are not correct")
示例#38
0
文件: test_carray.py 项目: 87/carray
 def test03(self):
     """Testing arange() with a `dtype`."""
     a = np.arange(self.N, dtype="i1")
     ac = ca.arange(self.N, dtype="i1")
     self.assert_(np.all(a == ac))
示例#39
0
文件: arange.py 项目: rayleyva/carray
import numpy as np
import carray as ca
from time import time

N = 1e8
dtype = "i4"

start, stop, step = 5, N, 4

t0 = time()
a = np.arange(start, stop, step, dtype=dtype)
print "Time numpy.arange() --> %.3f" % (time() - t0)

t0 = time()
ac = ca.arange(start, stop, step, dtype=dtype)
print "Time carray.arange() --> %.3f" % (time() - t0)

print "ac-->", ` ac `

# assert(np.all(a == ac))
示例#40
0
文件: test_carray.py 项目: 87/carray
 def test04(self):
     """Testing `trim()` method (trimming more than available items)"""
     a = np.arange(0.)
     b = ca.arange(1e4)
     #print "b->", `b`
     self.assertRaises(ValueError, b.trim, 1e4+1)
示例#41
0
文件: arange.py 项目: 87/carray
import numpy as np
import carray as ca
from time import time

N = 1e8
dtype = 'i4'

start, stop, step = 5, N, 4

t0 = time()
a = np.arange(start, stop, step, dtype=dtype)
print "Time numpy.arange() --> %.3f" % (time()-t0)

t0 = time()
ac = ca.arange(start, stop, step, dtype=dtype)
print "Time carray.arange() --> %.3f" % (time()-t0)

print "ac-->", `ac`

#assert(np.all(a == ac))
示例#42
0
 def test00(self):
     """Testing `carray` constructor"""
     a = np.arange(16).reshape((2, 2, 4))
     b = ca.arange(16).reshape((2, 2, 4))
     # print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
示例#43
0
 def test01b(self):
     """Testing where() with a multidimensional array"""
     a = ca.zeros((self.N, 10), dtype="bool")
     a[30:40] = ca.ones(10, dtype="bool")
     b = ca.arange(self.N*10, dtype="f4").reshape((self.N, 10))
     self.assertRaises(NotImplementedError, b.where, a)
示例#44
0
文件: test_carray.py 项目: 87/carray
 def test02(self):
     """Testing arange() with a `start`, `stop` and `step`."""
     a = np.arange(3, self.N, 4)
     ac = ca.arange(3, self.N, 4)
     self.assert_(np.all(a == ac))
示例#45
0
文件: test_carray.py 项目: 87/carray
 def test04(self):
     """Testing `trim()` method (trimming more than available items)"""
     a = np.arange(0.)
     b = ca.arange(1e4)
     #print "b->", `b`
     self.assertRaises(ValueError, b.trim, 1e4 + 1)
示例#46
0
文件: test_carray.py 项目: 87/carray
 def test00(self):
     """Testing arange() with only a `stop`."""
     a = np.arange(self.N)
     ac = ca.arange(self.N)
     self.assert_(np.all(a == ac))
示例#47
0
文件: test_carray.py 项目: 87/carray
 def test02(self):
     """Testing arange() with a `start`, `stop` and `step`."""
     a = np.arange(3, self.N, 4)
     ac = ca.arange(3, self.N, 4)
     self.assert_(np.all(a == ac))
示例#48
0
文件: test_carray.py 项目: 87/carray
 def test03(self):
     """Testing arange() with a `dtype`."""
     a = np.arange(self.N, dtype="i1")
     ac = ca.arange(self.N, dtype="i1")
     self.assert_(np.all(a == ac))
示例#49
0
 def test00(self):
     """Testing `carray` constructor"""
     a = np.arange(16).reshape((2, 2, 4))
     b = ca.arange(16).reshape((2, 2, 4))
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
示例#50
0
文件: test_carray.py 项目: 87/carray
 def test00(self):
     """Testing arange() with only a `stop`."""
     a = np.arange(self.N)
     ac = ca.arange(self.N)
     self.assert_(np.all(a == ac))