From 42509439711548a040b24a359efe34291853db33 Mon Sep 17 00:00:00 2001 From: Casey Brooks Date: Thu, 18 Dec 2025 15:10:36 +0000 Subject: [PATCH 1/2] test: add separability regressions [skip ci] --- .../tests/test_separable_regressions.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 astropy/modeling/tests/test_separable_regressions.py diff --git a/astropy/modeling/tests/test_separable_regressions.py b/astropy/modeling/tests/test_separable_regressions.py new file mode 100644 index 000000000000..2b44db7b9fbb --- /dev/null +++ b/astropy/modeling/tests/test_separable_regressions.py @@ -0,0 +1,38 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +"""Regression tests for separability matrix combinations.""" + +from __future__ import annotations + +import numpy as np + +from astropy.modeling import models +from astropy.modeling.separable import separability_matrix + + +def test_separability_plain_and(): + compound = models.Linear1D(10) & models.Linear1D(5) + expected = np.array([[True, False], [False, True]]) + assert np.array_equal(separability_matrix(compound), expected) + + +def test_separability_mixed_compound(): + compound = models.Identity(2) & models.Linear1D(10) & models.Linear1D(5) + expected = np.eye(4, dtype=bool) + assert np.array_equal(separability_matrix(compound), expected) + + +def test_separability_nested_compound(): + inner = models.Identity(2) + compound = models.Identity(2) & inner + expected = np.eye(4, dtype=bool) + assert np.array_equal(separability_matrix(compound), expected) + + +def test_separability_deep_nesting_equivalence(): + a = models.Linear1D(1) + b = models.Linear1D(2) + c = models.Linear1D(3) + d = models.Linear1D(4) + nested = (a & (b & c)) & d + flat = a & b & c & d + assert np.array_equal(separability_matrix(nested), separability_matrix(flat)) From 7464340f26b4897c07fa49732564bd97a2bec672 Mon Sep 17 00:00:00 2001 From: Casey Brooks Date: Thu, 18 Dec 2025 15:10:47 +0000 Subject: [PATCH 2/2] fix: correct separability cstack handling [skip ci] --- astropy/modeling/separable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astropy/modeling/separable.py b/astropy/modeling/separable.py index a308e27297d1..45bea360859c 100644 --- a/astropy/modeling/separable.py +++ b/astropy/modeling/separable.py @@ -242,7 +242,7 @@ def _cstack(left, right): cright = _coord_matrix(right, 'right', noutp) else: cright = np.zeros((noutp, right.shape[1])) - cright[-right.shape[0]:, -right.shape[1]:] = 1 + cright[-right.shape[0]:, -right.shape[1]:] = right return np.hstack([cleft, cright])