Skip to content

Remove reimplementation of np.testing.assert_allclose #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/extending/creating_an_op.rst
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,9 @@ exception. You can use the ``assert`` keyword to automatically raise an
inp = np.asarray(rng.random((5, 4)), dtype=pytensor.config.floatX)
out = f(inp)
# Compare the result computed to the expected value.
utt.assert_allclose(inp * 2, out)
np.testing.assert_allclose(inp * 2, out)

We call ``utt.assert_allclose(expected_value, value)`` to compare
We call ``np.testing.assert_allclose(expected_value, value)`` to compare
NumPy ndarray.This raise an error message with more information. Also,
the default tolerance can be changed with the PyTensor flags
``config.tensor__cmp_sloppy`` that take values in 0, 1 and 2. The
Expand Down
5 changes: 2 additions & 3 deletions tests/link/c/test_params_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pytensor.link.c.type import EnumList, Generic
from pytensor.scalar import ScalarType
from pytensor.tensor.type import TensorType, matrix
from tests import unittest_tools as utt


tensor_type_0d = TensorType("float64", shape=tuple())
Expand Down Expand Up @@ -355,5 +354,5 @@ def test_op_params(self):
vy1 = f1(vx)
vy2 = f2(vx)
ref = a * (vx**2) + b * vx + c
utt.assert_allclose(vy1, vy2)
utt.assert_allclose(ref, vy1)
np.testing.assert_allclose(vy1, vy2)
np.testing.assert_allclose(ref, vy1)
3 changes: 1 addition & 2 deletions tests/link/test_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from pytensor.tensor.math import cosh, tanh
from pytensor.tensor.type import lscalar, scalar, scalars, vector, vectors
from pytensor.tensor.variable import TensorConstant
from tests import unittest_tools as utt


class SomeOp(Op):
Expand Down Expand Up @@ -221,7 +220,7 @@ def test_partial_function(linker):
assert f(3, output_subset=[0, 1, 2]) == f(3)
assert f(4, output_subset=[0, 2]) == [f(4)[0], f(4)[2]]

utt.assert_allclose(f(5), np.array([32.0, 16.0, 1.7857142857142858]))
np.testing.assert_allclose(f(5), np.array([32.0, 16.0, 1.7857142857142858]))


@pytest.mark.parametrize(
Expand Down
11 changes: 5 additions & 6 deletions tests/scalar/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytensor
import pytensor.tensor as pt
import tests.unittest_tools as utt
from pytensor.compile.mode import Mode
from pytensor.graph.fg import FunctionGraph
from pytensor.link.c.basic import DualLinker
Expand Down Expand Up @@ -477,11 +476,11 @@ def test_grad_inrange():
# x is equal to the lower or higher bound but in that case
# PyTensor defines the gradient to be zero for stability.
f = pytensor.function([x, low, high], [gx, glow, ghigh])
utt.assert_allclose(f(0, 1, 5), [0, 0, 0])
utt.assert_allclose(f(1, 1, 5), [0, 0, 0])
utt.assert_allclose(f(2, 1, 5), [0, 0, 0])
utt.assert_allclose(f(5, 1, 5), [0, 0, 0])
utt.assert_allclose(f(7, 1, 5), [0, 0, 0])
np.testing.assert_allclose(f(0, 1, 5), [0, 0, 0])
np.testing.assert_allclose(f(1, 1, 5), [0, 0, 0])
np.testing.assert_allclose(f(2, 1, 5), [0, 0, 0])
np.testing.assert_allclose(f(5, 1, 5), [0, 0, 0])
np.testing.assert_allclose(f(7, 1, 5), [0, 0, 0])


def test_grad_abs():
Expand Down
Loading