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 printing of matrices of intervals #434

Closed
dpsanders opened this issue Jan 15, 2021 · 5 comments · Fixed by #567
Closed

Fix printing of matrices of intervals #434

dpsanders opened this issue Jan 15, 2021 · 5 comments · Fixed by #567

Comments

@dpsanders
Copy link
Member

dpsanders commented Jan 15, 2021

julia> M = [1.2..1.6 1.2..1.6; -1..1 -1..1]
2×2 Array{Interval{Float64},2}:
      [1.19999, 1.60001]       [1.19999, 1.60001]
 [-1, 1]                  [-1, 1]
@dpsanders
Copy link
Member Author

Should be aligned better.

@lucaferranti
Copy link
Member

quite interesting that Arrays of interval boxes do not suffer from this 🤔

julia> M
2×2 Matrix{Interval{Float64}}:
      [1.19999, 1.60001]       [1.19999, 1.60001]
 [-1, 1]                  [-1, 1]

julia> IntervalBox.(M, 2)
2×2 Matrix{IntervalBox{2, Float64}}:
 [1.19999, 1.60001] × [1.19999, 1.60001]  [1.19999, 1.60001] × [1.19999, 1.60001]
 [-1, 1] × [-1, 1]                        [-1, 1] × [-1, 1]

@dpsanders
Copy link
Member Author

That's strange. Maybe there's a problem with how the display functions are defined. I'm not sure how Julia checks the width of the output to align it.

@lucaferranti
Copy link
Member

lucaferranti commented Mar 25, 2021

Based on this prototype, I think indeed the problem is somewhere in the display functions of the package. Now the funny part is figuring out where exactly 🤣 .

julia> struct Tmp
       lo
       hi
       end

julia> Base.show(io::IO, a::Tmp) = print(io, "[$(a.lo), $(a.hi)]")

julia> a = Tmp(1.19999, 1.60001)
[1.19999, 1.60001]

julia> b = Tmp(-1, 1)
[-1, 1]

julia> [a a; b b]
2×2 Matrix{Tmp}:
 [1.19999, 1.60001]  [1.19999, 1.60001]
 [-1, 1]             [-1, 1]

I don't understand why it works with interval boxes though, based on the source code, I think join(X.v, " × ") calls the representation(X::Interval) somewhere under the hood, so I don't see what fixes the problem.

function representation(X::IntervalBox, format=nothing)

    if format == nothing
        format = display_params.format  # default
    end

    if display_params.format == :full
        return string("IntervalBox(", join(X.v, ", "), ")")

    else
        return join(X.v, " × ")
    end

end

@lbenet
Copy link
Member

lbenet commented Feb 15, 2023

Fixed in the 1.0-dev branch...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants