def test_evaluate_with_functional_array(): input = lambda i,j: 2*i + j m = LazyArray(input, shape=(4,3)) assert_array_equal(m.evaluate(), np.array([[0, 1, 2], [2, 3, 4], [4, 5, 6], [6, 7, 8]]))
def test_multiple_operations_with_structured_array(): input = np.arange(12).reshape((4, 3)) m0 = LazyArray(input, shape=(4, 3)) m1 = (m0 + 2) < 5 m2 = (m0 < 5) + 2 assert_array_equal(m1.evaluate(simplify=True), (input + 2) < 5) assert_array_equal(m2.evaluate(simplify=True), (input < 5) + 2) assert_array_equal(m0.evaluate(simplify=True), input)
def test_setitem_nonexpanded_different_value(): A = LazyArray(3, shape=(5,)) assert A.evaluate(simplify=True) == 3 A[0] = 4 A[4] = 5 assert_array_equal(A.evaluate(simplify=True), np.array([4, 3, 3, 3, 5]))
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
def test_create_with_array(): A = LazyArray(np.array([1, 2, 3]), shape=(3,)) assert A.shape == (3,) assert_array_equal(A.evaluate(simplify=True), np.array([1, 2, 3]))
def test_create_with_float(): A = LazyArray(3.0, shape=(5,)) assert A.shape == (5,) assert A.evaluate(simplify=True) == 3.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)
def test_iadd_with_flat_array(): m = LazyArray(5, shape=(4, 3)) m += 2 assert_array_equal(m.evaluate(), 7 * np.ones((4, 3))) assert_equal(m.base_value, 5) assert_equal(m.evaluate(simplify=True), 7)
def test_evaluate_with_structured_array(): input = np.arange(12).reshape((4, 3)) m = LazyArray(input, shape=(4, 3)) assert_array_equal(m.evaluate(), input)
def test_evaluate_with_flat_array(): m = LazyArray(5, shape=(4, 3)) assert_array_equal(m.evaluate(), 5 * np.ones((4, 3)))