Skip to content

Commit 2804814

Browse files
alexfiklinducer
authored andcommitted
remove deprecated usage from tests
1 parent 958d281 commit 2804814

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

test/test_arraycontext.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
PytatoPyOpenCLArrayContext,
3838
EagerJAXArrayContext,
3939
ArrayContainer,
40-
to_numpy, tag_axes)
40+
tag_axes)
4141
from arraycontext import ( # noqa: F401
4242
pytest_generate_tests_for_array_contexts,
4343
)
@@ -1145,23 +1145,22 @@ def test_numpy_conversion(actx_factory):
11451145
enthalpy=np.array(np.random.rand()),
11461146
)
11471147

1148-
from arraycontext import from_numpy, to_numpy
1149-
ac_actx = from_numpy(ac, actx)
1150-
ac_roundtrip = to_numpy(ac_actx, actx)
1148+
ac_actx = actx.from_numpy(ac)
1149+
ac_roundtrip = actx.to_numpy(ac_actx)
11511150

11521151
assert np.allclose(ac.mass, ac_roundtrip.mass)
11531152
assert np.allclose(ac.momentum[0], ac_roundtrip.momentum[0])
11541153

11551154
from dataclasses import replace
11561155
ac_with_cl = replace(ac, enthalpy=ac_actx.mass)
11571156
with pytest.raises(TypeError):
1158-
from_numpy(ac_with_cl, actx)
1157+
actx.from_numpy(ac_with_cl)
11591158

11601159
with pytest.raises(TypeError):
1161-
from_numpy(ac_actx, actx)
1160+
actx.from_numpy(ac_actx)
11621161

11631162
with pytest.raises(TypeError):
1164-
to_numpy(ac, actx)
1163+
actx.to_numpy(ac)
11651164

11661165
# }}}
11671166

@@ -1226,55 +1225,52 @@ def scale_and_orthogonalize(alpha, vel):
12261225

12271226

12281227
def test_actx_compile(actx_factory):
1229-
from arraycontext import (to_numpy, from_numpy)
12301228
actx = actx_factory()
12311229

12321230
compiled_rhs = actx.compile(scale_and_orthogonalize)
12331231

12341232
v_x = np.random.rand(10)
12351233
v_y = np.random.rand(10)
12361234

1237-
vel = from_numpy(Velocity2D(v_x, v_y, actx), actx)
1235+
vel = actx.from_numpy(Velocity2D(v_x, v_y, actx))
12381236

12391237
scaled_speed = compiled_rhs(np.float64(3.14), vel)
12401238

1241-
result = to_numpy(scaled_speed, actx)
1239+
result = actx.to_numpy(scaled_speed)
12421240
np.testing.assert_allclose(result.u, -3.14*v_y)
12431241
np.testing.assert_allclose(result.v, 3.14*v_x)
12441242

12451243

12461244
def test_actx_compile_python_scalar(actx_factory):
1247-
from arraycontext import (to_numpy, from_numpy)
12481245
actx = actx_factory()
12491246

12501247
compiled_rhs = actx.compile(scale_and_orthogonalize)
12511248

12521249
v_x = np.random.rand(10)
12531250
v_y = np.random.rand(10)
12541251

1255-
vel = from_numpy(Velocity2D(v_x, v_y, actx), actx)
1252+
vel = actx.from_numpy(Velocity2D(v_x, v_y, actx))
12561253

12571254
scaled_speed = compiled_rhs(3.14, vel)
12581255

1259-
result = to_numpy(scaled_speed, actx)
1256+
result = actx.to_numpy(scaled_speed)
12601257
np.testing.assert_allclose(result.u, -3.14*v_y)
12611258
np.testing.assert_allclose(result.v, 3.14*v_x)
12621259

12631260

12641261
def test_actx_compile_kwargs(actx_factory):
1265-
from arraycontext import (to_numpy, from_numpy)
12661262
actx = actx_factory()
12671263

12681264
compiled_rhs = actx.compile(scale_and_orthogonalize)
12691265

12701266
v_x = np.random.rand(10)
12711267
v_y = np.random.rand(10)
12721268

1273-
vel = from_numpy(Velocity2D(v_x, v_y, actx), actx)
1269+
vel = actx.from_numpy(Velocity2D(v_x, v_y, actx))
12741270

12751271
scaled_speed = compiled_rhs(3.14, vel=vel)
12761272

1277-
result = to_numpy(scaled_speed, actx)
1273+
result = actx.to_numpy(scaled_speed)
12781274
np.testing.assert_allclose(result.u, -3.14*v_y)
12791275
np.testing.assert_allclose(result.v, 3.14*v_x)
12801276

@@ -1550,7 +1546,7 @@ def test_to_numpy_on_frozen_arrays(actx_factory):
15501546
actx = actx_factory()
15511547
u = actx.freeze(actx.zeros(10, dtype="float64")+1)
15521548
np.testing.assert_allclose(actx.to_numpy(u), 1)
1553-
np.testing.assert_allclose(to_numpy(u, actx), 1)
1549+
np.testing.assert_allclose(actx.to_numpy(u), 1)
15541550

15551551

15561552
def test_tagging(actx_factory):

0 commit comments

Comments
 (0)