Skip to content

Commit ba18c65

Browse files
Deprecate redefinition of np.testing.assert_allclose
1 parent b7b309d commit ba18c65

29 files changed

+410
-371
lines changed

doc/extending/creating_an_op.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ exception. You can use the ``assert`` keyword to automatically raise an
551551

552552
import numpy as np
553553
import pytensor
554-
from tests import unittest_tools as utt
555554

556555

557556
class TestDouble(utt.InferShapeTester):
@@ -569,9 +568,9 @@ exception. You can use the ``assert`` keyword to automatically raise an
569568
inp = np.asarray(rng.random((5, 4)), dtype=pytensor.config.floatX)
570569
out = f(inp)
571570
# Compare the result computed to the expected value.
572-
utt.assert_allclose(inp * 2, out)
571+
np.testing.assert_allclose(inp * 2, out)
573572

574-
We call ``utt.assert_allclose(expected_value, value)`` to compare
573+
We call ``np.testing.assert_allclose(expected_value, value)`` to compare
575574
NumPy ndarray.This raise an error message with more information. Also,
576575
the default tolerance can be changed with the PyTensor flags
577576
``config.tensor__cmp_sloppy`` that take values in 0, 1 and 2. The

tests/graph/test_replace.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
vectorize_node,
1313
)
1414
from pytensor.tensor import dvector, fvector, vector
15-
from tests import unittest_tools as utt
1615
from tests.graph.utils import MyOp, MyVariable, op_multiple_outputs
1716

1817

@@ -133,10 +132,10 @@ def test(x, y, mention_y):
133132
return function([], out)()
134133

135134
x = shared(np.asarray(0.0, dtype=config.floatX))
136-
utt.assert_allclose(
135+
np.testing.assert_allclose(
137136
test(x, pt.sum((x + 1) ** 2), mention_y=False), 1.21000003815
138137
)
139-
utt.assert_allclose(
138+
np.testing.assert_allclose(
140139
test(x, pt.sum((x + 1) ** 2), mention_y=True), 1.21000003815
141140
)
142141

tests/link/c/test_params_type.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from pytensor.link.c.type import EnumList, Generic
1010
from pytensor.scalar import ScalarType
1111
from pytensor.tensor.type import TensorType, matrix
12-
from tests import unittest_tools as utt
1312

1413

1514
tensor_type_0d = TensorType("float64", shape=tuple())
@@ -354,5 +353,5 @@ def test_op_params(self):
354353
vy1 = f1(vx)
355354
vy2 = f2(vx)
356355
ref = a * (vx**2) + b * vx + c
357-
utt.assert_allclose(vy1, vy2)
358-
utt.assert_allclose(ref, vy1)
356+
np.testing.assert_allclose(vy1, vy2)
357+
np.testing.assert_allclose(ref, vy1)

tests/link/test_vm.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from pytensor.tensor.math import cosh, tanh
2020
from pytensor.tensor.type import lscalar, scalar, scalars, vector, vectors
2121
from pytensor.tensor.variable import TensorConstant
22-
from tests import unittest_tools as utt
2322

2423

2524
class SomeOp(Op):
@@ -221,7 +220,7 @@ def test_partial_function(linker):
221220
assert f(3, output_subset=[0, 1, 2]) == f(3)
222221
assert f(4, output_subset=[0, 2]) == [f(4)[0], f(4)[2]]
223222

224-
utt.assert_allclose(f(5), np.array([32.0, 16.0, 1.7857142857142858]))
223+
np.testing.assert_allclose(f(5), np.array([32.0, 16.0, 1.7857142857142858]))
225224

226225

227226
@pytest.mark.parametrize(

tests/scalar/test_basic.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import pytensor
55
import pytensor.tensor as pt
6-
import tests.unittest_tools as utt
76
from pytensor.compile.mode import Mode
87
from pytensor.graph.fg import FunctionGraph
98
from pytensor.link.c.basic import DualLinker
@@ -477,11 +476,11 @@ def test_grad_inrange():
477476
# x is equal to the lower or higher bound but in that case
478477
# PyTensor defines the gradient to be zero for stability.
479478
f = pytensor.function([x, low, high], [gx, glow, ghigh])
480-
utt.assert_allclose(f(0, 1, 5), [0, 0, 0])
481-
utt.assert_allclose(f(1, 1, 5), [0, 0, 0])
482-
utt.assert_allclose(f(2, 1, 5), [0, 0, 0])
483-
utt.assert_allclose(f(5, 1, 5), [0, 0, 0])
484-
utt.assert_allclose(f(7, 1, 5), [0, 0, 0])
479+
np.testing.assert_allclose(f(0, 1, 5), [0, 0, 0])
480+
np.testing.assert_allclose(f(1, 1, 5), [0, 0, 0])
481+
np.testing.assert_allclose(f(2, 1, 5), [0, 0, 0])
482+
np.testing.assert_allclose(f(5, 1, 5), [0, 0, 0])
483+
np.testing.assert_allclose(f(7, 1, 5), [0, 0, 0])
485484

486485

487486
def test_grad_abs():

0 commit comments

Comments
 (0)