コード例 #1
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 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")
コード例 #2
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 def test02(self):
     """Testing `ones` constructor"""
     a = np.ones((2,2), dtype='(4,)i4')
     b = ca.ones((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")
コード例 #3
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 def test01b(self):
     """Testing `zeros` constructor (II)"""
     a = np.zeros(2, dtype='(2,4)i4')
     b = ca.zeros(2, dtype='(2,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")
コード例 #4
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 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")
コード例 #5
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 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")
コード例 #6
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 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")
コード例 #7
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 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")
コード例 #8
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 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")
コード例 #9
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 def test04c(self):
     """Testing `__getitem()__` method with shape reduction (III)"""
     a = np.arange(6000).reshape((50,40,3))
     b = ca.carray(a, rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = (1,slice(1,4,2),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")
コード例 #10
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 def test03c(self):
     """Testing `__getitem()__` method with several slices (III)"""
     a = np.arange(120*1000).reshape((5*1000,4,3,2))
     b = ca.carray(a, rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = (slice(None,None,3), slice(1,3,2), slice(1,4,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")
コード例 #11
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 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")
コード例 #12
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 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", rootdir=self.rootdir)
     sl = slice(1,8,3)
     a[sl,:] = range(2)
     b[sl] = range(2)
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`, `b`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
コード例 #13
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 def test00b(self):
     """Testing `__setitem()__` method with only a start (vector)"""
     a = np.ones((200,300), dtype="i4")*3
     b = ca.fill((200,300), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(1)
     a[sl,:] = range(300)
     b[sl] = range(300)
     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")
コード例 #14
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 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")
コード例 #15
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 def test01a(self):
     """Testing `__setitem()__` method with start,stop (scalar)"""
     a = np.ones((500,200), dtype="i4")*3
     b = ca.fill((500,200), 3, dtype="i4", rootdir=self.rootdir,
                 cparams=ca.cparams())
     sl = slice(100,400)
     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")
コード例 #16
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 def test03d(self):
     """Testing `__setitem()__` method with several slices (IV)"""
     a = np.arange(120).reshape((5,4,3,2))
     b = ca.carray(a, rootdir=self.rootdir)
     sl = (slice(1,3), slice(1,3,1), slice(1,None,2), slice(1))
     #print "before->", `b[sl]`
     a[sl] = 2
     b[sl] = 2
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "after->", `b[sl]`
     assert_array_equal(a[:], b[:], "Arrays are not equal")
コード例 #17
0
ファイル: test_ndcarray.py プロジェクト: Stiivi/carray
 def test04c(self):
     """Testing `__setitem()__` method with shape reduction (III)"""
     a = np.arange(24).reshape((4,3,2))
     b = ca.carray(a, rootdir=self.rootdir)
     sl = (1,2,slice(None,None,None))
     #print "before->", `b[sl]`
     a[sl] = 2
     b[sl] = 2
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "after->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
コード例 #18
0
ファイル: test_attrs.py プロジェクト: caglar/carray
    def test00b(self):
        """Accessing attributes in a opened carray."""

        cn = self.getobject()
        # Some attrs
        cn.attrs['attr1'] = 'val1'
        cn.attrs['attr2'] = 'val2'
        cn.attrs['attr3'] = 'val3'
        # Re-open the carray
        if self.rootdir:
            cn = ca.open(rootdir=self.rootdir)
        self.assert_(cn.attrs['attr1'] == 'val1')
        self.assert_(cn.attrs['attr2'] == 'val2')
        self.assert_(cn.attrs['attr3'] == 'val3')
        self.assert_(len(cn.attrs) == 3)
コード例 #19
0
ファイル: test_attrs.py プロジェクト: caglar/carray
    def test01c(self):
        """Appending attributes in a opened carray."""

        cn = self.getobject()
        # Some attrs
        cn.attrs['attr1'] = 'val1'
        # Reopen
        if self.rootdir:
            cn = ca.open(rootdir=self.rootdir)
        # Append attrs
        cn.attrs['attr2'] = 'val2'
        cn.attrs['attr3'] = 'val3'
        self.assert_(cn.attrs['attr1'] == 'val1')
        self.assert_(cn.attrs['attr2'] == 'val2')
        self.assert_(cn.attrs['attr3'] == 'val3')
        self.assert_(len(cn.attrs) == 3)
コード例 #20
0
ファイル: test_attrs.py プロジェクト: caglar/carray
    def test01b(self):
        """Removing attributes in a opened carray."""

        cn = self.getobject()
        # Some attrs
        cn.attrs['attr1'] = 'val1'
        cn.attrs['attr2'] = 'val2'
        cn.attrs['attr3'] = 'val3'
        # Reopen
        if self.rootdir:
            cn = ca.open(rootdir=self.rootdir)
        # Remove one of them
        del cn.attrs['attr2']
        self.assert_(cn.attrs['attr1'] == 'val1')
        self.assert_(cn.attrs['attr3'] == 'val3')
        self.assertRaises(KeyError, cn.attrs.__getitem__, 'attr2')
        self.assert_(len(cn.attrs) == 2)