def test_to_task_dasks(): a = value(1, 'a') b = value(2, 'b') task, dasks = to_task_dasks([a, b, 3]) assert task == (list, ['a', 'b', 3]) assert len(dasks) == 2 assert a.dask in dasks assert b.dask in dasks task, dasks = to_task_dasks({a: 1, b: 2}) assert (task == (dict, (list, [(list, ['b', 2]), (list, ['a', 1])])) or task == (dict, (list, [(list, ['a', 1]), (list, ['b', 2])]))) assert len(dasks) == 2 assert a.dask in dasks assert b.dask in dasks
def test_unquote(): from dask.diagnostics.profile_visualize import unquote from dask.imperative import to_task_dasks f = lambda x: to_task_dasks(x)[0] t = {'a': 1, 'b': 2, 'c': 3} assert unquote(f(t)) == t t = {'a': [1, 2, 3], 'b': 2, 'c': 3} assert unquote(f(t)) == t t = [1, 2, 3] assert unquote(f(t)) == t
def test_unquote(): from dask.diagnostics.profile_visualize import unquote from dask.imperative import to_task_dasks f = lambda x: to_task_dasks(x)[0] t = {"a": 1, "b": 2, "c": 3} assert unquote(f(t)) == t t = {"a": [1, 2, 3], "b": 2, "c": 3} assert unquote(f(t)) == t t = [1, 2, 3] assert unquote(f(t)) == t
def test_to_task_dasks(): a = value(1, 'a') b = value(2, 'b') task, dasks = to_task_dasks([a, b, 3]) assert task == ['a', 'b', 3] assert len(dasks) == 2 assert a.dask in dasks assert b.dask in dasks task, dasks = to_task_dasks({a: 1, b: 2}) assert (task == (dict, [['b', 2], ['a', 1]]) or task == (dict, [['a', 1], ['b', 2]])) assert len(dasks) == 2 assert a.dask in dasks assert b.dask in dasks f = namedtuple('f', ['x', 'y']) x = f(1, 2) task, dasks = to_task_dasks(x) assert task == x assert dasks == []
def test_to_task_dasks(): a = value(1, "a") b = value(2, "b") task, dasks = to_task_dasks([a, b, 3]) assert task == (list, ["a", "b", 3]) assert len(dasks) == 2 assert a.dask in dasks assert b.dask in dasks task, dasks = to_task_dasks({a: 1, b: 2}) assert task == (dict, (list, [(list, ["b", 2]), (list, ["a", 1])])) or task == ( dict, (list, [(list, ["a", 1]), (list, ["b", 2])]), ) assert len(dasks) == 2 assert a.dask in dasks assert b.dask in dasks f = namedtuple("f", ["x", "y"]) x = f(1, 2) task, dasks = to_task_dasks(x) assert task == x assert dasks == []
def test_array_imperative(): arr = np.arange(100).reshape((10, 10)) darr = da.from_array(arr, chunks=(5, 5)) val = do(sum)([arr, darr, 1]) assert isinstance(val, Value) assert np.allclose(val.compute(), arr + arr + 1) assert val.sum().compute() == (arr + arr + 1).sum() assert val[0, 0].compute() == (arr + arr + 1)[0, 0] task, dasks = to_task_dasks(darr) assert len(dasks) == 1 orig = set(darr.dask) final = set(dasks[0]) assert orig.issubset(final) diff = final.difference(orig) assert len(diff) == 1