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)
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)
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'))
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,))
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, ))
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)
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
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)
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_)
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))
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_))
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
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_
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