meanas/meanas/test/utils.py

33 lines
819 B
Python
Raw Normal View History

2022-10-04 14:32:40 -07:00
import numpy
2023-05-22 10:53:13 -07:00
from numpy.typing import NDArray
2026-04-21 21:13:34 -07:00
from numpy.typing import ArrayLike
2020-10-17 17:48:58 -07:00
2026-04-18 00:52:04 -07:00
def make_prng(seed: int = 12345) -> numpy.random.RandomState:
return numpy.random.RandomState(seed)
2020-10-17 17:48:58 -07:00
2022-10-04 14:32:40 -07:00
def assert_fields_close(
x: NDArray,
y: NDArray,
2022-10-06 13:45:04 -07:00
*args,
**kwargs,
2024-07-29 00:30:00 -07:00
) -> None:
x_disp = numpy.moveaxis(x, -1, 0)
y_disp = numpy.moveaxis(y, -1, 0)
numpy.testing.assert_allclose(
x, # type: ignore
y, # type: ignore
*args,
verbose=False,
err_msg=f'Fields did not match:\n{x_disp}\n{y_disp}',
**kwargs,
2022-10-06 13:45:04 -07:00
)
2022-10-04 14:32:40 -07:00
def assert_close(
2026-04-21 21:13:34 -07:00
x: ArrayLike,
y: ArrayLike,
2024-07-29 00:30:00 -07:00
*args,
**kwargs,
2022-10-04 14:32:40 -07:00
) -> None:
2026-04-21 21:13:34 -07:00
numpy.testing.assert_allclose(numpy.asarray(x), numpy.asarray(y), *args, **kwargs)