Skip to content

Commit 4a86044

Browse files
committed
Bug where array that is being computed is optimized away
1 parent 5cee462 commit 4a86044

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

cubed/tests/test_optimization.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,34 @@ def test_fusion(spec, opt_fn):
6060
)
6161

6262

63+
@pytest.mark.parametrize(
64+
"opt_fn", [None, simple_optimize_dag, multiple_inputs_optimize_dag]
65+
)
66+
def test_fusion_compute_multiple(spec, opt_fn):
67+
a = xp.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9]], chunks=(2, 2), spec=spec)
68+
b = xp.negative(a)
69+
c = xp.astype(b, np.float32)
70+
d = xp.negative(c)
71+
72+
# if we compute c and d then both have to be materialized
73+
num_created_arrays = 2 # c, d
74+
task_counter = TaskCounter()
75+
cubed.visualize(c, d, optimize_function=opt_fn)
76+
c_result, d_result = cubed.compute(
77+
c, d, optimize_function=opt_fn, callbacks=[task_counter]
78+
)
79+
assert task_counter.value == num_created_arrays + 8
80+
81+
assert_array_equal(
82+
c_result,
83+
np.array([[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]).astype(np.float32),
84+
)
85+
assert_array_equal(
86+
d_result,
87+
np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype(np.float32),
88+
)
89+
90+
6391
@pytest.mark.parametrize(
6492
"opt_fn", [None, simple_optimize_dag, multiple_inputs_optimize_dag]
6593
)

0 commit comments

Comments
 (0)