-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stdlib: faster kronecker product between hermitian and symmetric matrices #53186
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c22b47a
faster kronecker product between hermitian matrices
araujoms e8cc43e
separate out kernel and add methods for triangular matrices
araujoms e758fa9
slightly faster triangular kernel
araujoms 674fcf7
Merge branch 'master' into hermkron
araujoms 6a32c6e
add tests for kron with partially initialized matrices
araujoms d3f5ec6
Merge branch 'master' into hermkron
araujoms 8a60a4a
specialize methods to numeric matrices
araujoms f1326e3
Merge branch 'master' into hermkron
araujoms c356ede
Merge branch 'master' into hermkron
araujoms 485eadf
Merge branch 'master' into hermkron
oscardssmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method should probably be restricted to
Hermitian{<:Union{Real,Complex}, <StridedMatrix}
and similarly forSymmetric
, and a fallback implementation of the formkron!(C.data, A.data, B.data)
may be added. This will ensure that sparse arrays (or other special array types) remain performant, if they provide akron!
implementation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please forgive me my ignorance as I'm rather new to Julia. You are saying I should change the function declarations to
in order to act only on dense matrices, not sparse ones. Fine, I get this. But then I should also give a fallback implementation, that only acts if the sparse type doesn't provide their own
kron!
? How? I thought the original function declaration was already doing this, as a more specialized function declaration for a specific type would take precedence.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm recommending
as the signature of the method that is added here, and add another method
If the parent has an efficient
kron!
implementation, this would not loop over the entire array. This way, custom array types only need to specializekron!
for their own matrix types, and not for wrappers such asHermitian{<:Union{Real,Complex}, MyArray}
.You're right that the original method already provides a more efficient implementation than the fully generic dense-array implementation that loops over the entire
A
andB
. However, forwardingkron!
to the parents allows us to access even more optimized methods that packages may provide. Ultimately, it's a tradeoff. You're right that a more specialized methodkron!(::Hermitian{<:Union{Real,Complex}}, ::Hermitian{<:Union{Real,Complex}, MyArray}, ::Hermitian{<:Union{Real,Complex}, MyArray})
would take precedence, but it's better if packages don't need to define such methods for wrappers around their arrays, as that greatly increases the total number of methods that need to be defined. If we forward the operation to the parent, then the parent does not need to know aboutHermitian
at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, the issue is that a generic Kronecker product over sparse arrays will still be vastly more efficient for Hermitian matrices than my dense version, so we don't want to capture that. Of course, such a sparse type can also implement its own specialization for Hermitian matrices, but that's a different issue.
The best I could come up with was
for the fallback and
for the signature of the method itself. It's rather hideous. Is there a better solution?
Also, doesn't exactly the same issue applies to
dot
? Is there any package actually implementing faster versions ofdot
andkron
for sparse arrays?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take my comment back, as
kron
forwarded to the parent doesn't produce the same result:I think the current implementation is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just do the symmetric/hermitian for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 I wasted a lot of time doing the triangular case only because @dkarrasch asked. I have no use for it. Next time please only ask for features you actually want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I'm in no way suggesting that we abandon the work if you've implemented it already. My impression was otherwise. Please continue with your work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. Well, it's done already, I've already pushed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well?