Skip to content

Commit

Permalink
add scaling division
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Feb 20, 2024
1 parent 2387dc1 commit c299113
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tangent_types/abstract_tangent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ abstract type AbstractTangent end
Base.:+(x::AbstractTangent) = x

@inline Base.conj(x::AbstractTangent) = x

Base.:/(x::AbstractTangent, y) = x * inv(y)
Base.:\(x, y::AbstractTangent) = inv(x) * y
13 changes: 13 additions & 0 deletions test/tangent_types/structural_tangent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,19 @@ end
@test_throws MethodError Tangent{Foo}(; y=1.5, x=2.5) * @thunk [1 2; 3 4]
end

@testset "scaling division"
a = Tangent{Foo}(; x=2.0, y=-2.0)
@test a / 2.0 == Tangent{Foo}(; x=1.0, y=-1.0) == 2.0 \ a
@test (
Tangent{Tuple{Float64,Float64}}(2.0, 4.0) / 2.0 ==
Tangent{Tuple{Float64,Float64}}(1.0, 2.0) ==
2.0 \ Tangent{Tuple{Float64,Float64}}(2.0, 4.0)
)


end


@testset "iszero" begin
@test iszero(Tangent{Foo}())
@test iszero(Tangent{Tuple{}}())
Expand Down

0 comments on commit c299113

Please sign in to comment.