Beispiel #1
0
def test_manifest_func():
    x = Array([1, 2, 3])
    y = Array([1, 2, 3])

    val = add(x, y)

    assert val[0] == 2
    assert val[1] == 4
    assert val[2] == 6
Beispiel #2
0
def test_all_construct():
    # Assert that the pretty pritner works for all of the
    # toplevel structures

    expected_ds = dshape('3, int')

    a = NDArray([1,2,3])
    str(a)
    repr(a)
    a.datashape._equal(expected_ds)

    a = Array([1,2,3])
    str(a)
    repr(a)
    a.datashape._equal(expected_ds)


    a = NDTable([(1, 1)])
    str(a)
    repr(a)
    #a.datashape._equal(expected_ds)

    a = Table([(1, 1)])
    str(a)
    repr(a)
def test_getitem_nd():
    # create
    nd = ndarr()
    barray = Array(nd)

    # read
    data = barray[:]

    assert np.all(data == nd)
Beispiel #4
0
def test_simple_persistence():
    import tempfile, shutil, os.path
    import numpy as np
    from blaze import Array, dshape, params
    ds = dshape('2, 2, float64')
    data = np.zeros(4).reshape(2,2)
    td = tempfile.mkdtemp()
    tmppath = os.path.join(td, 'a')

    a = Array([1,2,3,4], ds, params=params(storage=tmppath))

    # Remove everything under the temporary dir
    shutil.rmtree(td)
Beispiel #5
0
def dd_as_py(dd):
    """
    Converts the data in a data descriptor into Python
    types. This uses the data_descriptor iteration methods,
    so is not expected to be fast. Its main initial purpose
    is to assist with writing unit tests.
    """
    # TODO: This function should probably be removed.
    if not isinstance(dd, IDataDescriptor):
        raise TypeError('expected DataDescriptor, got %r' % type(dd))

    if isinstance(dd, BLZDataDescriptor):
        return [dd_as_py(child_dd) for child_dd in dd]

    if dd.capabilities.deferred:
        from blaze import Array, eval
        dd = eval(Array(dd))._data
    return nd.as_py(dd.dynd_arr())
def test_getitem_nd_persistent():
    import tempfile, shutil, os.path

    td = tempfile.mkdtemp()
    path = os.path.join(td, 'test.blz')

    # write
    bparams = params(storage=path, clevel=6)
    nd = ndarr()
    barray = Array(nd, params=bparams)

    # read
    arr = open(path)
    data = arr[:]

    assert np.all(data == nd)

    shutil.rmtree(td)
Beispiel #7
0
def arr():
    return Array([1, 2, 3], '3, int32')
Beispiel #8
0
def test_simple_session():
    from blaze import Array, dshape
    ds = dshape('2, 2, int')

    a = Array([1,2,3,4], ds)