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

Define getproperty on AbstractZeroTangents #636

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRulesCore"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.16.0"
version = "1.17.0"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
2 changes: 2 additions & 0 deletions src/tangent_types/abstract_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Base.convert(::Type{T}, x::AbstractZero) where {T<:Number} = zero(T)
(::Type{Complex})(x::Real, y::AbstractZero) = Complex(x, false)

Base.getindex(z::AbstractZero, args...) = z
Base.getproperty(z::AbstractZero, name::Symbol) = z


Base.view(z::AbstractZero, ind...) = z
Base.sum(z::AbstractZero; dims=:) = z
Expand Down
4 changes: 4 additions & 0 deletions test/tangent_types/abstract_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
@test z[1:3] === z
@test z[1, 2] === z
@test getindex(z) === z

@test z.foo === z

@test first(z) === z
@test last(z) === z
Expand Down Expand Up @@ -134,6 +136,8 @@
@test dne[1:3] === dne
@test dne[1, 2] === dne
@test getindex(dne) === dne

oxinabox marked this conversation as resolved.
Show resolved Hide resolved
@test dne.foo === dne
end

@testset "ambiguities" begin
Expand Down
Loading