Skip to content

Commit

Permalink
Merge pull request #934 from HelgeGehring/real_imag_vectorvalue
Browse files Browse the repository at this point in the history
add real/imag for VectorValue
  • Loading branch information
JordiManyer authored Nov 2, 2023
2 parents 8ebe624 + b03325c commit 86e8101
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Implemented real/imag for VectorValues

### Fixed

- `BlockMultiFieldStyle` available for `TransientMultiFieldFESpaces` since PR [#946](https://github.com/gridap/Gridap.jl/pull/946).
Expand Down
2 changes: 1 addition & 1 deletion src/TensorValues/TensorValues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export data_index
import Base: show
import Base: zero, one
import Base: +, -, *, /, \, ==, , isless
import Base: conj
import Base: conj, real, imag
import Base: sum, maximum, minimum
import Base: getindex, iterate, eachindex, lastindex
import Base: size, length, eltype
Expand Down
3 changes: 3 additions & 0 deletions src/TensorValues/VectorValueTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ change_eltype(::VectorValue{D,T1},::Type{T2}) where {D,T1,T2} = change_eltype(Ve

get_array(arg::VectorValue{D,T}) where {D,T} = convert(SVector{D,T}, arg)

real(x::VectorValue{D,<:Complex}) where {D} = VectorValue{D}(real.(x.data))
imag(x::VectorValue{D,<:Complex}) where {D} = VectorValue{D}(imag.(x.data))

###############################################################
# Introspection (VectorValue)
###############################################################
Expand Down
8 changes: 8 additions & 0 deletions test/TensorValuesTests/OperationsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,14 @@ b = 4.0 - 3.0*im
@test outer(a,b) == a*b
@test inner(a,b) == a*b

@test real(VectorValue(1+1im)) == VectorValue(1)
@test real(VectorValue(1+1im, 1+1im)) == VectorValue(1, 1)
@test real(VectorValue(1+1im, 1+1im, 1+1im)) == VectorValue(1, 1, 1)

@test imag(VectorValue(1+1im)) == VectorValue(1)
@test imag(VectorValue(1+1im, 1+1im)) == VectorValue(1, 1)
@test imag(VectorValue(1+1im, 1+1im, 1+1im)) == VectorValue(1, 1, 1)

# Broadcast
a = VectorValue(1,2,3)
b = VectorValue(1.,2.,3.)
Expand Down

0 comments on commit 86e8101

Please sign in to comment.