コード例 #1
0
ファイル: test_linalg.py プロジェクト: renjiec/blaze-core
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)
コード例 #2
0
ファイル: test_linalg.py プロジェクト: renjiec/blaze-core
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)
コード例 #3
0
ファイル: test_linalg.py プロジェクト: renjiec/blaze-core
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)
コード例 #4
0
ファイル: test_dtw.py プロジェクト: garfee/blaze
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)
コード例 #5
0
ファイル: test_dtw.py プロジェクト: atbrox/blaze
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)
コード例 #6
0
ファイル: test_linalg.py プロジェクト: renjiec/blaze-core
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
コード例 #7
0
ファイル: test_metadata.py プロジェクト: c-mori/blaze-core
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)
コード例 #8
0
ファイル: test_metadata.py プロジェクト: c-mori/blaze-core
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)
コード例 #9
0
 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])
コード例 #10
0
 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])
コード例 #11
0
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)
コード例 #12
0
 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])
コード例 #13
0
 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])
コード例 #14
0
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)
コード例 #15
0
 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)))
コード例 #16
0
 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)))
コード例 #17
0
 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)))
コード例 #18
0
 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)))
コード例 #19
0
 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)))
コード例 #20
0
 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)))
コード例 #21
0
 def test_ones(self):
     for t in self.full_types:
         a = ones(t)
         self.assertEqual(a.datashape, dshape(t))
コード例 #22
0
def _create_persistent_array(name, dshape):
    print 'creating ' + name + '...'
    blaze.ones(dshape, params=blaze.params(storage=name, clevel=0))
コード例 #23
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)
コード例 #24
0
 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)
コード例 #25
0
# 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)
コード例 #26
0
 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)
コード例 #27
0
ファイル: example.py プロジェクト: atbrox/blaze
# 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
コード例 #28
0
ファイル: test_quickstart.py プロジェクト: renjiec/blaze-core
def test_ones():
    from blaze import ones, params

    a = ones('10, float64', params=params(clevel=5))
コード例 #29
0
 def test_ones(self):
     for t in self.full_types:
         a = ones(t)
         self.assertEqual(a.datashape, dshape(t))
コード例 #30
0
ファイル: test_array_creation.py プロジェクト: efrainra/blaze
 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)
コード例 #31
0
 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)
コード例 #32
0
ファイル: chunked_dot.py プロジェクト: renjiec/blaze-core
def _create_persistent_array(name, dshape):
    print 'creating ' + name + '...'
    blaze.ones(dshape, params=blaze.params(storage=name, clevel=0))
コード例 #33
0
def make_test_array(datashape):
    return blaze.ones(datashape) * randint(1, 10)
コード例 #34
0
ファイル: lazy.py プロジェクト: kanghaiyang/blaze
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)
コード例 #35
0
ファイル: array_creation.py プロジェクト: dreamfrog/blaze
# 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)
コード例 #36
0
ファイル: lazy.py プロジェクト: dlbrittain/blaze-core
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)
コード例 #37
0
# 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)
コード例 #38
0
ファイル: example.py プロジェクト: garfee/blaze
# 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