Skip to content

Commit cccc913

Browse files
committed
some improvements to complex
1 parent ea5cd64 commit cccc913

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/complex.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
function Base.show(io::IO, p::Complex{<:AbstractParticles})
2+
print(io, to_num_str(p, 3))
3+
end
14

25
for PT in (:Particles, :StaticParticles)
36
@eval begin
@@ -75,8 +78,8 @@ for ff in (sqrt, exp, sin, cos)
7578
@eval $(Symbol(f,:!))(s, z::Complex{<: AbstractParticles}) = ℂ2ℂ_function!($f, s, z)
7679
end
7780

78-
Base.isinf(p::Complex{<: AbstractParticles}) = @show isinf(real(p)) || isinf(imag(p))
79-
Base.isfinite(p::Complex{<: AbstractParticles}) = @show isfinite(real(p)) && isfinite(imag(p))
81+
Base.isinf(p::Complex{<: AbstractParticles}) = isinf(real(p)) || isinf(imag(p))
82+
Base.isfinite(p::Complex{<: AbstractParticles}) = isfinite(real(p)) && isfinite(imag(p))
8083

8184
function Base.:(/)(a::Complex{T}, b::Complex{T}) where T<:AbstractParticles
8285
are = real(a); aim = imag(a); bre = real(b); bim = imag(b)

src/particles.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function Base.show(io::IO, ::MIME"text/plain", p::AbstractParticles{T,N}) where
124124
end
125125
end
126126

127-
function Base.show(io::IO, ::MIME"text/plain", z::Complex{<:AbstractParticles})
127+
function Base.show(io::IO, z::Complex{<:AbstractParticles})
128128
r, i = reim(z)
129129
compact = get(io, :compact, false)
130130
print(io, "(")
@@ -243,9 +243,9 @@ for PT in ParticleSymbols
243243
Helper function for performing uncertainty propagation through complex-valued functions with vector inputs.
244244
Applies `f : ℝⁿ → Cⁿ` to an array of particles. E.g., `LinearAlgebra.eigvals(p::Matrix{<:AbstractParticles}) = ℝⁿ2ℂⁿ_function(eigvals,p)`
245245
"""
246-
function ℝⁿ2ℂⁿ_function(f::F, p::AbstractArray{$PT{T,N}}) where {F,T,N}
246+
function ℝⁿ2ℂⁿ_function(f::F, p::AbstractArray{$PT{T,N}}; kwargs...) where {F,T,N}
247247
individuals = map(1:length(p[1])) do i
248-
f(getindex.(p,i))
248+
f(getindex.(p,i); kwargs...)
249249
end
250250
PRT = $PT{T,N}
251251
RT = eltype(eltype(individuals))
@@ -558,7 +558,7 @@ LinearAlgebra.norm(x::AbstractParticles, args...) = abs(x)
558558

559559

560560
Base.log(p::Matrix{<:AbstractParticles}) = ℝⁿ2ℂⁿ_function(log,p) # Matrix more specific than StridedMatrix used in Base.log
561-
LinearAlgebra.eigvals(p::Matrix{<:AbstractParticles}) = ℝⁿ2ℂⁿ_function(eigvals,p)
561+
# LinearAlgebra.eigvals(p::Matrix{<:AbstractParticles}; kwargs...) = ℝⁿ2ℂⁿ_function(eigvals,p; kwargs...) # Replaced with implementation below
562562
Base.exp(p::AbstractMatrix{<:AbstractParticles}) = ℝⁿ2ℝⁿ_function(exp, p)
563563
LinearAlgebra.lyap(p1::Matrix{<:AbstractParticles}, p2::Matrix{<:AbstractParticles}) = ℝⁿ2ℝⁿ_function(lyap, p1, p2)
564564

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ Random.seed!(0)
470470
0.0 + (1.0 ± 0.0005)*im])) < 0.002
471471

472472
e = eigvals([1 ± 0.001 0; 0 1.])
473-
@test e isa Vector{Particles{Float64,DEFAULT_NUM_PARTICLES}}
474-
@test e [1.0 ± 0.00058, 1.0 ± 0.00058]
473+
@test e isa Vector{Complex{Particles{Float64, DEFAULT_NUM_PARTICLES}}}
474+
@test all(isapprox.(e, [1.0 ± 0.00058, 1.0 ± 0.00058], atol=1e-2))
475475

476476
@test (1 .. 2) isa Particles
477477
@test std(diff(sort((1 .. 2).particles))) < sqrt(eps())

0 commit comments

Comments
 (0)