Ejemplo n.º 1
0
def test_separation_binary(
    backend, u, v, u_diff_ndim, v_diff_ndim, func, diff_u, diff_v
):
    try:
        with ua.set_backend(backend), ua.set_backend(udiff, coerce=True):
            u = np.asarray(u)
            u.var = udiff.Variable("u", diff_ndim=u_diff_ndim)
            v = np.asarray(v)
            v.var = udiff.Variable("v", diff_ndim=v_diff_ndim)

            ret = func(u, v)
    except ua.BackendNotImplementedError:
        if backend in FULLY_TESTED_BACKENDS:
            raise
        pytest.xfail(reason="The backend has no implementation for this ufunc.")

    if isinstance(ret, da.Array):
        ret.compute()

    assert_allclose(ret.diffs[u].arr, diff_u.tolist())
    assert_allclose(ret.diffs[v].arr, diff_v.tolist())
Ejemplo n.º 2
0
def test_arbitrary_function(backend, func, y_d):
    x_arr = [0.2, 0.3]
    try:
        with ua.set_backend(backend), ua.set_backend(udiff, coerce=True):
            x = np.asarray(x_arr)
            x.var = udiff.Variable('x')
            ret = func(x)
            y_d_arr = y_d(x)
    except ua.BackendNotImplementedError:
        if backend in FULLY_TESTED_BACKENDS:
            raise
        pytest.xfail(reason="The backend has no implementation for this ufunc.")

    if isinstance(ret, da.Array):
        ret.compute()

    assert_allclose(ret.diffs[x].arr, y_d_arr.arr)
Ejemplo n.º 3
0
def test_arbitrary_function(backend, func, y_d, domain):
    if domain is None:
        x_arr = generate_test_data()
    else:
        x_arr = generate_test_data(a=domain[0], b=domain[1])
    try:
        with ua.set_backend(backend), ua.set_backend(udiff, coerce=True):
            x = np.asarray(x_arr)
            x.var = udiff.Variable("x")
            ret = func(x)
            y_d_arr = y_d(x)
    except ua.BackendNotImplementedError:
        if backend in FULLY_TESTED_BACKENDS:
            raise
        pytest.xfail(reason="The backend has no implementation for this ufunc.")

    if isinstance(ret, da.Array):
        ret.compute()

    assert_allclose(ret.diffs[x].arr, y_d_arr.arr)