Example #1
0
def zeros(dshape, params=None):
    """ Create an Array and fill it with zeros.

    Parameters
    ----------
    dshape : str, blaze.dshape instance
        Specifies the datashape of the outcome object.
    params : blaze.params object
        Any parameter supported by the backend library.

    Returns
    -------
    out : an Array object.

    """
    if isinstance(dshape, basestring):
        dshape = _dshape(dshape)
    shape, dtype = to_numpy(dshape)
    cparams, rootdir, format_flavor = to_cparams(params or _params())
    if rootdir is not None:
        carray.zeros(shape, dtype, rootdir=rootdir, cparams=cparams)
        return open(rootdir)
    else:
        source = CArraySource(carray.zeros(shape, dtype, cparams=cparams),
                              params=params)
        return Array(source)
Example #2
0
def zeros(dshape, params=None):
    """ Create an Array and fill it with zeros.

    Parameters
    ----------
    dshape : str, blaze.dshape instance
        Specifies the datashape of the outcome object.
    params : blaze.params object
        Any parameter supported by the backend library.

    Returns
    -------
    out : an Array object.

    """
    if isinstance(dshape, basestring):
        dshape = _dshape(dshape)
    shape, dtype = to_numpy(dshape)
    cparams, rootdir, format_flavor = to_cparams(params or _params())
    if rootdir is not None:
        carray.zeros(shape, dtype, rootdir=rootdir, cparams=cparams)
        return open(rootdir)
    else:
        source = CArraySource(carray.zeros(shape, dtype, cparams=cparams),
                              params=params)
        return Array(source)
Example #3
0
    def __init__(self, data=None, dshape=None, params=None):
        # need at least one of the three
        assert (data is not None) or (dshape is not None) or \
               (params.get('storage'))

        if isinstance(data, ctable):
            self.ca = data
            return

        # Extract the relevant carray parameters from the more
        # general Blaze params object.
        if params:
            cparams, rootdir, format_flavor = to_cparams(params)
        else:
            rootdir,cparams = None, None

        # Extract the relevant carray parameters from the more
        # general Blaze params object.
        if dshape:
            shape, dtype = to_numpy(dshape)
            if len(data) == 0:
                data = np.empty(0, dtype=dtype)
                self.ca = ctable(data, rootdir=rootdir, cparams=cparams)
            else:
                self.ca = ctable(data, dtype=dtype, rootdir=rootdir)
        else:
            self.ca = ctable(data, rootdir=rootdir, cparams=cparams)
Example #4
0
def test_not_compat():
    with assert_raises(NotNumpyCompatible):
        to_numpy(dshape('x, int32'))

    with assert_raises(NotNumpyCompatible):
        to_numpy(dshape('{1}, int32'))

    with assert_raises(NotNumpyCompatible):
        to_numpy(dshape('Range(0, 3), int32'))
Example #5
0
def test_not_compat():
    with assert_raises(NotNumpyCompatible):
        to_numpy(dshape('x, int32'))

    with assert_raises(NotNumpyCompatible):
        to_numpy(dshape('{1}, int32'))

    with assert_raises(NotNumpyCompatible):
        to_numpy(dshape('Range(0, 3), int32'))
Example #6
0
def broadcast(*operands):
    types = [_get_datashape(op) for op in operands if op is not None]
    shapes = []
    for t in types:
        try:
            shapes.append(coretypes.extract_dims(t))
        except coretypes.NotNumpyCompatible:
            pass

    # TODO: broadcasting
    datashapes = [coretypes.to_numpy(coretypes.extract_measure(ds)) for ds in types]
    type = coretypes.promote_cvals(*datashapes)
    if not shapes:
        return type
    return DataShape(shapes[0] + (type,))
Example #7
0
def broadcast(*operands):
    types = [_get_datashape(op) for op in operands if op is not None]
    shapes = []
    for t in types:
        try:
            shapes.append(coretypes.extract_dims(t))
        except coretypes.NotNumpyCompatible:
            pass

    # TODO: broadcasting
    datashapes = [
        coretypes.to_numpy(coretypes.extract_measure(ds)) for ds in types
    ]
    type = coretypes.promote_cvals(*datashapes)
    if not shapes:
        return type
    return DataShape(shapes[0] + (type, ))
Example #8
0
    def __init__(self, data=None, dshape=None, params=None):
        # need at least one of the three
        assert (data is not None) or (dshape is not None) or \
               (params.get('storage'))

        # Extract the relevant carray parameters from the more
        # general Blaze params object.
        if params:
            cparams, rootdir, format_flavor = to_cparams(params)
        else:
            rootdir,cparams = None, None

        if dshape:
            dtype = to_numpy(dshape)
            self.ca = carray.carray(data, dtype, rootdir=rootdir)
        else:
            self.ca = carray.carray(data, rootdir=rootdir, cparams=cparams)
Example #9
0
    def __init__(self, data=None, dshape=None, params=None):
        # need at least one of the three
        assert (data is not None) or (dshape is not None) or \
               (params.get('storage'))

        # Extract the relevant carray parameters from the more
        # general Blaze params object.
        if params:
            cparams, rootdir, format_flavor = to_cparams(params)
        else:
            rootdir, cparams = None, None

        if dshape:
            shape, dtype = to_numpy(dshape)
            self.ca = carray.carray(data, dtype=dtype, rootdir=rootdir)
        else:
            self.ca = carray.carray(data, rootdir=rootdir, cparams=cparams)

        self.dshape = dshape
Example #10
0
    def __init__(self, data=None, dshape=None, params=None):
        """ CArray object passed directly into the constructor,
        ostensibly this is just a thin wrapper that consumes a
        reference.
        """
        # need at least one of the three
        assert (data is not None) or (dshape is not None) or (params.get("storage"))

        # TODO: clean up ugly conditionals

        if params:
            rootdir = params.get("storage")
            # compatabaility
            cparams = carray.cparams(params.get("clevel"), params.get("shuffle"))
        else:
            rootdir = None
            cparams = None

        if dshape:
            dtype = to_numpy(dshape)
            self.ca = carray.carray(data, dtype, rootdir=rootdir)
        else:
            self.ca = carray.carray(data, rootdir=rootdir, cparams=cparams)
Example #11
0
 def test_dtype_compat(self):
     self.assertEqual(to_numpy(blaze.int32), np.int32)
     self.assertEqual(to_numpy(blaze.int64), np.int64)
     self.assertEqual(to_numpy(blaze.float_), np.float_)
     self.assertEqual(to_numpy(blaze.int_), np.int_)
Example #12
0
 def test_shape_compat(self):
     self.assertEqual(to_numpy(dshape('1, int32')), ((1,), np.int32))
     self.assertEqual(to_numpy(dshape('1, 2, int32')), ((1, 2), np.int32))
     self.assertEqual(to_numpy(dshape('1, 2, 3, 4, int32')), ((1, 2, 3, 4), np.int32))
Example #13
0
 def test_dtype_compat(self):
     self.assertEqual(to_numpy(blaze.int32), np.dtype(np.int32))
     self.assertEqual(to_numpy(blaze.int64), np.dtype(np.int64))
     self.assertEqual(to_numpy(blaze.float_), np.dtype(np.float_))
     self.assertEqual(to_numpy(blaze.int_), np.dtype(np.int_))
Example #14
0
def test_shape_compat():
    to_numpy(dshape('1, int32')) == (1,), np.int32
    to_numpy(dshape('1, 2, int32')) == (1, 2), np.int32
    to_numpy(dshape('1, 2, 3, 4, int32')) == (1, 2, 3, 4), np.int32
Example #15
0
def test_dtype_compat():
    to_numpy(blaze.int32) == np.int32
    to_numpy(blaze.int64) == np.int64
    to_numpy(blaze.float_) == np.float_
    to_numpy(blaze.int_) == np.int_
Example #16
0
def test_dtype_compat():
    to_numpy(blaze.int32) == np.int32
    to_numpy(blaze.int64) == np.int64
    to_numpy(blaze.float_) == np.float_
    to_numpy(blaze.int_) == np.int_
Example #17
0
def test_shape_compat():
    to_numpy(dshape('1, int32')) == (1, ), np.int32
    to_numpy(dshape('1, 2, int32')) == (1, 2), np.int32
    to_numpy(dshape('1, 2, 3, 4, int32')) == (1, 2, 3, 4), np.int32
Example #18
0
 def test_shape_compat(self):
     self.assertEqual(to_numpy(dshape('1, int32')), ((1,), np.int32))
     self.assertEqual(to_numpy(dshape('1, 2, int32')), ((1, 2), np.int32))
     self.assertEqual(to_numpy(dshape('1, 2, 3, 4, int32')), ((1, 2, 3, 4), np.int32))