-
Notifications
You must be signed in to change notification settings - Fork 102
Allow real and imag functions to return real TensorValue #1080
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
Conversation
Thanks for the PR @ovanvincq , this is good for me. v1 = VectorValue(1+1im)
v2 = VectorValue(1)
@test real(v1) == v2 && eltype(real(v1)) == eltype(v2)
@test imag(v1) == v2 && eltype(imag(v1)) == eltype(v2)
v2 = VectorValue(1-1im)
@test conj(v1) == v2 && eltype(conj(v1)) == eltype(v2)
v1 = VectorValue(1+1im, 1+1im)
v2 = VectorValue(1, 1)
@test real(v1) == v2 && eltype(real(v1)) == eltype(v2)
@test imag(v1) == v2 && eltype(imag(v1)) == eltype(v2)
v2 = VectorValue(1-1im, 1-1im)
@test conj(v1) == v2 && eltype(conj(v1)) == eltype(v2)
v1 = VectorValue(1+1im, 1+1im, 1+1im)
v2 = VectorValue(1, 1, 1)
@test real(v1) == v2 && eltype(real(v1)) == eltype(v2)
@test imag(v1) == v2 && eltype(imag(v1)) == eltype(v2)
v2 = VectorValue(1-1im, 1-1im, 1-1im)
@test conj(v1) == v2 && eltype(conj(v1)) == eltype(v2)
v1 = TensorValue(1+1im, 1+1im, 1+1im, 1+1im)
v2 = TensorValue(1, 1, 1, 1)
@test real(v1) == v2 && eltype(real(v1)) == eltype(v2)
@test imag(v1) == v2 && eltype(imag(v1)) == eltype(v2)
v2 = TensorValue(1-1im, 1-1im, 1-1im, 1-1im)
@test conj(v1) == v2 && eltype(conj(v1)) == eltype(v2)
v1 = SymTracelessTensorValue(1+1im, 1+1im)
v2 = SymTracelessTensorValue(1, 1)
@test real(v1) == v2 && eltype(real(v1)) == eltype(v2)
@test imag(v1) == v2 && eltype(imag(v1)) == eltype(v2)
v2 = SymTracelessTensorValue(1-1im, 1-1im)
@test conj(v1) == v2 && eltype(conj(v1)) == eltype(v2) |
Are we sure that the changes to
|
Oh true julia> my_eltype(op,r,a...) = typeof(reduce(op, zero.(eltype.(a))))
my_eltype (generic function with 1 method)
julia> my_eltype2(op,r,a,b) = typeof(op(zero(eltype(a)),zero(eltype(b))))
my_eltype2 (generic function with 2 methods)
julia> @code_typed my_eltype(+,(1-im,),(1.0-im),(1-im))
CodeInfo(
1 ─ %1 = Core.tuple(a)::Tuple{Tuple{ComplexF64, Complex{Int64}}}
....
│ %11 = Main.reduce(op, %10)::Any
│ %12 = Main.typeof(%11)::DataType # computed at runtime
└── return %12
) => DataType
julia> @code_typed my_eltype2(+,(1-im,),(1.0-im),(1-im))
CodeInfo(
1 ─ return ComplexF64
) => Type{ComplexF64} |
Ok, I made the requested corrections. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1080 +/- ##
==========================================
- Coverage 89.06% 89.05% -0.02%
==========================================
Files 197 197
Lines 23927 23938 +11
==========================================
+ Hits 21310 21317 +7
- Misses 2617 2621 +4 ☔ View full report in Codecov by Sentry. |
@ovanvincq can you add some coverage for the missing lines? It's not critical, but better than not have it. Also, could you add a description of the PR in the |
@JordiManyer I added some tests for |
This small PR allows the
real
andimag
functions to return real results like the base Julia functionsreturns