You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working with LinearAlgebra.diagind(::Diagonal, ::IndexCartesian) I bumped into the following error:
using LinearAlgebra
d =Diagonal(rand(3));
r =diagind(d, IndexCartesian()) # StepRangeLen(CartesianIndex(1, 1), CartesianIndex(1, 1), 3)CartesianIndex(1,1) indiagind(d, IndexCartesian()) # errors
produces (both on 1.11.2 and nightly)
ERROR: MethodError: no method matching /(::CartesianIndex{2}, ::CartesianIndex{2})
The function`/` exists, but no method is defined for this combination of argument types.
Closest candidates are:/(::BigInt, ::BigInt)
@ Base gmp.jl:517/(::BigInt, ::Union{Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8})
@ Base gmp.jl:566/(::ComplexF64, ::ComplexF64)
@ Base complex.jl:397...
Stacktrace:
[1] _in_range
@ ./range.jl:1434 [inlined]
[2] in(x::CartesianIndex{2}, r::StepRangeLen{CartesianIndex{2}, CartesianIndex{2}, CartesianIndex{2}, Int64})
@ Base ./range.jl:1440
I can fix this in a similar way to base by adding a specialized function:
function_in_range(x::CartesianIndex{N}, r::AbstractRange{CartesianIndex{N}}) where {N}
isempty(r) &&returnfalsefor i in1:N
f, l =first(r)[i], last(r)[i]
# check for NaN, Inf, and large x that may overflow in the next calculation
f <= x[i] <= l || l <= x[i] <= f ||returnfalseend
i =findfirst(!iszero, step(r).I)
isnothing(i) &&returntrue
n =round(Integer, (x[i] -first(r)[i]) /step(r)[i]) +1return n ≥1&& n ≤length(r) && r[n] == x
end
but I wanted to check first if this is the preferred way to do this (and where that function should go)
The text was updated successfully, but these errors were encountered:
When working with
LinearAlgebra.diagind(::Diagonal, ::IndexCartesian)
I bumped into the following error:produces (both on 1.11.2 and nightly)
I can fix this in a similar way to base by adding a specialized function:
but I wanted to check first if this is the preferred way to do this (and where that function should go)
The text was updated successfully, but these errors were encountered: