Skip to content

Commit

Permalink
Merge pull request #642 from lukas-weber/tangent-norm
Browse files Browse the repository at this point in the history
tangent_arithmetic: add `norm` for `NoTangent`, `ZeroTangent` and `NotImplemented`
  • Loading branch information
oxinabox authored Dec 18, 2023
2 parents cb1aa6b + e63f62b commit 86a3256
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/tangent_types/abstract_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Base.last(x::AbstractZero) = x
Base.Broadcast.broadcastable(x::AbstractZero) = Ref(x)
Base.Broadcast.broadcasted(::Type{T}) where {T<:AbstractZero} = T()

LinearAlgebra.norm(::AbstractZero) = 0

# Linear operators
Base.adjoint(z::AbstractZero) = z
Base.transpose(z::AbstractZero) = 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 @@ -120,6 +120,9 @@
@test dot(ZeroTangent(), dne) == ZeroTangent()
@test dot(dne, ZeroTangent()) == ZeroTangent()

@test norm(ZeroTangent()) == 0
@test norm(ZeroTangent(), 0.4) == 0

for x in dne
@test x === dne
end
Expand Down
4 changes: 4 additions & 0 deletions test/tangent_types/tangent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,15 @@ end
@test c * NoTangent() == NoTangent()
@test dot(NoTangent(), c) == NoTangent()
@test dot(c, NoTangent()) == NoTangent()
@test norm(Tangent{Foo}(; y=c.y, x=NoTangent())) == c.y
@test norm(NoTangent(), Inf) == 0

@test ZeroTangent() * c == ZeroTangent()
@test c * ZeroTangent() == ZeroTangent()
@test dot(ZeroTangent(), c) == ZeroTangent()
@test dot(c, ZeroTangent()) == ZeroTangent()
@test norm(ZeroTangent()) == 0
@test norm(ZeroTangent(), 0.4) == 0

@test true * c === c
@test c * true === c
Expand Down

0 comments on commit 86a3256

Please sign in to comment.