From fe7cb00a644a144a2f0f5a9ca15c447e0f41611c Mon Sep 17 00:00:00 2001 From: Marten van Kerkwijk Date: Thu, 19 Oct 2023 13:45:27 -0400 Subject: [PATCH] Fix recognition of non-contigous input data --- erfa/tests/test_erfa.py | 14 +++++++++++++- erfa/ufunc.c.templ | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/erfa/tests/test_erfa.py b/erfa/tests/test_erfa.py index e582a34..7e4d9b3 100644 --- a/erfa/tests/test_erfa.py +++ b/erfa/tests/test_erfa.py @@ -360,7 +360,19 @@ def test_float32_input(): xyz = np.array([[1, 0, 0], [0.9, 0.1, 0]]) out64 = erfa.p2s(xyz) out32 = erfa.p2s(xyz.astype('f4')) - np.testing.assert_allclose(out32, out64, rtol=1.e-5) + assert_allclose(out32, out64, rtol=1.e-5) + + +def test_non_contiguous_matrix(): + # Regression test for gh-123 (astropy gh-15503) + matrix = np.array([[1, 0, 0, 5], + [0, 1, 0, 6], + [0, 0, 1, 7]], dtype='float')[:, :3] + vector = np.array([1., 2., 3.]) + assert_array_equal(matrix, np.eye(3)) + conv = erfa.rxp(matrix, vector) + assert_array_equal(matrix @ vector, vector) + assert_array_equal(conv, vector) class TestAstromNotInplace: diff --git a/erfa/ufunc.c.templ b/erfa/ufunc.c.templ index 9edddb3..ae6f923 100644 --- a/erfa/ufunc.c.templ +++ b/erfa/ufunc.c.templ @@ -144,7 +144,7 @@ static inline void copy_to_eraLDBODY(char *ptr, npy_intp s, npy_intp n, note: one can only have 1 or 2 dimensions */ #} {%- if arg.ndim == 2 %} int copy_{{ arg_name - }} = (is_{{ arg_name }}1 != sizeof({{ arg.ctype }}) && + }} = (is_{{ arg_name }}1 != sizeof({{ arg.ctype }}) || is_{{ arg_name }}0 != {{ arg.shape[1] }} * sizeof({{ arg.ctype }})); {%- else %} int copy_{{ arg_name }} = (is_{{ arg_name }}0 != sizeof({{ arg.ctype }}));