def ones(dshape, caps={'efficient-write': True}, storage=None):
    """Create an array and fill it with ones.

    Parameters
    ----------
    dshape : datashape
        The datashape for the resulting array.

    caps : capabilities dictionary
        A dictionary containing the desired capabilities of the array.

    storage : Storage instance
        A Storage object with the necessary info for data storage.

    Returns
    -------
    out: a concrete blaze array.

    """
    dshape = _normalize_dshape(dshape)
    storage = _storage_convert(storage)

    if storage is not None:
        shape, dt = to_numpy(dshape)
        dd = BLZDataDescriptor(blz.ones(shape, dt,
                                        rootdir=storage.path))
    elif 'efficient-write' in caps:
        # TODO: Handle var dimension properly (raise exception?)
        dyndarr = nd.empty(str(dshape))
        dyndarr[...] = True
        dd = DyNDDataDescriptor(dyndarr)
    elif 'compress' in caps:
        shape, dt = to_numpy(dshape)
        dd = BLZDataDescriptor(blz.ones(shape, dt))
    return Array(dd)
Exemple #2
0
def ones(dshape, caps={'efficient-write': True}, storage=None):
    """Create an array and fill it with ones.

    Parameters
    ----------
    dshape : datashape
        The datashape for the resulting array.

    caps : capabilities dictionary
        A dictionary containing the desired capabilities of the array.

    storage : Storage instance
        A Storage object with the necessary info for data storage.

    Returns
    -------
    out: a concrete blaze array.

    """
    dshape = _normalize_dshape(dshape)
    storage = _storage_convert(storage)

    if storage is not None:
        shape, dt = to_numpy(dshape)
        dd = BLZDataDescriptor(blz.ones(shape, dt, rootdir=storage.path))
    elif 'efficient-write' in caps:
        # TODO: Handle var dimension properly (raise exception?)
        dyndarr = nd.empty(str(dshape))
        dyndarr[...] = True
        dd = DyNDDataDescriptor(dyndarr)
    elif 'compress' in caps:
        shape, dt = to_numpy(dshape)
        dd = BLZDataDescriptor(blz.ones(shape, dt))
    return Array(dd)
Exemple #3
0
 def test02(self):
     """Testing `iter()` (w/ start, stop, step)"""
     a = np.ones((3, ), dtype="i4")
     b = blz.ones((1000, 3), dtype="i4")
     #print "b->", `b`
     for r in b.iter(15, 100, 3):
         assert_array_equal(a, r, "Arrays are not equal")
def ones(dshape, ddesc=None):
    """Create an array and fill it with ones.

    Parameters
    ----------
    dshape : datashape
        The datashape for the resulting array.

    ddesc : data descriptor instance
        This comes with the necessary info for storing the data.  If
        None, a DyND_DDesc will be used.

    Returns
    -------
    out: a concrete blaze array.

    """
    dshape = _normalize_dshape(dshape)

    if ddesc is None:
        ddesc = DyND_DDesc(nd.ones(str(dshape), access='rw'))
        return Array(ddesc)
    if isinstance(ddesc, BLZ_DDesc):
        shape, dt = to_numpy(dshape)
        ddesc.blzarr = blz.ones(
            shape, dt, rootdir=ddesc.path, mode=ddesc.mode, **ddesc.kwargs)
    elif isinstance(ddesc, HDF5_DDesc):
        obj = nd.as_numpy(nd.empty(str(dshape)))
        with tb.open_file(ddesc.path, mode=ddesc.mode) as f:
            where, name = split_path(ddesc.datapath)
            f.create_earray(where, name, filters=ddesc.filters, obj=obj)
        ddesc.mode = 'a'  # change into 'a'ppend mode for further operations
    return Array(ddesc)
Exemple #5
0
 def test02c(self):
     """Testing ones() constructor, with a string type"""
     a = np.ones(self.N, dtype='S3')
     ac = blz.ones(self.N, dtype='S3', rootdir=self.rootdir)
     #print "a-->", a, ac
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac[:]))
Exemple #6
0
 def test01(self):
     """Testing `resize()` (enlarge)"""
     a = np.ones((4,3), dtype="i4")
     b = blz.ones((3,3), dtype="i4", rootdir=self.rootdir)
     b.resize(4)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Exemple #7
0
 def test02(self):
     """Testing `iter()` (w/ start, stop, step)"""
     a = np.ones((3,), dtype="i4")
     b = blz.ones((1000,3), dtype="i4")
     #print "b->", `b`
     for r in b.iter(15, 100, 3):
         assert_array_equal(a, r, "Arrays are not equal")
Exemple #8
0
 def test01(self):
     """Testing `reshape()` (ndim -> unidim)"""
     a = np.ones(12, dtype="i4")
     c = blz.ones(12, dtype="i4").reshape((3,4))
     b = c.reshape(12)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Exemple #9
0
 def test01(self):
     """Testing `resize()` (enlarge)"""
     a = np.ones((4, 3), dtype="i4")
     b = blz.ones((3, 3), dtype="i4", rootdir=self.rootdir)
     b.resize(4)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Exemple #10
0
 def test01(self):
     """Testing `reshape()` (ndim -> unidim)"""
     a = np.ones(12, dtype="i4")
     c = blz.ones(12, dtype="i4").reshape((3, 4))
     b = c.reshape(12)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Exemple #11
0
 def test02(self):
     """Testing unicode types (iter)"""
     a = np.ones((3,), dtype="U40")
     b = blz.ones((1000,3), dtype="U40")
     #print "b->", `b`
     for r in b.iter():
         #print "r-->", r
         assert_array_equal(a, r, "Arrays are not equal")
Exemple #12
0
 def test02(self):
     """Testing `ones` constructor"""
     a = np.ones((2, 2), dtype='(4,)i4')
     b = blz.ones((2, 2), dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Exemple #13
0
 def test02(self):
     """Testing unicode types (iter)"""
     a = np.ones((3, ), dtype="U40")
     b = blz.ones((1000, 3), dtype="U40")
     #print "b->", `b`
     for r in b.iter():
         #print "r-->", r
         assert_array_equal(a, r, "Arrays are not equal")
Exemple #14
0
 def test00(self):
     """Testing compound types (creation)"""
     a = np.ones((300,4), dtype=self.dtype)
     b = blz.ones((300,4), dtype=self.dtype)
     #print "b.dtype-->", b.dtype
     #print "b->", `b`
     self.assert_(a.dtype == b.dtype.base)
     assert_array_equal(a, b[:], "Arrays are not equal")
Exemple #15
0
 def test00(self):
     """Testing compound types (creation)"""
     a = np.ones((300, 4), dtype=self.dtype)
     b = blz.ones((300, 4), dtype=self.dtype)
     #print "b.dtype-->", b.dtype
     #print "b->", `b`
     self.assert_(a.dtype == b.dtype.base)
     assert_array_equal(a, b[:], "Arrays are not equal")
Exemple #16
0
 def test02(self):
     """Testing `ones` constructor"""
     a = np.ones((2,2), dtype='(4,)i4')
     b = blz.ones((2,2), dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = blz.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Exemple #17
0
 def test03(self):
     """Testing `reshape()` (0-dim)"""
     a = np.ones((0, 4), dtype="i4")
     b = blz.ones(0, dtype="i4").reshape((0, 4))
     #print "b->", `b`
     # The next does not work well for barrays with shape (0,)
     #assert_array_equal(a, b, "Arrays are not equal")
     self.assert_(a.dtype.base == b.dtype.base)
     self.assert_(a.shape == b.shape + b.dtype.shape)
Exemple #18
0
 def test03(self):
     """Testing `reshape()` (0-dim)"""
     a = np.ones((0,4), dtype="i4")
     b = blz.ones(0, dtype="i4").reshape((0,4))
     #print "b->", `b`
     # The next does not work well for barrays with shape (0,)
     #assert_array_equal(a, b, "Arrays are not equal")
     self.assert_(a.dtype.base == b.dtype.base)
     self.assert_(a.shape == b.shape+b.dtype.shape)
Exemple #19
0
 def test00a(self):
     """Testing wheretrue() in combination with a list constructor"""
     a = blz.zeros(self.N, dtype="bool")
     a[30:40] = blz.ones(10, dtype="bool")
     alist = list(a)
     blist1 = [r for r in a.wheretrue()]
     self.assert_(blist1 == list(range(30,40)))
     alist2 = list(a)
     self.assert_(alist == alist2, "wheretrue() not working correctly")
Exemple #20
0
 def test00a(self):
     """Testing wheretrue() in combination with a list constructor"""
     a = blz.zeros(self.N, dtype="bool")
     a[30:40] = blz.ones(10, dtype="bool")
     alist = list(a)
     blist1 = [r for r in a.wheretrue()]
     self.assert_(blist1 == list(range(30, 40)))
     alist2 = list(a)
     self.assert_(alist == alist2, "wheretrue() not working correctly")
Exemple #21
0
 def test00b(self):
     """Testing `resize()` (trim to zero)"""
     a = np.ones((0, 3), dtype="i4")
     b = blz.ones((3, 3), dtype="i4", rootdir=self.rootdir)
     b.resize(0)
     #print "b->", `b`
     # The next does not work well for barrays with shape (0,)
     #assert_array_equal(a, b, "Arrays are not equal")
     self.assert_("a.dtype.base == b.dtype.base")
     self.assert_("a.shape == b.shape+b.dtype.shape")
Exemple #22
0
 def test00b(self):
     """Testing `resize()` (trim to zero)"""
     a = np.ones((0,3), dtype="i4")
     b = blz.ones((3,3), dtype="i4", rootdir=self.rootdir)
     b.resize(0)
     #print "b->", `b`
     # The next does not work well for barrays with shape (0,)
     #assert_array_equal(a, b, "Arrays are not equal")
     self.assert_("a.dtype.base == b.dtype.base")
     self.assert_("a.shape == b.shape+b.dtype.shape")
def ones(dshape, ddesc=None):
    """Create an array and fill it with ones.

    Parameters
    ----------
    dshape : datashape
        The datashape for the resulting array.

    ddesc : data descriptor instance
        This comes with the necessary info for storing the data.  If
        None, a DyND_DDesc will be used.

    Returns
    -------
    out: a concrete blaze array.

    """
    dshape = _normalize_dshape(dshape)

    if ddesc is None:
        ddesc = DyND_DDesc(nd.ones(str(dshape), access='rw'))
        return Array(ddesc)
    if isinstance(ddesc, BLZ_DDesc):
        shape, dt = to_numpy(dshape)
        ddesc.blzarr = blz.ones(shape,
                                dt,
                                rootdir=ddesc.path,
                                mode=ddesc.mode,
                                **ddesc.kwargs)
    elif isinstance(ddesc, HDF5_DDesc):
        obj = nd.as_numpy(nd.empty(str(dshape)))
        with tb.open_file(ddesc.path, mode=ddesc.mode) as f:
            where, name = split_path(ddesc.datapath)
            f.create_earray(where, name, filters=ddesc.filters, obj=obj)
        ddesc.mode = 'a'  # change into 'a'ppend mode for further operations
    return Array(ddesc)
Exemple #24
0
 def test02b(self):
     """Testing ones() constructor, with a `dtype`."""
     a = np.ones(self.N, dtype='i4')
     ac = blz.ones(self.N, dtype='i4', rootdir=self.rootdir)
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac[:]))
Exemple #25
0
 def test00b(self):
     """Testing wheretrue() with a multidimensional array"""
     a = blz.zeros((self.N, 10), dtype="bool")
     a[30:40] = blz.ones(10, dtype="bool")
     self.assertRaises(NotImplementedError, a.wheretrue)
Exemple #26
0
 def test00c(self):
     """Testing `reshape()` (unidim -> ndim, -1 in newshape (II))"""
     a = np.ones((3, 4), dtype="i4")
     b = blz.ones(12, dtype="i4").reshape((3, -1))
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Exemple #27
0
 def test00b(self):
     """Testing wheretrue() with a multidimensional array"""
     a = blz.zeros((self.N, 10), dtype="bool")
     a[30:40] = blz.ones(10, dtype="bool")
     self.assertRaises(NotImplementedError, a.wheretrue)
Exemple #28
0
 def test01b(self):
     """Testing where() with a multidimensional array"""
     a = blz.zeros((self.N, 10), dtype="bool")
     a[30:40] = blz.ones(10, dtype="bool")
     b = blz.arange(self.N * 10, dtype="f4").reshape((self.N, 10))
     self.assertRaises(NotImplementedError, b.where, a)
Exemple #29
0
 def test00c(self):
     """Testing `reshape()` (unidim -> ndim, -1 in newshape (II))"""
     a = np.ones((3,4), dtype="i4")
     b = blz.ones(12, dtype="i4").reshape((3,-1))
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Exemple #30
0
 def test02a(self):
     """Testing ones() constructor."""
     a = np.ones(self.N)
     ac = blz.ones(self.N, rootdir=self.rootdir)
     self.assert_(a.dtype == ac.dtype)
     self.assert_(np.all(a == ac[:]))
Exemple #31
0
 def test01b(self):
     """Testing where() with a multidimensional array"""
     a = blz.zeros((self.N, 10), dtype="bool")
     a[30:40] = blz.ones(10, dtype="bool")
     b = blz.arange(self.N*10, dtype="f4").reshape((self.N, 10))
     self.assertRaises(NotImplementedError, b.where, a)