예제 #1
0
    def test01b(self):
        """Testing ctable creation in "w" mode"""
        N = 1e1
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8')+1)
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
        # Overwrite the last ctable
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir, mode='w')
        #print "t->", `t`
        ra = np.rec.fromarrays([a[:],b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")

        # Now check some accesses
        t.append((10, 11.0))
        t.append((10, 11.0))
        t[11] = (11, 12.0)

        # Check values
        N = 12
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8')+1)
        ra = np.rec.fromarrays([a[:],b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #2
0
    def test01b(self):
        """Testing ctable creation in "w" mode"""
        N = 1e1
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8') + 1)
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
        # Overwrite the last ctable
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir, mode='w')
        #print "t->", `t`
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")

        # Now check some accesses
        t.append((10, 11.0))
        t.append((10, 11.0))
        t[11] = (11, 12.0)

        # Check values
        N = 12
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8') + 1)
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #3
0
 def test04(self):
     """Testing append() with another ctable"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     ra2 = np.fromiter(((i, i*2.) for i in xrange(N, N+10)), dtype='i4,f8')
     t2 = ca.ctable(ra2)
     t.append(t2)
     ra = np.fromiter(((i, i*2.) for i in xrange(N+10)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #4
0
 def test04(self):
     """Testing append() with another ctable"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     ra2 = np.fromiter(((i, i * 2.) for i in xrange(N, N + 10)),
                       dtype='i4,f8')
     t2 = ca.ctable(ra2)
     t.append(t2)
     ra = np.fromiter(((i, i * 2.) for i in xrange(N + 10)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #5
0
 def test00b(self):
     """Testing ctable creation from a tuple of lists"""
     t = ca.ctable(([1,2,3],[4,5,6]), ('f0', 'f1'), rootdir=self.rootdir)
     #print "t->", `t`
     ra = np.rec.fromarrays([[1,2,3],[4,5,6]]).view(np.ndarray)
     #print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #6
0
    def test00c(self):
        """Testing ctable opening in "a" mode"""
        N = 1e1
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8') + 1)
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
        # Open t
        t = ca.open(rootdir=self.rootdir, mode='a')
        #print "t->", `t`

        # Check values
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")

        # Now check some accesses
        t.append((10, 11.0))
        t.append((10, 11.0))
        t[-1] = (11, 12.0)

        # Check values
        N = 12
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8') + 1)
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #7
0
    def test00c(self):
        """Testing ctable opening in "a" mode"""
        N = 1e1
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8')+1)
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
        # Open t
        t = ca.open(rootdir=self.rootdir, mode='a')
        #print "t->", `t`

        # Check values
        ra = np.rec.fromarrays([a[:],b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")

        # Now check some accesses
        t.append((10, 11.0))
        t.append((10, 11.0))
        t[-1] = (11, 12.0)

        # Check values
        N = 12
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8')+1)
        ra = np.rec.fromarrays([a[:],b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #8
0
 def test00(self):
     """Testing __len__()"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     self.assert_(len(t) == len(ra), "Objects do not have the same length")
예제 #9
0
 def test00b(self):
     """Testing ctable creation from a tuple of lists"""
     t = ca.ctable(([1, 2, 3], [4, 5, 6]), ('f0', 'f1'),
                   rootdir=self.rootdir)
     #print "t->", `t`
     ra = np.rec.fromarrays([[1, 2, 3], [4, 5, 6]]).view(np.ndarray)
     #print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #10
0
 def test00(self):
     """Testing append() with scalar values"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     t.append((N, N*2))
     ra = np.fromiter(((i, i*2.) for i in xrange(N+1)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #11
0
 def test01b(self):
     """Testing cparams when adding a new column (numpy flavor)"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, cparams=ca.cparams(1), rootdir=self.rootdir)
     c = np.arange(N, dtype='i8')*3
     t.addcol(c, 'f2')
     self.assert_(t['f2'].cparams.clevel == 1, "Incorrect clevel")
예제 #12
0
 def test01b(self):
     """Testing cparams when adding a new column (numpy flavor)"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, cparams=ca.cparams(1), rootdir=self.rootdir)
     c = np.arange(N, dtype='i8') * 3
     t.addcol(c, 'f2')
     self.assert_(t['f2'].cparams.clevel == 1, "Incorrect clevel")
예제 #13
0
 def test00(self):
     """Testing append() with scalar values"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     t.append((N, N * 2))
     ra = np.fromiter(((i, i * 2.) for i in xrange(N + 1)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #14
0
 def test02(self):
     """Testing ctable creation from an structured array"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     #print "t->", `t`
     #print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #15
0
 def test02(self):
     """Testing ctable creation from an structured array"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     #print "t->", `t`
     #print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #16
0
 def test01c(self):
     """Testing ctable creation in "a" mode"""
     N = 1e1
     a = ca.carray(np.arange(N, dtype='i4'))
     b = ca.carray(np.arange(N, dtype='f8')+1)
     t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
     # Overwrite the last ctable
     self.assertRaises(RuntimeError, ca.ctable, (a, b), ('f0', 'f1'),
                       rootdir=self.rootdir, mode='a')
예제 #17
0
 def test03(self):
     """Testing copy() with no shuffle"""
     N = 10 * 1000
     ra = np.fromiter(((i, i**2.2) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     # print "t:", t, t.rootdir
     t2 = t.copy(cparams=ca.cparams(shuffle=False), rootdir=self.rootdir)
     #print "cbytes in f1, f2:", t['f1'].cbytes, t2['f1'].cbytes
     self.assert_(t['f1'].cbytes < t2['f1'].cbytes, "clevel not changed")
예제 #18
0
 def test00(self):
     """Testing __getitem__ with only a start"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     start = 9
     #print "t->", `t`
     #print "ra[:]", ra[:]
     assert_array_equal(t[start], ra[start], "ctable values are not correct")
예제 #19
0
 def test02(self):
     """Testing __sizeof__() (small ctables)"""
     N = int(111)
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     #print "size t uncompressed ->", t.nbytes
     #print "size t compressed   ->", t.cbytes
     self.assert_(sys.getsizeof(t) > t.nbytes,
                  "ctable compress too much??")
예제 #20
0
 def test01(self):
     """Testing __sizeof__() (big ctables)"""
     N = int(1e4)
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     #print "size t uncompressed ->", t.nbytes
     #print "size t compressed   ->", t.cbytes
     self.assert_(sys.getsizeof(t) < t.nbytes,
                  "ctable does not seem to compress at all")
예제 #21
0
 def test03(self):
     """Testing copy() with no shuffle"""
     N = 10*1000
     ra = np.fromiter(((i, i**2.2) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     # print "t:", t, t.rootdir
     t2 = t.copy(cparams=ca.cparams(shuffle=False), rootdir=self.rootdir)
     #print "cbytes in f1, f2:", t['f1'].cbytes, t2['f1'].cbytes
     self.assert_(t['f1'].cbytes < t2['f1'].cbytes, "clevel not changed")
예제 #22
0
 def test02(self):
     """Testing __sizeof__() (small ctables)"""
     N = int(111)
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     #print "size t uncompressed ->", t.nbytes
     #print "size t compressed   ->", t.cbytes
     self.assert_(sys.getsizeof(t) > t.nbytes, "ctable compress too much??")
예제 #23
0
 def test01(self):
     """Testing ctable.iter() without params"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4, rootdir=self.rootdir)
     cl = [r.f1 for r in t.iter()]
     nl = [r['f1'] for r in ra]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
예제 #24
0
 def test03(self):
     """Testing fancy indexing (list of floats)"""
     N = 101
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = t[[2.3, 5.6]]
     rar = ra[[2.3, 5.6]]
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")
예제 #25
0
 def test07(self):
     """Testing ctable.iter() with start, stop, step and limit, skip"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4, rootdir=self.rootdir)
     cl = [r.f1 for r in t.iter(1,9,2, limit=2, skip=1)]
     nl = [r['f1'] for r in ra[1:9:2][1:3]]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
예제 #26
0
 def test02(self):
     """Testing copy() with lower clevel"""
     N = 10*1000
     ra = np.fromiter(((i, i**2.2) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     t2 = t.copy(cparams=ca.cparams(clevel=1))
     self.assert_(t.cparams.clevel == ca.cparams().clevel)
     self.assert_(t2.cparams.clevel == 1)
     #print "cbytes in f1, f2:", t['f1'].cbytes, t2['f1'].cbytes
     self.assert_(t['f1'].cbytes < t2['f1'].cbytes, "clevel not changed")
예제 #27
0
 def test03(self):
     """Testing ctable.iter() with outcols"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4, rootdir=self.rootdir)
     cl = [tuple(r) for r in t.iter(outcols='f2, nrow__, f0')]
     nl = [(r['f2'], i, r['f0']) for i, r in enumerate(ra)]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
예제 #28
0
 def test04(self):
     """Testing ctable.iter() with start,stop,step and outcols"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4, rootdir=self.rootdir)
     cl = [r for r in t.iter(1,9,3, 'f2, nrow__ f0')]
     nl = [(r['f2'], r['f0'], r['f0']) for r in ra[1:9:3]]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
예제 #29
0
 def test02(self):
     """Testing append() with carrays"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     a = np.arange(N, N+10, dtype='i4')
     b = np.arange(N, N+10, dtype='f8')*2.
     t.append((ca.carray(a), ca.carray(b)))
     ra = np.fromiter(((i, i*2.) for i in xrange(N+10)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #30
0
 def test02(self):
     """Testing fancy indexing with an empty list"""
     N = 10*1000
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = t[[]]
     rar = ra[[]]
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")
예제 #31
0
 def test01(self):
     """Testing ctable creation from a tuple of numpy arrays"""
     N = 1e1
     a = np.arange(N, dtype='i4')
     b = np.arange(N, dtype='f8')+1
     t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
     #print "t->", `t`
     ra = np.rec.fromarrays([a,b]).view(np.ndarray)
     #print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #32
0
 def test02(self):
     """Testing __getitem__ with start, stop, step"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     start, stop, step = 3, 9, 2
     #print "t->", `t[start:stop:step]`
     #print "ra->", ra[start:stop:step]
     assert_array_equal(t[start:stop:step], ra[start:stop:step],
                        "ctable values are not correct")
예제 #33
0
 def test02(self):
     """Testing append() with carrays"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     a = np.arange(N, N + 10, dtype='i4')
     b = np.arange(N, N + 10, dtype='f8') * 2.
     t.append((ca.carray(a), ca.carray(b)))
     ra = np.fromiter(((i, i * 2.) for i in xrange(N + 10)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #34
0
 def test03(self):
     """Testing __getitem__ with a column name"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     colname = "f1"
     #print "t->", `t[colname]`
     #print "ra->", ra[colname]
     assert_array_equal(t[colname][:], ra[colname],
                        "ctable values are not correct")
예제 #35
0
 def test02(self):
     """Testing copy() with lower clevel"""
     N = 10 * 1000
     ra = np.fromiter(((i, i**2.2) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     t2 = t.copy(cparams=ca.cparams(clevel=1))
     self.assert_(t.cparams.clevel == ca.cparams().clevel)
     self.assert_(t2.cparams.clevel == 1)
     #print "cbytes in f1, f2:", t['f1'].cbytes, t2['f1'].cbytes
     self.assert_(t['f1'].cbytes < t2['f1'].cbytes, "clevel not changed")
예제 #36
0
 def test03(self):
     """Testing __getitem__ with a column name"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     colname = "f1"
     #print "t->", `t[colname]`
     #print "ra->", ra[colname]
     assert_array_equal(t[colname][:], ra[colname],
                        "ctable values are not correct")
예제 #37
0
 def test01(self):
     """Testing ctable creation from a tuple of numpy arrays"""
     N = 1e1
     a = np.arange(N, dtype='i4')
     b = np.arange(N, dtype='f8') + 1
     t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
     #print "t->", `t`
     ra = np.rec.fromarrays([a, b]).view(np.ndarray)
     #print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #38
0
 def test02(self):
     """Testing __getitem__ with start, stop, step"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     start, stop, step = 3, 9, 2
     #print "t->", `t[start:stop:step]`
     #print "ra->", ra[start:stop:step]
     assert_array_equal(t[start:stop:step], ra[start:stop:step],
                        "ctable values are not correct")
예제 #39
0
 def test00(self):
     """Testing __getitem__ with only a start"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     start = 9
     #print "t->", `t`
     #print "ra[:]", ra[:]
     assert_array_equal(t[start], ra[start],
                        "ctable values are not correct")
예제 #40
0
 def test01(self):
     """Testing __sizeof__() (big ctables)"""
     N = int(1e4)
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     #print "size t uncompressed ->", t.nbytes
     #print "size t compressed   ->", t.cbytes
     self.assert_(
         sys.getsizeof(t) < t.nbytes,
         "ctable does not seem to compress at all")
예제 #41
0
 def test00b(self):
     """Testing fancy indexing (setitem) with a small list (II)"""
     N = 100
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=10)
     sl = [3,1]
     t[sl] = [(-1, -2, -3), (-3, -2, -1)]
     ra[sl] = [(-1, -2, -3), (-3, -2, -1)]
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #42
0
 def test01(self):
     """Testing fancy indexing (setitem) with a large array"""
     N = 1000
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=10)
     sl = np.random.randint(N, size=100)
     t[sl] = (-1, -2, -3)
     ra[sl] = (-1, -2, -3)
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #43
0
 def test02b(self):
     """Testing fancy indexing (setitem) with a boolean array (II)"""
     N = 1000
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=10)
     sl = np.random.randint(10, size=1000).astype('bool')
     t[sl] = [(-1, -2, -3)]
     ra[sl] = [(-1, -2, -3)]
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #44
0
 def test03b(self):
     """Testing fancy indexing (setitem) with a boolean array (all true)"""
     N = 1000
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=10)
     sl = np.ones(N, dtype="bool")
     t[sl] = [(-1, -2, -3)]
     ra[sl] = [(-1, -2, -3)]
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #45
0
 def test04(self):
     """Testing __setitem__ with a large step"""
     N = 100
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, chunklen=10, rootdir=self.rootdir)
     sl = slice(1, 43, 20)
     t[sl] = (0, 1)
     ra[sl] = (0, 1)
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #46
0
 def test08(self):
     """Testing removing an existing column (by name)"""
     N = 10
     ra = np.fromiter(((i, i*3, i*2.) for i in xrange(N)), dtype='i4,i8,f8')
     t = ca.ctable(ra, rootdir=self.rootdir)
     t.delcol('f1')
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     ra.dtype.names = ('f0', 'f2')
     #print "t->", `t`
     #print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #47
0
 def test04(self):
     """Testing __setitem__ with a large step"""
     N = 100
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, chunklen=10, rootdir=self.rootdir)
     sl = slice(1,43, 20)
     t[sl] = (0, 1)
     ra[sl] = (0, 1)
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #48
0
 def test01(self):
     """Testing fancy indexing with a large numpy array"""
     N = 10*1000
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     idx = np.random.randint(1000, size=1000)
     rt = t[idx]
     rar = ra[idx]
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")
예제 #49
0
 def test07(self):
     """Testing ctable.iter() with start, stop, step and limit, skip"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4, rootdir=self.rootdir)
     cl = [r.f1 for r in t.iter(1, 9, 2, limit=2, skip=1)]
     nl = [r['f1'] for r in ra[1:9:2][1:3]]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
예제 #50
0
 def test04(self):
     """Testing ctable.iter() with start,stop,step and outcols"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4, rootdir=self.rootdir)
     cl = [r for r in t.iter(1, 9, 3, 'f2, nrow__ f0')]
     nl = [(r['f2'], r['f0'], r['f0']) for r in ra[1:9:3]]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
예제 #51
0
 def test01c(self):
     """Testing ctable creation in "a" mode"""
     N = 1e1
     a = ca.carray(np.arange(N, dtype='i4'))
     b = ca.carray(np.arange(N, dtype='f8') + 1)
     t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
     # Overwrite the last ctable
     self.assertRaises(RuntimeError,
                       ca.ctable, (a, b), ('f0', 'f1'),
                       rootdir=self.rootdir,
                       mode='a')
예제 #52
0
 def test01(self):
     """Testing ctable.iter() without params"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4, rootdir=self.rootdir)
     cl = [r.f1 for r in t.iter()]
     nl = [r['f1'] for r in ra]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
예제 #53
0
 def test03(self):
     """Testing ctable.iter() with outcols"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4, rootdir=self.rootdir)
     cl = [tuple(r) for r in t.iter(outcols='f2, nrow__, f0')]
     nl = [(r['f2'], i, r['f0']) for i, r in enumerate(ra)]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
예제 #54
0
 def test03(self):
     """Testing fancy indexing (list of floats)"""
     N = 101
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = t[[2.3, 5.6]]
     rar = ra[[2.3, 5.6]]
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")
예제 #55
0
 def test02(self):
     """Testing fancy indexing with an empty list"""
     N = 10 * 1000
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = t[[]]
     rar = ra[[]]
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")
예제 #56
0
 def test03b(self):
     """Testing fancy indexing (setitem) with a boolean array (all true)"""
     N = 1000
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=10)
     sl = np.ones(N, dtype="bool")
     t[sl] = [(-1, -2, -3)]
     ra[sl] = [(-1, -2, -3)]
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #57
0
 def test02b(self):
     """Testing fancy indexing (setitem) with a boolean array (II)"""
     N = 1000
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=10)
     sl = np.random.randint(10, size=1000).astype('bool')
     t[sl] = [(-1, -2, -3)]
     ra[sl] = [(-1, -2, -3)]
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #58
0
 def test01(self):
     """Testing fancy indexing (setitem) with a large array"""
     N = 1000
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=10)
     sl = np.random.randint(N, size=100)
     t[sl] = (-1, -2, -3)
     ra[sl] = (-1, -2, -3)
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #59
0
 def test00b(self):
     """Testing fancy indexing (setitem) with a small list (II)"""
     N = 100
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=10)
     sl = [3, 1]
     t[sl] = [(-1, -2, -3), (-3, -2, -1)]
     ra[sl] = [(-1, -2, -3), (-3, -2, -1)]
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
예제 #60
0
 def test01(self):
     """Testing fancy indexing with a large numpy array"""
     N = 10 * 1000
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     idx = np.random.randint(1000, size=1000)
     rt = t[idx]
     rar = ra[idx]
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")