Skip to content

Conversation

@jishnub
Copy link
Member

@jishnub jishnub commented Feb 17, 2025

This adds a level of indirection in *(::AbstractMatrix, ::AbstractMatrix) to avoid method ambiguities with packages. This generally happens when a package defines *(::SpecializedMatrix, ::SomeMatrix) and LinearAlgebra defines *(::SomeMatrix, ::AnotherSpecializedMatrix). By changing the latter to add a method to the internal function mul, we avoid such method ambiguities.

Practically speaking, this is mainly necessary when a method is being added to * with one of the arguments being quite specialized, e.g. *(::Diagonal, ::UpperTriangular{<:Any, <:StridedMatrix}). In such cases, we may add the method to mul instead. This should usually not be necessary if one is just defining *(::Diagonal, ::UpperTriangular). However, seeing that packages may add methods like *(::Diagonal{<:Any, <:SpecialMatrix}, ::AbstractMatrix), we may decide to change these to use mul as well in the future. I've not made too many changes in this PR to avoid clutter, and this mainly focusses on addressing regressions arising from the diagonal-triangular multiplications.

This PR resolves a couple of method ambiguity errors in theArrayLayouts.jl test set that are seen on nightly.

@jishnub jishnub added the backport 1.12 Change should be backported to release-1.12 label Feb 17, 2025
@codecov
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.89%. Comparing base (16d9d61) to head (3e9afb8).
Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1210      +/-   ##
==========================================
+ Coverage   91.87%   91.89%   +0.01%     
==========================================
  Files          34       34              
  Lines       15368    15369       +1     
==========================================
+ Hits        14120    14123       +3     
+ Misses       1248     1246       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good idea. Packages may keep overloading *, but if we can move away the "internal" to LinearAlgebra.jl dispatch toward mul, then this should actually greatly help the ecosystem. I think we have done something very similar with the inplace multiplication methods. I wonder if basically "all" specialized * methods should/could be moved to mul? I see methods in bidiag.jl and lots of triangular stuff. Could be in another PR, though.

@dkarrasch dkarrasch merged commit 5cf41c4 into master Feb 20, 2025
4 checks passed
@dkarrasch dkarrasch deleted the jishnub/mul branch February 20, 2025 11:20
KristofferC pushed a commit that referenced this pull request Feb 25, 2025
@KristofferC KristofferC mentioned this pull request Feb 25, 2025
7 tasks
KristofferC added a commit that referenced this pull request Feb 25, 2025
Backported PRs:
- [x] #1194 
- [x] #1207 
- [x] #1196 <!-- Explicitly declare type constructor imports -->
- [x] #1202 <!-- Add fast path in generic matmul -->
- [x] #1203 <!-- Restrict Diagonal sqrt branch to positive diag -->
- [x] #1210 <!-- Indirection in matrix multiplication to avoid
ambiguities -->
@jishnub jishnub mentioned this pull request May 12, 2025
27 tasks
@jishnub jishnub removed the backport 1.12 Change should be backported to release-1.12 label May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants