From c9450f1113a045c86ffeea073b018385c8dc85ff Mon Sep 17 00:00:00 2001 From: Michael Helton Date: Tue, 18 Apr 2023 08:50:06 -0400 Subject: [PATCH] add conjugate --- src/complex.jl | 3 +++ test/complex_test.jl | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/complex.jl b/src/complex.jl index c508cc5..6b3c2d5 100644 --- a/src/complex.jl +++ b/src/complex.jl @@ -79,3 +79,6 @@ end @inline fadd(x::Union{T, Complex{T}}, y::Union{T, Complex{T}}) where T = x + y @inline fsub(x::Union{T, Complex{T}}, y::Union{T, Complex{T}}) where T = x - y @inline fneg(x::Union{T, Complex{T}}) where T = -x + +# conjugate +@inline Base.conj(z::ComplexVec{N, FloatTypes}) where {N, FloatTypes} = ComplexVec{N, FloatTypes}(z.re, fneg(z.im)) diff --git a/test/complex_test.jl b/test/complex_test.jl index 1db891f..464f7bb 100644 --- a/test/complex_test.jl +++ b/test/complex_test.jl @@ -62,6 +62,15 @@ end @test convert(ComplexVec{4, Float64}, 1.2) == ComplexVec{4, Float64}((1.2, 1.2, 1.2, 1.2), (0.0, 0.0, 0.0, 0.0)) +# test conjugate +let + c = (1.1 + 1.4im, 1.3 - 1.2im) + cv = ComplexVec{2, Float64}((1.1, 1.3), (1.4, -1.2)) + cconj = conj(cv) + @test cconj[1] == conj(c[1]) + @test cconj[2] == conj(c[2]) +end + P1 = (1.1, 1.2, 1.4, 1.5, 1.3, 1.4, 1.5, 1.6, 1.7, 1.2, 1.2, 2.1, 3.1, 1.4, 1.5) P2 = (1.1, 1.2, 1.4, 1.53, 1.32, 1.41, 1.52, 1.64, 1.4, 1.0, 1.6, 2.5, 3.1, 1.9, 1.2) pp3 = pack_poly((P1, P2))