Skip to content

Fix isapprox for TensorMaps with different spaces#439

Open
Yue-Zhengyuan wants to merge 1 commit into
mainfrom
fix-isapprox
Open

Fix isapprox for TensorMaps with different spaces#439
Yue-Zhengyuan wants to merge 1 commit into
mainfrom
fix-isapprox

Conversation

@Yue-Zhengyuan
Copy link
Copy Markdown
Member

This PR improves isapprox for TensorMaps: when two TensorMaps have different spaces, isapprox should directly return false. Previously such a check is missing and a SpaceMismatch error will be raised.

@Jutho
Copy link
Copy Markdown
Member

Jutho commented May 21, 2026

I think the current behavior is in line with how isapprox works on matrices:

julia> isapprox(rand(3,4), rand(5,6))
ERROR: DimensionMismatch: a has size (3, 4), b has size (5, 6), mismatch at dim 1
Stacktrace:
 [1] throw_promote_shape_mismatch(a::Tuple{Base.OneTo{…}, Base.OneTo{…}}, b::Tuple{Base.OneTo{…}, Base.OneTo{…}}, i::Int64)
   @ Base ./indices.jl:135
 [2] promote_shape
   @ ./indices.jl:196 [inlined]
 [3] promote_shape
   @ ./indices.jl:188 [inlined]
 [4] -(A::Matrix{Float64}, B::Matrix{Float64})
   @ Base ./arraymath.jl:7
 [5] isapprox(x::Matrix{…}, y::Matrix{…}; atol::Int64, rtol::Float64, nans::Bool, norm::typeof(LinearAlgebra.norm))
   @ LinearAlgebra ~/.julia/juliaup/julia-1.12.5+0.aarch64.apple.darwin14/Julia-1.12.app/Contents/Resources/julia/share/julia/stdlib/v1.12/LinearAlgebra/src/generic.jl:1985
 [6] isapprox(x::Matrix{Float64}, y::Matrix{Float64})
   @ LinearAlgebra ~/.julia/juliaup/julia-1.12.5+0.aarch64.apple.darwin14/Julia-1.12.app/Contents/Resources/julia/share/julia/stdlib/v1.12/LinearAlgebra/src/generic.jl:1981
 [7] top-level scope
   @ REPL[1]:1
Some type information was truncated. Use `show(err)` to see complete types.

@Yue-Zhengyuan
Copy link
Copy Markdown
Member Author

Let me ask if LinearAlgebra.jl does this intentionally: JuliaLang/LinearAlgebra.jl#1624

@lkdvos
Copy link
Copy Markdown
Member

lkdvos commented May 25, 2026

As I mentioned in that issue there, I am not a huge fan of this, and would prefer if this just throws an error. My main objection is that the definition of isapprox(x, y) implies norm(x, y) > tol if !isapprox is true, which would no longer be the case here.

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 this pull request may close these issues.

3 participants