Ejemplo n.º 1
0
def test_evaluate_with_functional_array():
    input = lambda i,j: 2*i + j
    m = LazyArray(input, shape=(4,3))
    assert_arrays_equal(m.evaluate(),
                        numpy.array([[0, 1, 2],
                                     [2, 3, 4],
                                     [4, 5, 6],
                                     [6, 7, 8]]))
Ejemplo n.º 2
0
def test_multiple_operations_with_structured_array():
    input = numpy.arange(12).reshape((4,3))
    m0 = LazyArray(input, shape=(4,3))
    m1 = (m0 + 2) < 5
    m2 = (m0 < 5) + 2
    assert_arrays_equal(m1.evaluate(simplify=True), (input+2)<5)
    assert_arrays_equal(m2.evaluate(simplify=True), (input<5)+2)
    assert_arrays_equal(m0.evaluate(simplify=True), input)
Ejemplo n.º 3
0
def test_setitem_nonexpanded_different_value():
    A = LazyArray(3, shape=(5,))
    assert A.evaluate(simplify=True) == 3
    A[0] = 4; A[4] = 5
    assert_arrays_equal(A.evaluate(simplify=True), numpy.array([4, 3, 3, 3, 5]))
Ejemplo n.º 4
0
def test_setitem_nonexpanded_same_value():
    A = LazyArray(3, shape=(5,))
    assert A.evaluate(simplify=True) == 3
    A[0] = 3
    assert A.evaluate(simplify=True) == 3
Ejemplo n.º 5
0
def test_create_with_array():
    A = LazyArray(numpy.array([1,2,3]), shape=(3,))
    assert A.shape == (3,)
    assert_arrays_equal(A.evaluate(simplify=True), numpy.array([1,2,3]))
Ejemplo n.º 6
0
def test_create_with_float():
    A = LazyArray(3.0, shape=(5,))
    assert A.shape == (5,)
    assert A.evaluate(simplify=True) == 3.0
Ejemplo n.º 7
0
def test_lt_with_flat_array():
    m0 = LazyArray(5, shape=(4,3))
    m1 = m0 < 10
    assert_equal(m1.evaluate(simplify=True), True)
    assert_equal(m0.evaluate(simplify=True), 5)
Ejemplo n.º 8
0
def test_iadd_with_flat_array():
    m = LazyArray(5, shape=(4,3))
    m += 2
    assert_arrays_equal(m.evaluate(), 7*numpy.ones((4,3)))
    assert_equal(m.base_value, 5)
    assert_equal(m.evaluate(simplify=True), 7)
Ejemplo n.º 9
0
def test_evaluate_with_structured_array():
    input = numpy.arange(12).reshape((4,3))
    m = LazyArray(input, shape=(4,3))
    assert_arrays_equal(m.evaluate(), input)
Ejemplo n.º 10
0
def test_evaluate_with_flat_array():
    m = LazyArray(5, shape=(4,3))
    assert_arrays_equal(m.evaluate(), 5*numpy.ones((4,3)))
Ejemplo n.º 11
0
def test_evaluate_with_functional_array():
    input = lambda i, j: 2 * i + j
    m = LazyArray(input, shape=(4, 3))
    assert_arrays_equal(
        m.evaluate(), numpy.array([[0, 1, 2], [2, 3, 4], [4, 5, 6], [6, 7,
                                                                     8]]))
Ejemplo n.º 12
0
def test_evaluate_with_structured_array():
    input = numpy.arange(12).reshape((4, 3))
    m = LazyArray(input, shape=(4, 3))
    assert_arrays_equal(m.evaluate(), input)
Ejemplo n.º 13
0
def test_evaluate_with_flat_array():
    m = LazyArray(5, shape=(4, 3))
    assert_arrays_equal(m.evaluate(), 5 * numpy.ones((4, 3)))