Improve handling of strings supplied as matrix entries #39505
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.
Fixes #34821. The construction
matrix(ZZ, nrows=2, entries=["12", "12"])
is ambiguous, because the string "12" could be interpreted either as the single integer12
or as a sequence of two single-digit integers: that is,entries
could be interpreted as either[12, 12]
or[[1,2], [1,2]]
. To avoid this problem, thesequence_type
method ofMatrixArgs
(insage.matrix.args.pyx
) does not allow strings as the entries of certain matrices with only one column (and in some other situations):However, this special treatment of one-column matrices results in inconsistent (and very puzzling) behaviour, such as the following:
This PR eliminates the inconsistency, by interpreting the string as a scalar (i.e., an element of the ring) in this situation, which is the same interpretation as when there is more than one column.
The PR also makes a similar change in the
get_type
method, in order to eliminate the followingTypeError
:Associated doctests are added/updated.
📝 Checklist
⌛ Dependencies