Example #1
0
 def test00b(self):
     """Testing `append()` method (correct shape, single row)"""
     a = np.ones((2,300), dtype="i4")*3
     b = ca.fill((1,300), 3, dtype="i4", rootdir=self.rootdir)
     b.append((3,)*300)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Example #2
0
 def test03c(self):
     """Testing fill() constructor, with a string type"""
     a = np.ones(self.N, dtype='S3')
     ac = ca.fill(self.N, "1", dtype='S3')
     #print "a-->", a, ac
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Example #3
0
 def test00b(self):
     """Testing `append()` method (correct shape, single row)"""
     a = np.ones((2, 3), dtype="i4") * 3
     b = ca.fill((1, 3), 3, dtype="i4")
     b.append((3, 3, 3))
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Example #4
0
 def test00(self):
     """Testing `__getitem()__` method with only a start"""
     a = np.ones((2, 3), dtype="i4") * 3
     b = ca.fill((2, 3), 3, dtype="i4")
     sl = slice(1)
     # print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #5
0
 def test03c(self):
     """Testing fill() constructor, with a string type"""
     a = np.ones(self.N, dtype='S3')
     ac = ca.fill(self.N, "1", dtype='S3')
     #print "a-->", a, ac
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Example #6
0
 def test02(self):
     """Testing `append()` method (several rows)"""
     a = np.ones((4,3), dtype="i4")*3
     b = ca.fill((1,3), 3, dtype="i4", rootdir=self.rootdir)
     b.append([(3,3,3)]*3)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Example #7
0
 def test02(self):
     """Testing `__getitem()__` method with a start, stop, step"""
     a = np.ones((10, 2), dtype="i4") * 3
     b = ca.fill((10, 2), 3, dtype="i4")
     sl = slice(1, 9, 2)
     # print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #8
0
 def test00a(self):
     """Testing `append()` method (correct shape)"""
     a = np.ones((2, 3), dtype="i4") * 3
     b = ca.fill((1, 3), 3, dtype="i4")
     b.append([(3, 3, 3)])
     # print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Example #9
0
 def test02(self):
     """Testing `append()` method (several rows)"""
     a = np.ones((4, 3), dtype="i4") * 3
     b = ca.fill((1, 3), 3, dtype="i4")
     b.append([(3, 3, 3)] * 3)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Example #10
0
 def test02(self):
     """Testing `__getitem()__` method with a start, stop, step"""
     a = np.ones((10, 2), dtype="i4") * 3
     b = ca.fill((10, 2), 3, dtype="i4")
     sl = slice(1, 9, 2)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #11
0
 def test00(self):
     """Testing `__getitem()__` method with only a start"""
     a = np.ones((2, 3), dtype="i4") * 3
     b = ca.fill((2, 3), 3, dtype="i4")
     sl = slice(1)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #12
0
 def test03b(self):
     """Testing `fill` constructor (array default)"""
     a = np.ones((2,2), dtype='(4,)i4')*3
     b = ca.fill((2,2), [3,3,3,3], 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")
Example #13
0
 def test01a(self):
     """Testing `__setitem()__` method with start,stop (scalar)"""
     a = np.ones((5, 2), dtype="i4") * 3
     b = ca.fill((5, 2), 3, dtype="i4")
     sl = slice(1, 4)
     a[sl, :] = 0
     b[sl] = 0
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #14
0
 def test02b(self):
     """Testing `__setitem()__` method with start,stop,step (scalar)"""
     a = np.ones((10, 2), dtype="i4") * 3
     b = ca.fill((10, 2), 3, dtype="i4")
     sl = slice(1, 8, 3)
     a[sl, :] = range(2)
     b[sl] = range(2)
     # print "b[sl]->", `b[sl]`, `b`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #15
0
 def test01a(self):
     """Testing `__setitem()__` method with start,stop (scalar)"""
     a = np.ones((5, 2), dtype="i4") * 3
     b = ca.fill((5, 2), 3, dtype="i4")
     sl = slice(1, 4)
     a[sl, :] = 0
     b[sl] = 0
     # print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #16
0
 def test00b(self):
     """Testing `__setitem()__` method with only a start (vector)"""
     a = np.ones((2, 3), dtype="i4") * 3
     b = ca.fill((2, 3), 3, dtype="i4")
     sl = slice(1)
     a[sl, :] = range(3)
     b[sl] = range(3)
     # print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #17
0
 def test00b(self):
     """Testing `__setitem()__` method with only a start (vector)"""
     a = np.ones((2, 3), dtype="i4") * 3
     b = ca.fill((2, 3), 3, dtype="i4")
     sl = slice(1)
     a[sl, :] = range(3)
     b[sl] = range(3)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #18
0
 def test02b(self):
     """Testing `__setitem()__` method with start,stop,step (scalar)"""
     a = np.ones((10, 2), dtype="i4") * 3
     b = ca.fill((10, 2), 3, dtype="i4")
     sl = slice(1, 8, 3)
     a[sl, :] = range(2)
     b[sl] = range(2)
     #print "b[sl]->", `b[sl]`, `b`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #19
0
 def test00b(self):
     """Testing `__getitem()__` method with only a start (slice)"""
     a = np.ones((27,2700), dtype="i4")*3
     b = ca.fill((27,2700), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = slice(1)
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #20
0
 def test04(self):
     """Testing `fill` constructor with open and resize (array default)"""
     a = np.ones((3,200), dtype='(4,)i4')*3
     b = ca.fill((2,200), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     c = np.ones((1,200), dtype='(4,)i4')*3
     b.append(c)
     #print "b->", `b`, len(b), b[1]
     assert_array_equal(a, b, "Arrays are not equal")
Example #21
0
 def test00a(self):
     """Testing `__getitem()__` method with only a start (scalar)"""
     a = np.ones((2,3), dtype="i4")*3
     b = ca.fill((2,3), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = 1
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #22
0
 def test02(self):
     """Testing `__getitem()__` method with a start, stop, step"""
     a = np.ones((10,2), dtype="i4")*3
     b = ca.fill((10,2), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = slice(1,9,2)
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #23
0
 def test05(self):
     """Testing `fill` constructor with open and resize (nchunks>1)"""
     a = np.ones((3,2000), dtype='(4,)i4')*3
     b = ca.fill((2,2000), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     c = np.ones((1,2000), dtype='(4,)i4')*3
     b.append(c)
     #print "b->", `b`
     # We need to use the b[:] here to overcome a problem with the
     # assert_array_equal() function
     assert_array_equal(a, b[:], "Arrays are not equal")
Example #24
0
 def test01b(self):
     """Testing `__setitem()__` method with start,stop (vector)"""
     a = np.ones((5,2), dtype="i4")*3
     b = ca.fill((5,2), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(1,4)
     a[sl,:] = range(2)
     b[sl] = range(2)
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #25
0
 def test02a(self):
     """Testing `__setitem()__` method with start,stop,step (scalar)"""
     a = np.ones((1000,200), dtype="i4")*3
     b = ca.fill((1000,200), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(100,800,3)
     a[sl,:] = 0
     b[sl] = 0
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Example #26
0
 def test03a(self):
     """Testing fill() constructor."""
     a = np.ones(self.N)
     ac = ca.fill(self.N, 1)
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Example #27
0
 def test03b(self):
     """Testing `fill` constructor (array default)"""
     a = np.ones((2, 2), dtype='(4,)i4') * 3
     b = ca.fill((2, 2), [3, 3, 3, 3], dtype='(4,)i4')
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Example #28
0
 def test03b(self):
     """Testing `fill` constructor (array default)"""
     a = np.ones((2, 2), dtype="(4,)i4") * 3
     b = ca.fill((2, 2), [3, 3, 3, 3], dtype="(4,)i4")
     # print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Example #29
0
 def test01(self):
     """Testing `append()` method (incorrect shape)"""
     a = np.ones((2, 3), dtype="i4") * 3
     b = ca.fill((1, 3), 3, dtype="i4")
     self.assertRaises(ValueError, b.append, [(3, 3)])
Example #30
0
 def test03b(self):
     """Testing fill() constructor, with a `dtype`."""
     a = np.ones(self.N, dtype='i4') * 3
     ac = ca.fill(self.N, 3, dtype='i4')
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Example #31
0
File: fill.py Project: 87/carray
import numpy as np
import carray as ca
from time import time

N = 1e8
dtype = 'i4'

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

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

print "ac-->", `ac`

t0 = time()
sa = a.sum()
print "Time a.sum() --> %.4f" % (time()-t0)

t0 = time()
sac = ac.sum()
print "Time ac.sum() --> %.4f" % (time()-t0)


assert(sa == sac)
Example #32
0
 def test03a(self):
     """Testing fill() constructor."""
     a = np.ones(self.N)
     ac = ca.fill(self.N, 1)
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))
Example #33
0
 def test01(self):
     """Testing `append()` method (incorrect shape)"""
     a = np.ones((2,3), dtype="i4")*3
     b = ca.fill((1,3), 3, dtype="i4", rootdir=self.rootdir)
     self.assertRaises(ValueError, b.append, [(3,3)])
Example #34
0
import numpy as np
import carray as ca
from time import time

N = 1e8
dtype = 'i4'

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

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

print "ac-->", ` ac `

t0 = time()
sa = a.sum()
print "Time a.sum() --> %.4f" % (time() - t0)

t0 = time()
sac = ac.sum()
print "Time ac.sum() --> %.4f" % (time() - t0)

assert (sa == sac)
Example #35
0
 def test03b(self):
     """Testing fill() constructor, with a `dtype`."""
     a = np.ones(self.N, dtype='i4')*3
     ac = ca.fill(self.N, 3, dtype='i4')
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac))