Skip to content

Commit 09ae81d

Browse files
authored
Merge pull request #666 from JuliaDiff/ox/div
add scaling division
2 parents 2387dc1 + 3cfd06d commit 09ae81d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/tangent_types/abstract_tangent.jl

+3
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ abstract type AbstractTangent end
3838
Base.:+(x::AbstractTangent) = x
3939

4040
@inline Base.conj(x::AbstractTangent) = x
41+
42+
Base.:/(x::AbstractTangent, y) = x * inv(y)
43+
Base.:\(x, y::AbstractTangent) = inv(x) * y

test/tangent_types/structural_tangent.jl

+10
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,16 @@ end
396396
@test_throws MethodError Tangent{Foo}(; y=1.5, x=2.5) * @thunk [1 2; 3 4]
397397
end
398398

399+
@testset "scaling division" begin
400+
a = Tangent{Foo}(; x=2.0, y=-2.0)
401+
@test a / 2.0 == Tangent{Foo}(; x=1.0, y=-1.0) == 2.0 \ a
402+
@test (
403+
Tangent{Tuple{Float64,Float64}}(2.0, 4.0) / 2.0 ==
404+
Tangent{Tuple{Float64,Float64}}(1.0, 2.0) ==
405+
2.0 \ Tangent{Tuple{Float64,Float64}}(2.0, 4.0)
406+
)
407+
end
408+
399409
@testset "iszero" begin
400410
@test iszero(Tangent{Foo}())
401411
@test iszero(Tangent{Tuple{}}())

0 commit comments

Comments
 (0)