def infer_datashape(source): if isinstance(source, np.ndarray): return from_numpy(source.shape, source.dtype) elif isinstance(source, list): # TODO: um yeah, we'd don't actually want to do this cast = np.array(source) return from_numpy(cast.shape, cast.dtype) else: return dynamic
def infer_datashape(source): """ The user has only provided us with a Python object ( could be a buffer interface, a string, a list, list of lists, etc) try our best to infer what the datashape should be in the context of what it would mean as a CArray. """ if isinstance(source, np.ndarray): return from_numpy(source.shape, source.dtype) elif isinstance(source, list): # TODO: um yeah, we'd don't actually want to do this cast = np.array(source) return from_numpy(cast.shape, cast.dtype) else: return dynamic
def infer_datashape(source): """ The user has only provided us with a Python object ( could be a buffer interface, a string, a list, list of lists, etc) try our best to infer what the datashape should be in the context of this datasource. """ if isinstance(source, np.ndarray): return from_numpy(source.shape, source.dtype) elif isinstance(source, list): # TODO: um yeah, we'd don't actually want to do this cast = np.array(source) return from_numpy(cast.shape, cast.dtype) else: return dynamic
def empty(self, dshape): """ Create a CArraySource from a datashape specification, downcasts into Numpy dtype and shape tuples if possible otherwise raises an exception. """ shape, dtype = from_numpy(dshape) return CArraySource(carray([], dtype))
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) self.dshape = dshape else: self.ca = carray.carray(data, rootdir=rootdir, cparams=cparams) self.dshape = from_numpy(self.ca.shape, self.ca.dtype)
def empty(self, dshape): shape, dtype = from_numpy(dshape) return CTableSource(carray([[]], dtype))
def test_from_numpy(): from_numpy((), np.int32) == blaze.int32 from_numpy((), np.int_) == blaze.int_ from_numpy((1,), np.int32) == blaze.dshape('1, int32') from_numpy((1,2), np.int32) == blaze.dshape('1, 2, int32')
def empty(self, datashape): shape, dtype = from_numpy(datashape) return ArraySource(np.ndarray(shape, dtype))
def test_from_numpy(self): self.assertEqual(from_numpy((), np.int32), blaze.int32) self.assertEqual(from_numpy((), np.int_), blaze.int_) self.assertEqual(from_numpy((1,), np.int32), blaze.dshape('1, int32')) self.assertEqual(from_numpy((1,2), np.int32), blaze.dshape('1, 2, int32'))
def test_from_numpy(): from_numpy((), np.int32) == blaze.int32 from_numpy((), np.int_) == blaze.int_ from_numpy((1, ), np.int32) == blaze.dshape('1, int32') from_numpy((1, 2), np.int32) == blaze.dshape('1, 2, int32')