Skip to content

Commit

Permalink
allow getindex to have several indices
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Oct 15, 2021
1 parent e67f2b0 commit 36e561c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/tangent_types/abstract_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ Base.convert(::Type{T}, x::AbstractZero) where {T<:Number} = zero(T)
(::Type{Complex})(x::AbstractZero, y::Real) = Complex(false, y)
(::Type{Complex})(x::Real, y::AbstractZero) = Complex(x, false)

Base.getindex(z::AbstractZero, k) = z

Base.getindex(z::AbstractZero, ind...) = z
Base.view(z::AbstractZero, ind...) = z
Base.sum(z::AbstractZero; dims=:) = z

Expand Down
3 changes: 3 additions & 0 deletions test/tangent_types/abstract_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
end

@testset "Linear operators" begin
@test getindex(ZeroTangent(), 1) === ZeroTangent()
@test getindex(NoTangent(), 1, 2) === NoTangent()

@test view(ZeroTangent(), 1) == ZeroTangent()
@test view(NoTangent(), 1, 2) == NoTangent()

Expand Down

0 comments on commit 36e561c

Please sign in to comment.