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

Compatibility with SparseArrays #628

Closed
kalmarek opened this issue Feb 13, 2024 · 2 comments · Fixed by #631
Closed

Compatibility with SparseArrays #628

kalmarek opened this issue Feb 13, 2024 · 2 comments · Fixed by #631

Comments

@kalmarek
Copy link
Contributor

Hey, thanks for all the recent work on IntervalArithmetic!

It seems that common functionality for SparseArrays are still broken on 0.22.7 (despite #604):

julia> using IntervalArithmetic

julia> using SparseArrays

julia> x = [1.0 0; 0 0]
2×2 Matrix{Float64}:
 1.0  0.0
 0.0  0.0

julia> spx = sparse(x)
2×2 SparseMatrixCSC{Float64, Int64} with 1 stored entry:
 1.0    
       

julia> spix = interval.(spx)
2×2 SparseMatrixCSC{Interval{Float64}, Int64} with 1 stored entry:
 [1.0, 1.0]_com               
                             

julia> spx .= zero(eltype(spx))
2×2 SparseMatrixCSC{Float64, Int64} with 1 stored entry:
 0.0    
       

julia> spix .= zero(eltype(spix))
ERROR: ArgumentError: `==` is purposely not supported for intervals. See instead `isequal_interval`
Stacktrace:
 [1] ==(::Interval{Float64}, ::Interval{Float64})
   @ IntervalArithmetic ~/.julia/packages/IntervalArithmetic/7FL3g/src/intervals/real_interface.jl:83
 [2] fill!(A::SparseMatrixCSC{Interval{Float64}, Int64}, x::Interval{Float64})
   @ SparseArrays ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/SparseArrays/src/sparsevector.jl:2303
 [3] copyto!
   @ Base.Broadcast ./broadcast.jl:964 [inlined]
 [4] materialize!
   @ Base.Broadcast ./broadcast.jl:914 [inlined]
 [5] materialize!(dest::SparseMatrixCSC{Interval{Float64}, Int64}, bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(identity), Tuple{Interval{Float64}}})
   @ Base.Broadcast ./broadcast.jl:911
 [6] top-level scope
   @ REPL[24]:1

which can be traced to this line:
https://github.com/JuliaSparse/SparseArrays.jl/blob/4cc31f23619cfe4c2bcded16e71b7ec5cef974f9/src/sparsevector.jl#L2381

Looking at the comments of the file this is intentional to support -0.0 which iszero but is not equal to 0.0.

@Kolaru
Copy link
Collaborator

Kolaru commented Feb 14, 2024

That's a case where [-1, 1] == 0 should return false, as per the standard. I never thought I would find one in my lifetime :'-)

On the downside, it means we can not fix it by changing == or iszero (it would break too many other codes). This will have to be a package extension.

@OlivierHnt
Copy link
Member

On the other hand, on the 0.22 branch we have iszero(interval(-1, 1)) == false and interval(-1, 1) != 0.
For consistency we ought to allow interval(-1, 1) != interval(0).

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

Successfully merging a pull request may close this issue.

3 participants