From 380b5932f025fafb2f1073321fa7c164f1b1291e Mon Sep 17 00:00:00 2001 From: Helge Gehring <42973196+HelgeGehring@users.noreply.github.com> Date: Tue, 15 Aug 2023 01:01:23 -0700 Subject: [PATCH 1/4] add real/imag for VectorValue --- src/TensorValues/TensorValues.jl | 2 +- src/TensorValues/VectorValueTypes.jl | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/TensorValues/TensorValues.jl b/src/TensorValues/TensorValues.jl index e2227975c..513d046a0 100644 --- a/src/TensorValues/TensorValues.jl +++ b/src/TensorValues/TensorValues.jl @@ -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 diff --git a/src/TensorValues/VectorValueTypes.jl b/src/TensorValues/VectorValueTypes.jl index 6369b4dae..af3928912 100644 --- a/src/TensorValues/VectorValueTypes.jl +++ b/src/TensorValues/VectorValueTypes.jl @@ -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(real.(x.data)) +imag(x::VectorValue{D,<:Complex}) where{D} = VectorValue(imag.(x.data)) + ############################################################### # Introspection (VectorValue) ############################################################### From cb4dc638559f8b40080fcb56a5acd6a716cccb72 Mon Sep 17 00:00:00 2001 From: Helge Gehring <42973196+HelgeGehring@users.noreply.github.com> Date: Tue, 15 Aug 2023 01:14:21 -0700 Subject: [PATCH 2/4] add dimension to real/imag of VectorValue --- src/TensorValues/VectorValueTypes.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TensorValues/VectorValueTypes.jl b/src/TensorValues/VectorValueTypes.jl index af3928912..a142afc13 100644 --- a/src/TensorValues/VectorValueTypes.jl +++ b/src/TensorValues/VectorValueTypes.jl @@ -92,8 +92,8 @@ 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(real.(x.data)) -imag(x::VectorValue{D,<:Complex}) where{D} = VectorValue(imag.(x.data)) +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) From f6a1bc002c87b2bab83aaad7803664c2643bfac6 Mon Sep 17 00:00:00 2001 From: Helge Gehring <42973196+HelgeGehring@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:36:31 -0700 Subject: [PATCH 3/4] add tests for real/imag VectorValue --- test/TensorValuesTests/OperationsTests.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/TensorValuesTests/OperationsTests.jl b/test/TensorValuesTests/OperationsTests.jl index 631a8fe9f..d7fd0b4c3 100644 --- a/test/TensorValuesTests/OperationsTests.jl +++ b/test/TensorValuesTests/OperationsTests.jl @@ -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.) From ecad12162b35ae8803d3fc57792c8ab18ef3da60 Mon Sep 17 00:00:00 2001 From: Helge Gehring <42973196+HelgeGehring@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:40:42 -0700 Subject: [PATCH 4/4] add NEWS.md entry --- NEWS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index c731c011e..5c344a2a2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Implemented real/imag for VectorValues + ## [0.17.19] - 2023-08-23 ### Fixed