[fdmath] fix dtype promotion, array-like unvectorization, and mirror bounds
This commit is contained in:
parent
282ed2c38b
commit
247e3b0f73
7 changed files with 104 additions and 20 deletions
|
|
@ -56,7 +56,8 @@ def test_shift_circ_rejects_invalid_arguments(args: tuple[int, tuple[int, ...],
|
|||
[
|
||||
((0, (2,), 1), 'Invalid shape'),
|
||||
((3, SHAPE, 1), 'Invalid direction'),
|
||||
((0, SHAPE, SHAPE[0]), 'too large'),
|
||||
((0, SHAPE, SHAPE[0] + 1), 'too large'),
|
||||
((0, SHAPE, -SHAPE[0] - 1), 'too large'),
|
||||
],
|
||||
)
|
||||
def test_shift_with_mirror_rejects_invalid_arguments(args: tuple[int, tuple[int, ...], int], message: str) -> None:
|
||||
|
|
@ -64,6 +65,23 @@ def test_shift_with_mirror_rejects_invalid_arguments(args: tuple[int, tuple[int,
|
|||
operators.shift_with_mirror(*args)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('axis', [0, 1, 2])
|
||||
@pytest.mark.parametrize('polarity', [-1, 1])
|
||||
def test_shift_with_mirror_by_full_axis_length_reverses_axis(axis, polarity) -> None:
|
||||
result = _apply_scalar_matrix(operators.shift_with_mirror(axis, SHAPE, polarity * SHAPE[axis]))
|
||||
assert_close(result, numpy.flip(SCALAR_FIELD, axis=axis))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('axis', [0, 1, 2])
|
||||
@pytest.mark.parametrize('shift_distance', [-1, 0, 1])
|
||||
def test_shift_with_mirror_on_singleton_axis_is_identity(axis, shift_distance) -> None:
|
||||
shape = list(SHAPE)
|
||||
shape[axis] = 1
|
||||
field = numpy.arange(numpy.prod(shape)).reshape(shape)
|
||||
result = (operators.shift_with_mirror(axis, shape, shift_distance) @ field.ravel()).reshape(shape)
|
||||
assert_close(result, field)
|
||||
|
||||
|
||||
def test_vec_cross_matches_pointwise_cross_product() -> None:
|
||||
matrix_result = unvec(operators.vec_cross(vec(VECTOR_LEFT)) @ vec(VECTOR_RIGHT), SHAPE)
|
||||
expected = numpy.empty_like(VECTOR_LEFT)
|
||||
|
|
|
|||
Loading…
Reference in a new issue