|
37 | 37 | PytatoPyOpenCLArrayContext, |
38 | 38 | EagerJAXArrayContext, |
39 | 39 | ArrayContainer, |
40 | | - to_numpy, tag_axes) |
| 40 | + tag_axes) |
41 | 41 | from arraycontext import ( # noqa: F401 |
42 | 42 | pytest_generate_tests_for_array_contexts, |
43 | 43 | ) |
@@ -1145,23 +1145,22 @@ def test_numpy_conversion(actx_factory): |
1145 | 1145 | enthalpy=np.array(np.random.rand()), |
1146 | 1146 | ) |
1147 | 1147 |
|
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) |
1151 | 1150 |
|
1152 | 1151 | assert np.allclose(ac.mass, ac_roundtrip.mass) |
1153 | 1152 | assert np.allclose(ac.momentum[0], ac_roundtrip.momentum[0]) |
1154 | 1153 |
|
1155 | 1154 | from dataclasses import replace |
1156 | 1155 | ac_with_cl = replace(ac, enthalpy=ac_actx.mass) |
1157 | 1156 | with pytest.raises(TypeError): |
1158 | | - from_numpy(ac_with_cl, actx) |
| 1157 | + actx.from_numpy(ac_with_cl) |
1159 | 1158 |
|
1160 | 1159 | with pytest.raises(TypeError): |
1161 | | - from_numpy(ac_actx, actx) |
| 1160 | + actx.from_numpy(ac_actx) |
1162 | 1161 |
|
1163 | 1162 | with pytest.raises(TypeError): |
1164 | | - to_numpy(ac, actx) |
| 1163 | + actx.to_numpy(ac) |
1165 | 1164 |
|
1166 | 1165 | # }}} |
1167 | 1166 |
|
@@ -1226,55 +1225,52 @@ def scale_and_orthogonalize(alpha, vel): |
1226 | 1225 |
|
1227 | 1226 |
|
1228 | 1227 | def test_actx_compile(actx_factory): |
1229 | | - from arraycontext import (to_numpy, from_numpy) |
1230 | 1228 | actx = actx_factory() |
1231 | 1229 |
|
1232 | 1230 | compiled_rhs = actx.compile(scale_and_orthogonalize) |
1233 | 1231 |
|
1234 | 1232 | v_x = np.random.rand(10) |
1235 | 1233 | v_y = np.random.rand(10) |
1236 | 1234 |
|
1237 | | - vel = from_numpy(Velocity2D(v_x, v_y, actx), actx) |
| 1235 | + vel = actx.from_numpy(Velocity2D(v_x, v_y, actx)) |
1238 | 1236 |
|
1239 | 1237 | scaled_speed = compiled_rhs(np.float64(3.14), vel) |
1240 | 1238 |
|
1241 | | - result = to_numpy(scaled_speed, actx) |
| 1239 | + result = actx.to_numpy(scaled_speed) |
1242 | 1240 | np.testing.assert_allclose(result.u, -3.14*v_y) |
1243 | 1241 | np.testing.assert_allclose(result.v, 3.14*v_x) |
1244 | 1242 |
|
1245 | 1243 |
|
1246 | 1244 | def test_actx_compile_python_scalar(actx_factory): |
1247 | | - from arraycontext import (to_numpy, from_numpy) |
1248 | 1245 | actx = actx_factory() |
1249 | 1246 |
|
1250 | 1247 | compiled_rhs = actx.compile(scale_and_orthogonalize) |
1251 | 1248 |
|
1252 | 1249 | v_x = np.random.rand(10) |
1253 | 1250 | v_y = np.random.rand(10) |
1254 | 1251 |
|
1255 | | - vel = from_numpy(Velocity2D(v_x, v_y, actx), actx) |
| 1252 | + vel = actx.from_numpy(Velocity2D(v_x, v_y, actx)) |
1256 | 1253 |
|
1257 | 1254 | scaled_speed = compiled_rhs(3.14, vel) |
1258 | 1255 |
|
1259 | | - result = to_numpy(scaled_speed, actx) |
| 1256 | + result = actx.to_numpy(scaled_speed) |
1260 | 1257 | np.testing.assert_allclose(result.u, -3.14*v_y) |
1261 | 1258 | np.testing.assert_allclose(result.v, 3.14*v_x) |
1262 | 1259 |
|
1263 | 1260 |
|
1264 | 1261 | def test_actx_compile_kwargs(actx_factory): |
1265 | | - from arraycontext import (to_numpy, from_numpy) |
1266 | 1262 | actx = actx_factory() |
1267 | 1263 |
|
1268 | 1264 | compiled_rhs = actx.compile(scale_and_orthogonalize) |
1269 | 1265 |
|
1270 | 1266 | v_x = np.random.rand(10) |
1271 | 1267 | v_y = np.random.rand(10) |
1272 | 1268 |
|
1273 | | - vel = from_numpy(Velocity2D(v_x, v_y, actx), actx) |
| 1269 | + vel = actx.from_numpy(Velocity2D(v_x, v_y, actx)) |
1274 | 1270 |
|
1275 | 1271 | scaled_speed = compiled_rhs(3.14, vel=vel) |
1276 | 1272 |
|
1277 | | - result = to_numpy(scaled_speed, actx) |
| 1273 | + result = actx.to_numpy(scaled_speed) |
1278 | 1274 | np.testing.assert_allclose(result.u, -3.14*v_y) |
1279 | 1275 | np.testing.assert_allclose(result.v, 3.14*v_x) |
1280 | 1276 |
|
@@ -1550,7 +1546,7 @@ def test_to_numpy_on_frozen_arrays(actx_factory): |
1550 | 1546 | actx = actx_factory() |
1551 | 1547 | u = actx.freeze(actx.zeros(10, dtype="float64")+1) |
1552 | 1548 | 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) |
1554 | 1550 |
|
1555 | 1551 |
|
1556 | 1552 | def test_tagging(actx_factory): |
|
0 commit comments