-
-
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
minor fixes in multiplication with Diagonals #31443
Conversation
These seem like significant bug fixes. Would you mind adding some tests that would have caught them? |
Sure. BTW, I'd appreciate if anyone could explain to me when/where |
I realized a couple of things. In my first commit, I overlooked the recursive action of IMO, we should discourage to wrap a Diagonal by an
which is quite weird, because what we do here is to first "correct" the wrong wrapper, and then multiply as usual, with the caveat that this is not allocation-free, which is expected for
which would give unexpected/"wrong" results in the matrix of matrix case (and it threw because |
@andreasnoack, @fredrikekre — can one of you comment on whether this is "just a bug fix" and therefore backportable? |
@@ -552,10 +552,9 @@ end | |||
*(x::Adjoint{<:Any,<:AbstractVector}, D::Diagonal) = Adjoint(map((t,s) -> t'*s, D.diag, parent(x))) | |||
*(x::Adjoint{<:Any,<:AbstractVector}, D::Diagonal, y::AbstractVector) = | |||
mapreduce(t -> t[1]*t[2]*t[3], +, zip(x, D.diag, y)) | |||
*(x::Transpose{<:Any,<:AbstractVector}, D::Diagonal) = Transpose(map(*, D.diag, parent(x))) | |||
*(x::Transpose{<:Any,<:AbstractVector}, D::Diagonal) = Transpose(map((t,s) -> transpose(t)*s, D.diag, parent(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.
Does this change the behavior? Was this previously non-recursive?
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.
For Number
eltypes this does not change behaviour, since transpose
doesn't do anything to them. For block matrices, this is a bugfix. It makes this Transpose
line consistent with the Adjoint
line 552 above. Both these are now also covered by tests, testing Complex
numbers (where the adjoint boils down to conjugation on the element level) and 2x2 matrices (where both adjoint
and transpose
have an effect).
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.
Here's why I call this a bugfix and think it's worthy of a backport:
julia> A = reshape([[1 2; 3 4], zeros(Int,2,2), zeros(Int, 2, 2), [5 6; 7 8]], 2, 2)
2×2 Array{Array{Int64,2},2}:
[1 2; 3 4] [0 0; 0 0]
[0 0; 0 0] [5 6; 7 8]
julia> adjoint(1:2) * A
1×2 Adjoint{Adjoint{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}:
[1 2; 3 4] [10 12; 14 16]
julia> transpose(1:2) * A
1×2 Transpose{Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}:
[1 2; 3 4] [10 12; 14 16]
julia> adjoint(1:2) * Diagonal(A)
1×2 Adjoint{Adjoint{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}:
[1 2; 3 4] [10 12; 14 16]
julia> transpose(1:2) * Diagonal(A)
1×2 Transpose{Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}:
[1 3; 2 4] [10 14; 12 16]
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.
LGTM, just one comment.
Thanks for fixing this. I also think this should be considered a bug fix.
I don't recall if we generate these anywhere but I have an idea why they might be there. The problem is that the purpose of julia> Dr = Diagonal(ones(3));
julia> Dc = Diagonal(complex.(ones(3)));
julia> @btime Dr'*Dr.diag;
93.711 ns (2 allocations: 128 bytes)
julia> @btime Dc'*Dc.diag;
136.575 ns (3 allocations: 272 bytes) I'm not sure what the best solution is since it is generally best to push the wrapping to the "simples" array type. Maybe we should consider reintroducing the lazy array conjugation. |
@dkarrasch There is a test failure in the diagonal tests on 32bit. Could you take a look and identify the issue? Except for that, I think this one is good to go. |
It says that there is an issue with this
The displayed numbers look good, except for the last digit in the imaginary part of the last entries (scroll to the very right). Can/should I simply replace all |
Ok, I was under the wrong impression that we, when taking the |
Travis looks even worse now, but the failure does not seem to be related to the Diagonal tests. |
Boy, that CI run looks way worse than I've been seeing recently, but the ones I sampled do seem unrelated. I still don't feel great about merging this with so many failures, so I'm going to re-trigger CI — I think things have stabilized over the past two days. |
I agree we should be careful, and I don't mind if we wait for another few days if other things are still in the flow. |
* minor fixes in multiplication with Diagonals * correct rmul!(A,D), revert changes in AdjTrans(x)*D * [r/l]mul!: replace conj by adjoint, add transpose * add tests * fix typo * relax some tests, added more tests * simplify tests, strict equality (cherry picked from commit a93185f)
* minor fixes in multiplication with Diagonals * correct rmul!(A,D), revert changes in AdjTrans(x)*D * [r/l]mul!: replace conj by adjoint, add transpose * add tests * fix typo * relax some tests, added more tests * simplify tests, strict equality (cherry picked from commit a93185f)
* minor fixes in multiplication with Diagonals * correct rmul!(A,D), revert changes in AdjTrans(x)*D * [r/l]mul!: replace conj by adjoint, add transpose * add tests * fix typo * relax some tests, added more tests * simplify tests, strict equality (cherry picked from commit a93185f)
I see failures similar to the ones you posted above when building Julia on AArch64 Fedora. I've bisected them to this commit. Any ideas?
(and so on) |
I can't spot the slightest difference in the printed numbers, so I assume the difference is in the last digit(s). Maybe we should have been slightly more generous with approx. tests? It seems, however, that tests passed on most platforms, and in those which failed, I can't seem to find error messages as you report here. What's the recommendation? Should I make a "relaxation" PR? |
OK, thanks. That would make sense to me since AFAIK we allow BLAS to return slightly different results depending on many details (e.g. because of the use of SIMD and of variations in the number of threads). Have you found an explanation about the failures you've seen above? Why have they disappeared? |
I can't find any failures that would be related to the tests. So, unfortunately, no, I have no explanation of why there were so many failures at the time. |
* minor fixes in multiplication with Diagonals * correct rmul!(A,D), revert changes in AdjTrans(x)*D * [r/l]mul!: replace conj by adjoint, add transpose * add tests * fix typo * relax some tests, added more tests * simplify tests, strict equality (cherry picked from commit a93185f)
*mul!
with vectorsorder of multiplication