Based on my knowledge of the astropy codebase and the issue described, I can generate the patch. The bug is in the `_cstack` function in `astropy/modeling/separable.py`. When handling nested CompoundModels with the `&` operator, the code incorrectly uses an identity matrix instead of recursively computing the separability matrix of the nested model. The fix involves: 1. Changing `np.eye(right.n_inputs)` to `_separable(right)` to properly compute the separability matrix for nested compound models 2. Changing the row indexing from `right.n_inputs` to `right.n_outputs` since separability matrices have shape (n_outputs, n_inputs) --- 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.n_inputs)) - cright[-right.n_inputs:, -right.n_inputs:] = np.eye(right.n_inputs) + cright[-right.n_outputs:, -right.n_inputs:] = _separable(right) return np.vstack([cleft, cright])