def test_dot_shape_exception(): '''Dot product with wrong inner dimensions should raise exception.''' a = blaze.ones(blaze.dshape('20, 20, float64')) b = blaze.ones(blaze.dshape('30, 30, float64')) with assert_raises(ValueError): out = dot(a, b, outname=None)
def test_dot_not2d_exception(): '''Dot product of arrays other than 2D should raise exception.''' a = blaze.ones(blaze.dshape('20, 20, 20, float64')) b = blaze.ones(blaze.dshape('20, 20, 20, float64')) with assert_raises(ValueError): out = dot(a, b, outname=None)
def test_dot_out_exception(): '''Output array of wrong size should raise exception.''' a = blaze.ones(blaze.dshape('20, 20, float64')) b = blaze.ones(blaze.dshape('20, 30, float64')) out = blaze.zeros(blaze.dshape('20, 20, float64')) with assert_raises(ValueError): dot(a, b, out=out)
def test_dtw(): data = ones(dshape('100, float32')) query = ones(dshape('100, float32')) loc, dist = ucr.dtw(data, query, 0.1, 100, verbose=False) # these are stupid, mostly just to check for regressions assert isinstance(loc, int) assert isinstance(dist, float)
def test_dtw(): data = ones(dshape('100, float32')) query = ones(dshape('100, float32')) loc, dist = ucr.dtw(data, query, 0.1, 100, verbose=False) # these are stupid, mostly just to check for regressions assert isinstance(loc, int) assert isinstance(dist, float)
def test_dot(): '''Test of 2D dot product''' a = blaze.ones(blaze.dshape('20, 20, float64')) b = blaze.ones(blaze.dshape('20, 30, float64')) # Do not write output array to disk out = dot(a, b, outname=None) expected_ds = blaze.dshape('20, 30, float64') assert out.datashape._equal(expected_ds) # FIXME: Slow, but no other way to do this with Array API implemented so far for row in out: for elem in row: assert abs(elem - 20.0) < 1e-8
def test_metadata_has_prop(): a = blaze.ones(blaze.dshape('20, 20, float64')) c = blaze.NDTable([(1.0, 1.0), (1.0, 1.0)], dshape='2, {x: int32; y: float32}') assert blaze.metadata.has_prop(a, blaze.metadata.arraylike) assert blaze.metadata.has_prop(c, blaze.metadata.tablelike) assert not blaze.metadata.has_prop(a, blaze.metadata.tablelike)
def test_metadata_all_prop(): a = blaze.ones(blaze.dshape('20, 20, float64')) b = blaze.zeros(blaze.dshape('20, 20, float64')) c = blaze.NDTable([(1.0, 1.0), (1.0, 1.0)], dshape='2, {x: int32; y: float32}') assert blaze.metadata.all_prop((a, b), blaze.metadata.arraylike) assert not blaze.metadata.all_prop((a, b, c), blaze.metadata.arraylike)
def test_wrong_open_mode(self): ddesc = HDF5_DDesc(path=self.file, datapath='/earray', mode='w') a = blaze.ones('10 * float64', ddesc=ddesc) # Re-open the dataset ddesc = HDF5_DDesc(path=self.file, datapath='/earray', mode='r') self.assertTrue(ddesc.mode == 'r') a2 = blaze.array(ddesc) self.assertRaises(tb.FileModeError, append, a2, [1])
def test_wrong_open_mode(self): ddesc = BLZ_DDesc(path=self.rootdir, mode='w') a = blaze.ones('10 * float64', ddesc=ddesc) # Re-open the dataset ddesc = BLZ_DDesc(path=self.rootdir, mode='r') self.assertTrue(ddesc.mode == 'r') a2 = blaze.array(ddesc) self.assertRaises(IOError, append, a2, [1])
def test_metadata_has_prop(): a = blaze.ones(blaze.dshape('20, 20, float64')) c = blaze.NDTable([(1.0, 1.0), (1.0, 1.0)], dshape='2, {x: int32; y: float32}') assert blaze.metadata.has_prop(a, blaze.metadata.arraylike) assert blaze.metadata.has_prop(c, blaze.metadata.tablelike) assert not blaze.metadata.has_prop(a, blaze.metadata.tablelike)
def test_wrong_open_mode(self): ddesc = BLZ_DDesc(path=self.rootdir, mode='w') a = blaze.ones('10 * float64', ddesc=ddesc) # Re-open the dataset ddesc = BLZ_DDesc(path=self.rootdir, mode='r') self.assertTrue(ddesc.mode == 'r') a2 = blaze.array(ddesc) self.assertRaises(IOError, append, a2, [1])
def test_wrong_open_mode(self): ddesc = HDF5_DDesc(path=self.file, datapath='/earray', mode='w') a = blaze.ones('10 * float64', ddesc=ddesc) # Re-open the dataset ddesc = HDF5_DDesc(path=self.file, datapath='/earray', mode='r') self.assertTrue(ddesc.mode == 'r') a2 = blaze.array(ddesc) self.assertRaises(tb.FileModeError, append, a2, [1])
def test_metadata_all_prop(): a = blaze.ones(blaze.dshape('20, 20, float64')) b = blaze.zeros(blaze.dshape('20, 20, float64')) c = blaze.NDTable([(1.0, 1.0), (1.0, 1.0)], dshape='2, {x: int32; y: float32}') assert blaze.metadata.all_prop((a, b), blaze.metadata.arraylike) assert not blaze.metadata.all_prop((a, b, c), blaze.metadata.arraylike)
def test_open(self): persist = blaze.Persist(self.rooturi) a = blaze.ones('0, float64', persist=persist) a.append(range(10)) # Re-open the dataset in URI a2 = blaze.open(persist) self.assert_(isinstance(a2, blaze.Array)) self.assertEqual(dd_as_py(a2._data), list(range(10)))
def test_open(self): persist = blaze.Storage(self.rooturi, format="blz") a = blaze.ones('0 * float64', storage=persist) append(a,range(10)) # Re-open the dataset in URI a2 = blaze.open(persist) self.assertTrue(isinstance(a2, blaze.Array)) self.assertEqual(dd_as_py(a2._data), list(range(10)))
def test_open(self): ddesc = BLZ_DDesc(path=self.rootdir, mode='w') self.assertTrue(ddesc.mode == 'w') a = blaze.ones('0 * float64', ddesc=ddesc) append(a,range(10)) # Re-open the dataset ddesc = BLZ_DDesc(path=self.rootdir, mode='r') self.assertTrue(ddesc.mode == 'r') a2 = blaze.array(ddesc) self.assertTrue(isinstance(a2, blaze.Array)) self.assertEqual(ddesc_as_py(a2.ddesc), list(range(10)))
def test_open(self): ddesc = BLZ_DDesc(path=self.rootdir, mode='w') self.assertTrue(ddesc.mode == 'w') a = blaze.ones('0 * float64', ddesc=ddesc) append(a, range(10)) # Re-open the dataset ddesc = BLZ_DDesc(path=self.rootdir, mode='r') self.assertTrue(ddesc.mode == 'r') a2 = blaze.array(ddesc) self.assertTrue(isinstance(a2, blaze.Array)) self.assertEqual(ddesc_as_py(a2.ddesc), list(range(10)))
def test_open(self): ddesc = HDF5_DDesc(path=self.file, datapath='/earray', mode='a') self.assertTrue(ddesc.mode == 'a') a = blaze.ones('0 * float64', ddesc=ddesc) append(a, range(10)) # Re-open the dataset in URI ddesc = HDF5_DDesc(path=self.file, datapath='/earray', mode='r') self.assertTrue(ddesc.mode == 'r') a2 = blaze.array(ddesc) self.assertTrue(isinstance(a2, blaze.Array)) self.assertEqual(ddesc_as_py(a2.ddesc), list(range(10)))
def test_open(self): ddesc = HDF5_DDesc(path=self.file, datapath='/earray', mode='a') self.assertTrue(ddesc.mode == 'a') a = blaze.ones('0 * float64', ddesc=ddesc) append(a,range(10)) # Re-open the dataset in URI ddesc = HDF5_DDesc(path=self.file, datapath='/earray', mode='r') self.assertTrue(ddesc.mode == 'r') a2 = blaze.array(ddesc) self.assertTrue(isinstance(a2, blaze.Array)) self.assertEqual(ddesc_as_py(a2.ddesc), list(range(10)))
def test_ones(self): for t in self.full_types: a = ones(t) self.assertEqual(a.datashape, dshape(t))
def _create_persistent_array(name, dshape): print 'creating ' + name + '...' blaze.ones(dshape, params=blaze.params(storage=name, clevel=0))
def test_create_compress_ones(self): # A compressed array (backed by BLZ) a = blaze.ones('10 * int64', caps={'compress': True}) self.assertTrue(isinstance(a, blaze.Array)) self.assertEqual(dd_as_py(a._data), [1]*10)
def test_create_ones(self): # A default array a = blaze.ones('10 * int64') self.assertTrue(isinstance(a, blaze.Array)) self.assertEqual(dd_as_py(a._data), [1]*10)
# collection can be omitted. If that's the case, the dimensions will # be inferred. The following is thus equivalent: f = blaze.array([1, 2, 3], dshape='float32') print(f) # -------------------------------------------------------------------- print_section('Alternative constructors') # Arrays can be created to be all zeros: g = blaze.zeros('10 * 10 * int32') print(g) # All ones h = blaze.ones('10 * 10 * float64') print(h) # -------------------------------------------------------------------- print_section('Indexing') print_section('Indexing for read', level=1) print ('starting with a 4d array') array4d = blaze.ones('10 * 10 * 10 * 10 * float32') def describe_array(label, array): print(label) print('dshape: ', array.dshape) print(array)
def test_create_compress_ones(self): # A compressed array (backed by BLZ) ddesc = BLZ_DDesc(mode='w', bparams=blz.bparams(clevel=5)) a = blaze.ones('10 * int64', ddesc=ddesc) self.assertTrue(isinstance(a, blaze.Array)) self.assertEqual(list(a), [1]*10)
# Script for benchmarking OOC matrix matrix multiplication (only 2D supported) import shutil, os.path from time import time import blaze from linalg import dot # Remove pre-existent data directories for d in ('a', 'b', 'out'): if os.path.exists(d): shutil.rmtree(d) # Create simple inputs t0 = time() a = blaze.ones(blaze.dshape('2000, 2000, float64'), params=blaze.params(storage='a')) print "Time for matrix a creation : ", round(time()-t0, 3) t0 = time() b = blaze.ones(blaze.dshape('2000, 3000, float64'), params=blaze.params(storage='b')) print "Time for matrix b creation : ", round(time()-t0, 3) # Do the dot product t0 = time() out = dot(a, b, outname='out') print "Time for ooc matmul : ", round(time()-t0, 3) print "out:", out
def test_ones(): from blaze import ones, params a = ones('10, float64', params=params(clevel=5))
def test_ones(self): for t in self.full_types: a = ones(t) self.assertEqual(a.datashape, dshape(t))
def test_create_ones(self): # A default array (backed by NumPy) a = blaze.ones('10, int64') self.assert_(isinstance(a, blaze.Array)) self.assertEqual(dd_as_py(a._data), [1]*10)
def test_create_compress_ones(self): # A compressed array (backed by BLZ) ddesc = BLZ_DDesc(mode='w', bparams=blz.bparams(clevel=5)) a = blaze.ones('10 * int64', ddesc=ddesc) self.assertTrue(isinstance(a, blaze.Array)) self.assertEqual(list(a), [1] * 10)
def _create_persistent_array(name, dshape): print 'creating ' + name + '...' blaze.ones(dshape, params=blaze.params(storage=name, clevel=0))
def make_test_array(datashape): return blaze.ones(datashape) * randint(1, 10)
from blaze import ones from blaze.rts import execute from blaze.compile import compile, explain A = ones('100, 100, int32') B = ones('100, 100, int32') expr = (A + B) * B # Normally we just use expr.eval() but to demonstrate the compile # pipeline... plan = compile(expr) print explain(plan) print execute(plan)
# collection can be omitted. If that's the case, the dimensions will # be inferred. The following is thus equivalent: f = blaze.array([ 1, 2, 3], dshape='float32') print(f) # -------------------------------------------------------------------- print_section('Alternative constructors') # Arrays can be created to be all zeros: g = blaze.zeros('10, 10, int32') print(g) # All ones h = blaze.ones('10, 10, float64') print(h) # -------------------------------------------------------------------- print_section('Indexing') print_section('Indexing for read', level=1) print ('starting with a 4d array') array4d = blaze.ones('10,10,10,10, float32') def describe_array(label, array): print(label) print('dshape: ', array.dshape) print(array)
from blaze import manifest, delayed, ones from blaze.rts import execute from blaze.compile import compile, explain A = ones('100, 100, int32', eclass=delayed) B = ones('100, 100, int32', eclass=delayed) expr = (A + B) * B # Normally we just use expr.eval() but to demonstrate the compile # pipeline... plan = compile(expr) print plan print explain(plan) print execute(plan)
# collection can be omitted. If that's the case, the dimensions will # be inferred. The following is thus equivalent: f = blaze.array([1, 2, 3], dshape='float32') print(f) # -------------------------------------------------------------------- print_section('Alternative constructors') # Arrays can be created to be all zeros: g = blaze.zeros('10, 10, int32') print(g) # All ones h = blaze.ones('10, 10, float64') print(h) # -------------------------------------------------------------------- print_section('Indexing') print_section('Indexing for read', level=1) print('starting with a 4d array') array4d = blaze.ones('10,10,10,10, float32') def describe_array(label, array): print(label) print('dshape: ', array.dshape) print(array)
# Script for benchmarking OOC matrix matrix multiplication (only 2D supported) import shutil, os.path from time import time import blaze from linalg import dot # Remove pre-existent data directories for d in ('a', 'b', 'out'): if os.path.exists(d): shutil.rmtree(d) # Create simple inputs t0 = time() a = blaze.ones(blaze.dshape('2000, 2000, float64'), params=blaze.params(storage='a')) print "Time for matrix a creation : ", round(time() - t0, 3) t0 = time() b = blaze.ones(blaze.dshape('2000, 3000, float64'), params=blaze.params(storage='b')) print "Time for matrix b creation : ", round(time() - t0, 3) # Do the dot product t0 = time() out = dot(a, b, outname='out') print "Time for ooc matmul : ", round(time() - t0, 3) print "out:", out