JuliaReach / MathematicalSystems.jl

Systems definitions in Julia

Home Page:https://juliareach.github.io/MathematicalSystems.jl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getindex of range in IdentityMultiple

schillic opened this issue · comments

The type of ind has to be restricted to Integer and another method for StepRange (or the supertype OrdinalRange or even that one's supertype AbstractRange) needs to be added.

function Base.getindex(𝐼::IdentityMultiple, inds...)
any(idx -> idx > 𝐼.n, inds) && throw(BoundsError(𝐼, inds))
getindex(𝐼.M, inds...)
end
function Base.getindex(𝐼::IdentityMultiple{T}, ind) where {T}
if 1 ind 𝐼.n^2
return rem(ind-1, 𝐼.n+1) == 0 ? 𝐼.M.λ : zero(T)
else
throw(BoundsError(𝐼, ind))
end
end

julia> I = IdentityMultiple(1.0, 2)
IdentityMultiple{Float64} of value 1.0 and order 2

julia> Diagonal(I)
ERROR: MethodError: no method matching isless(::Int64, ::StepRange{Int64,Int64})
Closest candidates are:
  isless(::Missing, ::Any) at missing.jl:66
  isless(::Real, ::AbstractFloat) at operators.jl:157
  isless(::Real, ::Real) at operators.jl:346
  ...
Stacktrace:
 [1] <(::Int64, ::StepRange{Int64,Int64}) at ./operators.jl:268
 [2] <=(::Int64, ::StepRange{Int64,Int64}) at ./operators.jl:317
 [3] getindex(::IdentityMultiple{Float64}, ::StepRange{Int64,Int64}) at .julia/dev/MathematicalSystems/src/identity.jl:93