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

getindex of range in IdentityMultiple #189

Open
schillic opened this issue Feb 23, 2020 · 0 comments
Open

getindex of range in IdentityMultiple #189

schillic opened this issue Feb 23, 2020 · 0 comments

Comments

@schillic
Copy link
Member

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant