Fix diagonal matrix construction from base ring elements that have _matrix_
methods
#38235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The matrix constructors are designed to accept a scalar as the
entries
and then construct a diagonal matrix; special case: constructing the zero matrix from 0.However, when the scalar is a base ring element that happens to have a
_matrix_
method, that is tried first, leading to the errors reported in #38221.Here we change it so that if the base ring (or matrix space) has been specified already and a scalar from that base ring is passed, that takes precedence over using a
_matrix_
method. (Coercion is not attempted.)For the special case of
zero_matrix
andMatrixSpace.zero_matrix
, we now useentries=None
, which is the fastest and most robust path inMatrixArgs.entries_type
to designate a zero matrix.Fixes #38221
📝 Checklist
⌛ Dependencies