-
Notifications
You must be signed in to change notification settings - Fork 73
Enhance performance of generic transpose and transpose! methods, restrict in-place transpose! to square matrices
#1937
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1937 +/- ##
==========================================
+ Coverage 88.06% 88.33% +0.27%
==========================================
Files 126 126
Lines 31736 31797 +61
==========================================
+ Hits 27948 28088 +140
+ Misses 3788 3709 -79 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
58c57fb to
ca700e0
Compare
src/Matrix.jl
Outdated
| return x | ||
| end | ||
| # we have no generic way to change the dimensions of x, so instead we | ||
| # delegate to the two argument version of transpose! |
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.
Tests fails because in Nemo some transpose! methods with just one argument only work on square matrices.
Perhaps that the right decision, and I should match it here, and just throw an error in that case, too? Perhaps a bit more helpful one, but an error nevertheless.
Or perhaps the Nemo methods should be made more general.
Any thoughts on this, anyone?
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 never missed it for non-square matrices, but maybe @fieker has opinion/wishes?
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.
if it was missing - how can there be a test for it? I never used inplace transpose on non-square matrices. i do understand that this is possible (in flint) and an interesting research problem....
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.
Reviving this PR from 1 year ago:
The existing method for transpose! simply delegates to transpose:
src/Matrix.jl:1488:transpose!(A::MatrixElem) = transpose(A)
And there is an existing test which invokes transpose! on a non-square matrix:
a = QQ[1 2 3; 4 5 6]
...
b = transpose(a)
@test AbstractAlgebra.transpose!(a) == b
So I have two choices here:
- adjust the test to only invoke
transpose!on a square matrix, and enforce that in the implementation - allow non-square matrices (as the implementation here currently does).
Personally I'd be perfectly happy with 1, if we can agree on it (the comments from a year ago suggest that might be the case)
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.
This PR also adds a docstring for transpose! which of course should be adjusted depending on what we decide here.
It also inserts that docstring into the manual. Of course we also should agree on whether we want that (I don't see why not, but...)
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 noticed that Nemo also explicitly supports non-square matrices, e.g. it has
transpose!(A::Union{ZZMatrix,QQMatrix}) = is_square(A) ? transpose!(A, A) : transpose(A)On the other hand, it also errors out in a few cases, e.g.:
function transpose!(a::FqMatrix)
!is_square(a) && error("Matrix must be a square matrix")
@ccall libflint.fq_default_mat_transpose(a::Ref{FqMatrix}, a::Ref{FqMatrix}, base_ring(a)::Ref{FqField})::Nothing
endca700e0 to
6187c3a
Compare
6187c3a to
219cc17
Compare
|
As a "naive" user I would wonder what |
219cc17 to
c7bc337
Compare
transpose and transpose!transpose and transpose!
|
I've modified the PR to prevent in-place transpose for non-square matrices. Let's see if it breaks anything in Nemo, Hecke or Oscar. |
c7bc337 to
a6a1865
Compare
| end | ||
| transpose(x::MatRingElem) = MatRingElem(transpose(matrix(x))) | ||
| transpose!(x::MatRingElem) = MatRingElem(transpose!(matrix(x))) | ||
| transpose!(z::T, x::T) where T <: MatRingElem = MatRingElem(transpose!(matrix(z), matrix(x))) |
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.
Are these being tested right now?
Also restrict unary (in-place) transpose! to square matrices
eda9511 to
131c6ce
Compare
transpose and transpose!transpose and transpose!, restrict in-place transpose! to square matrices
transpose and transpose!, restrict in-place transpose! to square matricestranspose and transpose! methods, restrict in-place transpose! to square matrices
|
I think this is good to merge now, if someone would like to approve it ... |
|
I think you have to merge ignoring the checks. |
|
It was all green. Why the restart? |
I thought #2259 would resolve the CI issue. But I now noticed it is due to matching branches... |
Also forbid in-place
transpose!for non-square matrices.