Disambiguate structured and abstract matrix multiplication #52464
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 various methods of the form
*(::AbstractMatrix, ::Diagonal)
for structured matrices lead to method ambiguities in packages that define*(::MyMatrix, ::AbstractMatrix)
. However, these methods only seem to be defined here to use the first argument to construct the destination, as opposed to the fallback method that uses the second argument. Instead of specializing*
, we might as well specialize the call tosimilar
that chooses which matrix to use to construct the destination. This reduces code duplication, as well as avoids these ambiguities altogether. This also makes the destination types ofA * B
andB * A
identical if one of the two is aStructuredMatrix
.After this, for example, both of these produce sparse matrices:
The former is a
Matrix
on master.Close #51354
Address JuliaStats/PDMats.jl#176 on nightly
This PR changes the following behavior:
to
I'm unsure if the choice of
_init_eltype
was deliberate here (there is a test that specifically checks that_init_eltype
isn't being used for general matrices).