Skip to content

Commit

Permalink
Fix showing conjugate variables (#288)
Browse files Browse the repository at this point in the history
* Fix showing conjugate variables

* Add test
  • Loading branch information
projekter authored Dec 16, 2023
1 parent 79c141e commit 3c5b774
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Base.show(io::IO, p::TypesWithShow) = show(io, MIME"text/plain"(), p)
function _show(io::IO, mime::MIME, var::AbstractVariable)
base, indices = name_base_indices(var)
if isconj(var)
for c in base
for c in String(base)
print(io, c, '\u0305') # displays as overbar (̄z)
end
else
Expand Down
9 changes: 9 additions & 0 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
ordinary_variable(real(x)) ==
ordinary_variable(imag(x)) ==
ordinary_variable(x)
@testset "show" begin
struct SymbolVar <: MP.AbstractVariable end
struct SymbolConjVar <: MP.AbstractVariable end
Base.isreal(::Union{SymbolVar,SymbolConjVar}) = false
MP.name_base_indices(::Union{SymbolVar,SymbolConjVar}) = (:xy, (1, 2))
MP.isconj(::SymbolConjVar) = true
@test sprint(show, SymbolVar()) == "xy₁₋₂"
@test sprint(show, SymbolConjVar()) == "x̅y̅₁₋₂"
end
@test conj(x) != x && conj(conj(x)) == x
@test real(x) == real(conj(x))
@test imag(conj(x)) == -imag(x)
Expand Down

0 comments on commit 3c5b774

Please sign in to comment.