Skip to content

Commit

Permalink
Minor.
Browse files Browse the repository at this point in the history
  • Loading branch information
hhoppe committed May 2, 2024
1 parent 484cf23 commit b01ca97
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions resampler_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4114,17 +4114,17 @@
" 'uint32': 1,\n",
" 'int32': 1,\n",
" }[dtype]\n",
" dtype = np.dtype(dtype)\n",
" np_dtype = np.dtype(dtype)\n",
" rng = np.random.default_rng(0)\n",
" array = (\n",
" rng.integers(256, size=shape, dtype=dtype)\n",
" if np.issubdtype(dtype, np.integer)\n",
" else rng.random(shape).astype(dtype)\n",
" rng.integers(256, size=shape, dtype=np_dtype)\n",
" if np.issubdtype(np_dtype, np.integer)\n",
" else rng.random(shape).astype(np_dtype)\n",
" )\n",
" yx = np.moveaxis(np.indices(new_shape), 0, -1)\n",
" coords = (yx + 0.5) / new_shape if gridtype == 'dual' else yx / (np.array(new_shape) - 1)\n",
" coords = (coords - translate) / scale\n",
" kwargs = dict(gridtype=gridtype, boundary=boundary, filter=filter, gamma=gamma)\n",
" kwargs: Any = dict(gridtype=gridtype, boundary=boundary, filter=filter, gamma=gamma)\n",
" resize_kwargs = dict(scale=scale, translate=translate, **kwargs)\n",
" resized = resampler.resize_in_numpy(array, new_shape, **resize_kwargs)\n",
" array2 = resampler._make_array(array, arraylib)\n",
Expand All @@ -4133,7 +4133,7 @@
" _check_eq(resampler._arr_arraylib(resized), 'numpy')\n",
" assert resampler._arr_arraylib(resized2) == resampler._arr_arraylib(resampled2) == arraylib\n",
" _arr_dtype = resampler._arr_dtype\n",
" assert resized.dtype == _arr_dtype(resized2) == _arr_dtype(resampled2) == dtype\n",
" assert resized.dtype == _arr_dtype(resized2) == _arr_dtype(resampled2) == np_dtype\n",
" assert np.allclose(resized2, resized, rtol=0, atol=atol), config\n",
" assert np.allclose(resampled2, resized, rtol=0, atol=atol), config\n",
"\n",
Expand Down
12 changes: 6 additions & 6 deletions resampler_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,17 +1296,17 @@ def test_that_all_resize_and_resample_agree(shape=(3, 2, 2), new_shape=(4, 2, 4)
'uint32': 1,
'int32': 1,
}[dtype]
dtype = np.dtype(dtype)
np_dtype = np.dtype(dtype)
rng = np.random.default_rng(0)
array = (
rng.integers(256, size=shape, dtype=dtype)
if np.issubdtype(dtype, np.integer)
else rng.random(shape).astype(dtype)
rng.integers(256, size=shape, dtype=np_dtype)
if np.issubdtype(np_dtype, np.integer)
else rng.random(shape).astype(np_dtype)
)
yx = np.moveaxis(np.indices(new_shape), 0, -1)
coords = (yx + 0.5) / new_shape if gridtype == 'dual' else yx / (np.array(new_shape) - 1)
coords = (coords - translate) / scale
kwargs = dict(gridtype=gridtype, boundary=boundary, filter=filter, gamma=gamma)
kwargs: Any = dict(gridtype=gridtype, boundary=boundary, filter=filter, gamma=gamma)
resize_kwargs = dict(scale=scale, translate=translate, **kwargs)
resized = resampler.resize_in_numpy(array, new_shape, **resize_kwargs)
array2 = resampler._make_array(array, arraylib)
Expand All @@ -1315,7 +1315,7 @@ def test_that_all_resize_and_resample_agree(shape=(3, 2, 2), new_shape=(4, 2, 4)
_check_eq(resampler._arr_arraylib(resized), 'numpy')
assert resampler._arr_arraylib(resized2) == resampler._arr_arraylib(resampled2) == arraylib
_arr_dtype = resampler._arr_dtype
assert resized.dtype == _arr_dtype(resized2) == _arr_dtype(resampled2) == dtype
assert resized.dtype == _arr_dtype(resized2) == _arr_dtype(resampled2) == np_dtype
assert np.allclose(resized2, resized, rtol=0, atol=atol), config
assert np.allclose(resampled2, resized, rtol=0, atol=atol), config

Expand Down
2 changes: 1 addition & 1 deletion test_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def test_resize_using_resample(self) -> None:
for config in itertools.islice(configs, 0, None, step):
gridtype, boundary, filter, gamma = config
with self.subTest(config=config):
kwargs = dict(gridtype=gridtype, boundary=boundary, filter=filter)
kwargs: Any = dict(gridtype=gridtype, boundary=boundary, filter=filter)
kwargs |= dict(gamma=gamma, scale=scale, translate=translate)
expected = resampler._original_resize(array, new_shape, **kwargs)
new_array = resampler._resize_using_resample(array, new_shape, **kwargs)
Expand Down

0 comments on commit b01ca97

Please sign in to comment.