JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.91k stars 5.49k forks source link

Make `isapprox` error unless shapes match #56018

Open jariji opened 1 month ago

jariji commented 1 month ago

I don't like this and I would like it to error

julia> [1; 2; 3;;]
3×1 Matrix{Int64}:
 1
 2
 3
julia> [1; 2; 3;;] ≈ [1,2,3]
true

just like this does

julia> (x for x in 1:3) ≈ [1,2,3]
ERROR: MethodError: no method matching isapprox(::Base.Generator{UnitRange{Int64}, typeof(identity)}, ::Vector{Int64})
nsajko commented 1 month ago

Possible course of action: make a PR then request a PkgEval from NanoSoldier to see what will break.

nsajko commented 1 month ago

I would like it to error

Given that == returns false for array arguments of mismatched shape, perhaps [1; 2; 3;;] ≈ [1,2,3] should return false, too?

jariji commented 1 month ago

I think Matrix == Vector should error too. https://github.com/JuliaLang/julia/issues/40717

nsajko commented 1 month ago

Yeah, but that's definitely for a breaking release.

nsajko commented 1 month ago

Offending method:

https://github.com/JuliaLang/julia/blob/e516e4c63d383efb24613d27e6fab0ffffed5a88/stdlib/LinearAlgebra/src/generic.jl#L1877-L1892