Skip to content

Commit

Permalink
[test] Remove approx at top level.
Browse files Browse the repository at this point in the history
Related: taichi-dev#3782

`approx` is an internal testing utility.

ghstack-source-id: f1e3c5f29e5d97ee256c9722e57573408fb03429
Pull Request resolved: taichi-dev#4113
  • Loading branch information
Ailing Zhang committed Jan 25, 2022
1 parent 033a118 commit e9e4cd6
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion misc/test_poly_timed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from autograd import grad
from taichi._testing import approx

import taichi as ti
from taichi import approx


# Note: test happens at v = 0.2
Expand Down
1 change: 0 additions & 1 deletion python/taichi/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def wrapped(*args, **kwargs):


__all__ = [
'approx',
'allclose',
'test',
]
3 changes: 2 additions & 1 deletion tests/python/test_ad_atomic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from taichi._testing import approx

import taichi as ti
from taichi import approx


@ti.test()
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_ad_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import numpy as np
import pytest
from taichi._testing import approx

import taichi as ti
from taichi import approx

has_autograd = False

Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_ast_refactor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import pytest
from taichi._testing import approx

import taichi as ti
from taichi import approx


@ti.test()
Expand Down
3 changes: 2 additions & 1 deletion tests/python/test_atomic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from taichi._testing import approx

import taichi as ti
from taichi import approx

n = 128

Expand Down
4 changes: 2 additions & 2 deletions tests/python/test_expr_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def func(u: int, v: float) -> float:
x = {'foo': 2 + u, 'bar': 3 + v}
return x['foo'] * 100 + x['bar']

assert func(2, 0.1) == ti.approx(403.1)
assert func(2, 0.1) == ti._testing.approx(403.1)


@ti.test(ti.cpu)
Expand All @@ -22,7 +22,7 @@ def func() -> float:

a[0] = 2
a[1] = 0.1
assert func() == ti.approx(403.1)
assert func() == ti._testing.approx(403.1)


@ti.test(ti.cpu)
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_expr_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def func(u: int, v: float) -> float:
x = [2 + u, 3 + v]
return x[0] * 100 + x[1]

assert func(1, 1.1) == ti.approx(304.1)
assert func(1, 1.1) == ti._testing.approx(304.1)


@ti.test()
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_f16.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import numpy as np
import pytest
from taichi._testing import approx

import taichi as ti
from taichi import approx

archs_support_f16 = [ti.cpu, ti.cuda, ti.vulkan]

Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_image_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ def test_image_resize_sum(resx, resy, comp, scale):
new_img = ti.imresize(old_img, resx * scale)
else:
new_img = ti.imresize(old_img, resx * scale, resy * scale)
assert np.sum(old_img) * scale**2 == ti.approx(np.sum(new_img))
assert np.sum(old_img) * scale**2 == ti._testing.approx(np.sum(new_img))
2 changes: 1 addition & 1 deletion tests/python/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import numpy as np
import pytest
from taichi._testing import approx

import taichi as ti
from taichi import approx


@ti.test()
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import numpy as np
import pytest
from taichi._testing import approx

import taichi as ti
from taichi import approx

operation_types = [operator.add, operator.sub, operator.matmul]
test_matrix_arrays = [
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_mpm88.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os

import pytest
from taichi._testing import approx

import taichi as ti
from taichi import approx


def run_mpm88_test():
Expand Down
3 changes: 2 additions & 1 deletion tests/python/test_random.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from taichi._testing import approx

import taichi as ti
from taichi import approx


@ti.test()
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_return.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from taichi._testing import approx

import taichi as ti
from taichi import approx


@ti.test()
Expand Down
4 changes: 2 additions & 2 deletions tests/python/test_sfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def scatter():

x_grad = x.grad.to_numpy()
for i in range(n):
assert ti.approx(x_grad[i]) == 2.0 * i
assert ti._testing.approx(x_grad[i]) == 2.0 * i


@ti.test(require=ti.extension.async_mode, async_mode=True)
Expand All @@ -121,4 +121,4 @@ def compute_mean_of_boundary_edges() -> ti.i32:

x.from_numpy(np.arange(0, n, dtype=np.float32))
mean = compute_mean_of_boundary_edges()
assert ti.approx(mean) == 33
assert ti._testing.approx(mean) == 33
2 changes: 1 addition & 1 deletion tests/python/test_sparse_linear_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def fill(Abuilder: ti.linalg.sparse_matrix_builder(),
solver.factorize(A)
x = solver.solve(b)
for i in range(n):
assert x[i] == ti.approx(res[i])
assert x[i] == ti._testing.approx(res[i])
2 changes: 1 addition & 1 deletion tests/python/test_ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import math

import numpy as np
from taichi._testing import approx

import taichi as ti
from taichi import approx


@ti.test()
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_svd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from taichi._testing import approx

import taichi as ti
from taichi import approx


@ti.test(require=ti.extension.data64, fast_math=False)
Expand Down
14 changes: 7 additions & 7 deletions tests/python/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def test_require_extensions_2():
assert ti.cfg.arch in [ti.cuda]


### `ti.approx` and `ti.allclose`
### `ti._testing.approx` and `ti.allclose`


@pytest.mark.parametrize('x', [0.1, 3])
@pytest.mark.parametrize('allclose',
[ti.allclose, lambda x, y: x == ti.approx(y)])
@pytest.mark.parametrize(
'allclose', [ti.allclose, lambda x, y: x == ti._testing.approx(y)])
@ti.test()
def test_allclose_rel(x, allclose):
rel = ti._testing.get_rel_eps()
Expand All @@ -90,8 +90,8 @@ def test_allclose_rel(x, allclose):


@pytest.mark.parametrize('x', [0.1, 3])
@pytest.mark.parametrize('allclose',
[ti.allclose, lambda x, y: x == ti.approx(y)])
@pytest.mark.parametrize(
'allclose', [ti.allclose, lambda x, y: x == ti._testing.approx(y)])
@ti.test()
def test_allclose_rel_reordered1(x, allclose):
rel = ti._testing.get_rel_eps()
Expand All @@ -107,8 +107,8 @@ def test_allclose_rel_reordered1(x, allclose):


@pytest.mark.parametrize('x', [0.1, 3])
@pytest.mark.parametrize('allclose',
[ti.allclose, lambda x, y: x == ti.approx(y)])
@pytest.mark.parametrize(
'allclose', [ti.allclose, lambda x, y: x == ti._testing.approx(y)])
@ti.test()
def test_allclose_rel_reordered2(x, allclose):
rel = ti._testing.get_rel_eps()
Expand Down

0 comments on commit e9e4cd6

Please sign in to comment.