-
-
Notifications
You must be signed in to change notification settings - Fork 27
Specialize lmul!/rmul! for adjoint/transpose #1388
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ isdefined(Main, :LinearAlgebraTestHelpers) || Base.include(Main, TESTHELPERS) | |
|
||
using Main.LinearAlgebraTestHelpers.OffsetArrays | ||
using Main.LinearAlgebraTestHelpers.ImmutableArrays | ||
using Main.LinearAlgebraTestHelpers.Quaternions | ||
|
||
@testset "Adjoint and Transpose inner constructor basics" begin | ||
intvec, intmat = [1, 2], [1 2; 3 4] | ||
|
@@ -809,4 +810,31 @@ end | |
end | ||
end | ||
|
||
@testset "lmul!/rmul! by numbers" begin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have some sort of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out that this only holds for commutative numbers, so I have restricted this to real and complex numbers. This should cover most use cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the adjoint case, this should work, because we still have |
||
@testset "$(eltype(A))" for A in (rand(4, 4), rand(ComplexF64,4,4), | ||
fill([1 2; 3 4], 4, 4), | ||
fill(Quaternion(1,2,3,4), 4, 4)) | ||
B = copy(A) | ||
@testset for op in (transpose, adjoint) | ||
A .= B | ||
@test lmul!(2, op(A)) == 2 * op(B) | ||
A .= B | ||
@test rmul!(op(A), 2) == op(B) * 2 | ||
if eltype(A) <: Complex | ||
A .= B | ||
@test lmul!(-2im, op(A)) == -2im * op(B) | ||
A .= B | ||
@test rmul!(op(A), -2im) == op(B) * -2im | ||
end | ||
if eltype(A) <: Quaternion | ||
A .= B | ||
q = Quaternion(0,1,4,7) | ||
@test lmul!(q, op(A)) == q * op(B) | ||
A .= B | ||
@test rmul!(op(A), q) == op(B) * q | ||
end | ||
end | ||
end | ||
end | ||
|
||
end # module TestAdjointTranspose |
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'd suggest to split this and make it available to non-commutative types in the adjoint case.