From dda2e99d85f793b925b85da48df2251eed3e9f01 Mon Sep 17 00:00:00 2001 From: Facundo Sapienza Date: Mon, 18 Nov 2024 16:56:06 -0800 Subject: [PATCH 1/2] Pass order of derivative as Val() --- README.md | 4 ++-- docs/src/index.md | 4 ++-- examples/ode.jl | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 25fa2ae..73af9a4 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,9 @@ TaylorDiff.jl is fast! See our dedicated [benchmarks](https://benchmark.tansongc using TaylorDiff x = 0.1 -derivative(sin, x, 10) # scalar derivative +derivative(sin, x, Val(10)) # scalar derivative v, direction = [3.0, 4.0], [1.0, 0.0] -derivative(x -> sum(exp.(x)), v, direction, 2) # directional derivative +derivative(x -> sum(exp.(x)), v, direction, Val(2)) # directional derivative ``` Please see our [documentation](https://juliadiff.org/TaylorDiff.jl) for more details. diff --git a/docs/src/index.md b/docs/src/index.md index a1ea97c..891d2ba 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -31,9 +31,9 @@ TaylorDiff.jl is fast! See our dedicated [benchmarks](https://benchmark.tansongc using TaylorDiff x = 0.1 -derivative(sin, x, 10) # scalar derivative +derivative(sin, x, Val(10)) # scalar derivative v, direction = [3.0, 4.0], [1.0, 0.0] -derivative(x -> sum(exp.(x)), v, direction, 2) # directional derivative +derivative(x -> sum(exp.(x)), v, direction, Val(2)) # directional derivative ``` Please see our [documentation](https://juliadiff.org/TaylorDiff.jl) for more details. diff --git a/examples/ode.jl b/examples/ode.jl index 86ca42e..5ad2240 100644 --- a/examples/ode.jl +++ b/examples/ode.jl @@ -37,7 +37,7 @@ display(different_time(ic, p_true, 2e-5)) display(just_t(0.5)) #display(ForwardDiff.derivative(just_t,1.0)) -display(TaylorDiff.derivative(just_t, 1.0, 1)) #isnan error +display(TaylorDiff.derivative(just_t, 1.0, Val(1))) #isnan error #display(value_and_gradient(just_t, AutoForwardDiff(), 1.0)) #display(value_and_gradient(just_t, AutoReverseDiff(), 1.0)) #display(value_and_gradient(just_t, AutoEnzyme(Enzyme.Reverse), 1.0)) From f172fac4e188b52098dbcf3f46de90c806cb132c Mon Sep 17 00:00:00 2001 From: Facundo Sapienza Date: Fri, 22 Nov 2024 13:30:34 -0800 Subject: [PATCH 2/2] Add trivial tests for binary operations involving two TaylorScalar --- test/primitive.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/primitive.jl b/test/primitive.jl index a0571b0..e00801a 100644 --- a/test/primitive.jl +++ b/test/primitive.jl @@ -50,6 +50,12 @@ end # end end +@testset "Multi-argument functions" begin + @test derivative(x -> 1 + 1/x, 1.0, Val(1))≈-1.0 rtol=1e-6 + @test derivative(x -> (x+1)/x, 1.0, Val(1))≈-1.0 rtol=1e-6 + @test derivative(x -> x/x, 1.0, Val(1))≈ 0.0 rtol=1e-6 +end + @testset "Corner cases" begin offenders = ( TaylorScalar(Inf, (1.0, 0.0, 0.0)),