Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
def dot(a_, b_):
    global _locals, _params
    vm = _params.get('vm', 'python')
    op1 = evaluate(a_, vm=vm, user_dict=_locals)
    op2 = evaluate(b_, vm=vm, user_dict=_locals)
    _locals = None   # get rid of references to operands
    _params = None   # get rid of references to params
    if len(op1.datashape.shape) > 1:
        from blaze.algo import linalg 
        return linalg.dot(op1, op2)
    else:
        return chunked_dot(op1, op2)
Пример #5
0
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
Пример #6
0
# Script for benchmarking OOC matrix matrix multiplication (only 2D supported)

import shutil, os.path
from time import time
import blaze

from blaze.algo.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