Skip to content

Commit bac36f9

Browse files
committed
IdentityMultiple: restrict getindex to Integer
1 parent c1b8b06 commit bac36f9

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/identity.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ end
7676
Base.IndexStyle(::Type{<:IdentityMultiple}) = IndexLinear()
7777
Base.size(𝐼::IdentityMultiple) = (𝐼.n, 𝐼.n)
7878

79-
function Base.getindex(𝐼::IdentityMultiple, inds...)
79+
function Base.getindex(𝐼::IdentityMultiple, inds::Integer...)
8080
any(idx -> idx > 𝐼.n, inds) && throw(BoundsError(𝐼, inds))
8181
return getindex(𝐼.M, inds...)
8282
end
8383

84-
function Base.getindex(𝐼::IdentityMultiple{T}, ind) where {T}
84+
function Base.getindex(𝐼::IdentityMultiple{T}, ind::Integer) where {T}
8585
if 1 ind 𝐼.n^2
8686
return rem(ind - 1, 𝐼.n + 1) == 0 ? 𝐼.M.λ : zero(T)
8787
else

test/identity.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ end
7676
end
7777

7878
@testset "Specific methods for IdentityMultiple" begin
79+
@test Diagonal(Id(2)) == Diagonal([1.0, 1])
7980
@test Hermitian(Id(2)) == Hermitian([1.0 0; 0 1])
8081
@test exp(Id(3, 1)) == Id(3, exp(1))
8182
end

0 commit comments

Comments
 (0)