Skip to content
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

carry out (c)transpose in Ax_mul_Bx methods for Hermitian and Symmetric #22396

Merged
merged 1 commit into from
Jun 26, 2017

Conversation

fredrikekre
Copy link
Member

@fredrikekre fredrikekre commented Jun 16, 2017

Benchmarks: https://gist.github.com/fredrikekre/03f31913dd322f4c245740f3f6894436

transpose(A::Hermitian{<:Complex}) and ctranspose(A::Symmetric{<:Complex}) will allocate more here. (But that amount is comparable to element type promotion so I think it is okay?). It is still faster to be able to use BLAS instead of the generic methods.

(This change only makes sense after #22373 so will rebase after that is merged)

@fredrikekre
Copy link
Member Author

This introduced a lot of ambiguous methods so tests will fail... Will have a look at that tomorrow.


# Fallbacks to avoid generic_matvecmul!/generic_matmatmul!
## Symmetric and Hermitian{<:Real} are invariant to transpose and for
## Hermitian{<:Real} it is faster to carry out the transposition
Copy link
Contributor

Choose a reason for hiding this comment

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

faster than what?

@fredrikekre
Copy link
Member Author

Rebased and fixed ambiguities. The first iteration of this PR was not very well thought through, so I decided to only include the trivial cases in this PR and think a bit more on what to do with the remaining methods. I updated the benchmarks in the top post.

@@ -301,6 +302,25 @@ A_mul_B!(C::StridedMatrix{T}, A::StridedMatrix{T}, B::Hermitian{T,<:StridedMatri

*(A::HermOrSym, B::HermOrSym) = A*full(B)

# Fallbacks to avoid generic_matvecmul!/generic_matmatmul!
## Symmetric and Hermitian{<:Real} are invariant to transpose; peel of the t
Copy link
Contributor

Choose a reason for hiding this comment

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

peel off

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, fixed

A_mul_Bt(A::Diagonal, B::RealHermSymComplexSym) = A*B
At_mul_B(A::RealHermSymComplexSym, D::Diagonal) = A*B
A_mul_Bc(A::Diagonal, B::RealHermSymComplexHerm) = A*B
Ac_mul_B(A::RealHermSymComplexHerm, D::Diagonal) = A*B
Copy link
Member

Choose a reason for hiding this comment

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

Are these definitions correct (considering the recursive nature of [c]transpose)?

Copy link
Contributor

Choose a reason for hiding this comment

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

and given the second input was named D, not B - this method must not have been covered in tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are these definitions correct (considering the recursive nature of [c]transpose)?

I didn't think about that... The t in At_mul_B methods are also considered to be recursive, right?

and given the second input was named D, not B - this method must not have been covered in tests?

Should never do changes like that in the last minute... Will add some tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are these definitions correct (considering the recursive nature of [c]transpose)?

Turns out it is correct after all -- definition of the alias RealHermSymComplexHerm only allows element types <:Number so we will never dispatch here when the element type is a matrix for example (and thus this should not affect the behavior of block matrices). Probably worth adding a comment.

@fredrikekre
Copy link
Member Author

Is this expected beavior:

julia> A = [rand(2, 2) for i in 1:2, j in 1:2]; S = Symmetric(A);

julia> issymmetric(S)
true

julia> issymmetric(Matrix(S))
false

@fredrikekre
Copy link
Member Author

fredrikekre commented Jun 22, 2017

So interaction with Diagonal and Hermitian/Symmetric was broken in #19228 (#19228 (comment)) so the methods with Diagonal/Hermitian/Symmetric in this PR can not really be tested, but they are needed to resolve some ambiguities. Is there any merit to test that these return the correct ArgumentError instead of UndefVarError (ref #22396 (comment))? Edit: I should just fix this interaction instead.... (#22474)

@fredrikekre fredrikekre force-pushed the fe/symmetric-hermitian branch 2 times, most recently from 9cadce7 to 8e81d79 Compare June 25, 2017 03:39
@fredrikekre
Copy link
Member Author

Rebased after #22474 so I think this is good to go now.

A_mul_Bt(A::Diagonal, B::RealHermSymComplexSym) = A*B
At_mul_B(A::RealHermSymComplexSym, D::Diagonal) = A*B
A_mul_Bc(A::Diagonal, B::RealHermSymComplexHerm) = A*B
Ac_mul_B(A::RealHermSymComplexHerm, D::Diagonal) = A*B
Copy link
Member Author

Choose a reason for hiding this comment

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

Great... forgot to change D -> B....
Good thing we have tests!

…mitian and Symmetric

- Symmetric and Hermitian{<:Real} are invariant to transpose so it is a no-op
- Hermitian and Symmetric{<:Real} are invariant to ctranspose so it is a no-op
@fredrikekre
Copy link
Member Author

Timeout on travis 32bit

@tkelman
Copy link
Contributor

tkelman commented Jun 26, 2017

should some benchmarks be added to track that this continues dispatching the way it should?

@fredrikekre
Copy link
Member Author

Sure, will add something for this, #22309 and #22373. This PR doesn't necessarily have to wait for that though(?), put a benchmark label on this, like the other linked ones and I will fix in when time allows.

@KristofferC KristofferC added the kind:potential benchmark Could make a good benchmark in BaseBenchmarks label Jun 26, 2017
@KristofferC KristofferC merged commit 5fc393c into JuliaLang:master Jun 26, 2017
@fredrikekre fredrikekre deleted the fe/symmetric-hermitian branch June 26, 2017 18:43
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:linear algebra Linear algebra kind:potential benchmark Could make a good benchmark in BaseBenchmarks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants