Exemplo n.º 1
0
 def test01b(self):
     """Testing zeros() constructor, with a `dtype`."""
     a = np.zeros(self.N, dtype='i4')
     ac = ca.zeros(self.N, dtype='i4')
     #print "dtypes-->", a.dtype, ac.dtype
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Exemplo n.º 2
0
 def test01c(self):
     """Testing zeros() constructor, with a string type."""
     a = np.zeros(self.N, dtype='S5')
     ac = ca.zeros(self.N, dtype='S5')
     #print "ac-->", `ac`
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Exemplo n.º 3
0
 def test01c(self):
     """Testing zeros() constructor, with a string type."""
     a = np.zeros(self.N, dtype='S5')
     ac = ca.zeros(self.N, dtype='S5')
     #print "ac-->", `ac`
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Exemplo n.º 4
0
 def test01b(self):
     """Testing zeros() constructor, with a `dtype`."""
     a = np.zeros(self.N, dtype='i4')
     ac = ca.zeros(self.N, dtype='i4')
     #print "dtypes-->", a.dtype, ac.dtype
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Exemplo n.º 5
0
 def test01c(self):
     """Testing `zeros` constructor (III)"""
     a = np.zeros((2,2), dtype='(4,)i4')
     b = ca.zeros((2,2), 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")
Exemplo n.º 6
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
Exemplo n.º 7
0
 def test00a(self):
     """Testing wheretrue() in combination with a list constructor"""
     a = ca.zeros(self.N, dtype="bool")
     a[30:40] = ca.ones(10, dtype="bool")
     alist = list(a)
     blist1 = [r for r in a.wheretrue()]
     self.assert_(blist1 == range(30,40))
     alist2 = list(a)
     self.assert_(alist == alist2, "wheretrue() not working correctly")
Exemplo n.º 8
0
 def test00(self):
     """Testing wheretrue() in combination with a list constructor"""
     a = ca.zeros(self.N, dtype="bool")
     a[30:40] = ca.ones(10, dtype="bool")
     alist = list(a)
     blist1 = [r for r in a.wheretrue()]
     self.assert_(blist1 == range(30, 40))
     alist2 = list(a)
     self.assert_(alist == alist2, "wheretrue() not working correctly")
Exemplo n.º 9
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")
Exemplo n.º 10
0
 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")
Exemplo n.º 11
0
    def test00(self):
        """Creating and working with an extremely large carray (> 2**32)."""

        cn = ca.zeros(5e9, dtype="i1")
        self.assert_(len(cn) == int(5e9))

        # Now check some accesses
        cn[1] = 1
        self.assert_(cn[1] == 1)
        cn[int(2e9)] = 2
        self.assert_(cn[int(2e9)] == 2)
        cn[long(3e9)] = 3
        self.assert_(cn[long(3e9)] == 3)
        cn[-1] = 4
        self.assert_(cn[-1] == 4)

        self.assert_(cn.sum() == 10)
Exemplo n.º 12
0
    def test00(self):
        """Creating and working with an extremely large carray (> 2**32)."""

        cn = ca.zeros(5e9, dtype="i1")
        self.assert_(len(cn) == int(5e9))

        # Now check some accesses
        cn[1] = 1
        self.assert_(cn[1] == 1)
        cn[int(2e9)] = 2
        self.assert_(cn[int(2e9)] == 2)
        cn[long(3e9)] = 3
        self.assert_(cn[long(3e9)] == 3)
        cn[-1] = 4
        self.assert_(cn[-1] == 4)

        self.assert_(cn.sum() == 10)
Exemplo n.º 13
0
Arquivo: zeros.py Projeto: 87/carray
import numpy as np
import carray as ca
from time import time

N = 1e8
dtype = 'i4'

t0 = time()
a = np.zeros(N, dtype=dtype)
print "Time numpy.zeros() --> %.4f" % (time()-t0)

t0 = time()
ac = ca.zeros(N, dtype=dtype)
#ac = ca.carray(a)
print "Time carray.zeros() --> %.4f" % (time()-t0)

print "ac-->", `ac`

#assert(np.all(a == ac))
Exemplo n.º 14
0
Arquivo: zeros.py Projeto: 87/carray
import numpy as np
import carray as ca
from time import time

N = 1e8
dtype = 'i4'

t0 = time()
a = np.zeros(N, dtype=dtype)
print "Time numpy.zeros() --> %.4f" % (time() - t0)

t0 = time()
ac = ca.zeros(N, dtype=dtype)
#ac = ca.carray(a)
print "Time carray.zeros() --> %.4f" % (time() - t0)

print "ac-->", ` ac `

#assert(np.all(a == ac))
Exemplo n.º 15
0
 def test01a(self):
     """Testing zeros() constructor."""
     a = np.zeros(self.N)
     ac = ca.zeros(self.N)
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Exemplo n.º 16
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)
Exemplo n.º 17
0
 def test00b(self):
     """Testing wheretrue() with a multidimensional array"""
     a = ca.zeros((self.N, 10), dtype="bool")
     a[30:40] = ca.ones(10, dtype="bool")
     self.assertRaises(NotImplementedError, a.wheretrue)
Exemplo n.º 18
0
 def test01c(self):
     """Testing `zeros` constructor (III)"""
     a = np.zeros((2, 2), dtype='(4,)i4')
     b = ca.zeros((2, 2), dtype='(4,)i4')
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Exemplo n.º 19
0
 def test01c(self):
     """Testing `zeros` constructor (III)"""
     a = np.zeros((2, 2), dtype="(4,)i4")
     b = ca.zeros((2, 2), dtype="(4,)i4")
     # print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Exemplo n.º 20
0
 def test02(self):
     """Testing sum() with strings (TypeError)."""
     ac = ca.zeros(10, 'S3')
     self.assertRaises(TypeError, ac.sum)
Exemplo n.º 21
0
 def test01a(self):
     """Testing zeros() constructor."""
     a = np.zeros(self.N)
     ac = ca.zeros(self.N)
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Exemplo n.º 22
0
## Benchmark to check the creation of an array of length > 2**32 (5e9)

import carray as ca
from time import time

t0 = time()
#cn = ca.zeros(5e9, dtype="i1")
cn = ca.zeros(5e9, dtype="i1", rootdir='large_carray-bench', mode='w')
print "Creation time:", round(time() - t0, 3)
assert len(cn) == int(5e9)

t0 = time()
cn = ca.carray(rootdir='large_carray-bench', mode='a')
print "Re-open time:", round(time() - t0, 3)
print "len(cn)", len(cn)
assert len(cn) == int(5e9)

# Now check some accesses
cn[1] = 1
assert cn[1] == 1
cn[int(2e9)] = 2
assert cn[int(2e9)] == 2
cn[long(3e9)] = 3
assert cn[long(3e9)] == 3
cn[-1] = 4
assert cn[-1] == 4

t0 = time()
assert cn.sum() == 10
print "Sum time:", round(time() - t0, 3)
Exemplo n.º 23
0
 def test02(self):
     """Testing sum() with strings (TypeError)."""
     ac = ca.zeros(10, 'S3')
     self.assertRaises(TypeError, ac.sum)