Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix showing conjugate variables #288

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading