From a2d41408e17ae77c11cf81e7f93bf49c3d9c20ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Wed, 9 Aug 2023 00:40:21 -0400 Subject: [PATCH 1/6] add measurements to test --- Project.toml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index f7c66517..d4a0cfc9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ForwardDiff" uuid = "f6369f11-7733-5829-9624-2563aa707210" -version = "0.10.36" +version = "0.10.37" [deps] CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950" @@ -35,12 +35,13 @@ ForwardDiffStaticArraysExt = "StaticArrays" Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9" DiffTests = "de460e47-3fe3-5279-bb4a-814414816d5d" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Calculus", "DiffTests", "SparseArrays", "Test", "InteractiveUtils", "StaticArrays"] +test = ["Calculus", "DiffTests", "SparseArrays", "Test", "InteractiveUtils", "StaticArrays", "Measurements"] [weakdeps] -StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" \ No newline at end of file +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" From d7fae6958a44498ba4793bdaf2e5fff561447227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Wed, 9 Aug 2023 00:41:16 -0400 Subject: [PATCH 2/6] `one(T)` -> `oneunit(T)` --- src/partials.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/partials.jl b/src/partials.jl index fce67b0a..951e3f07 100644 --- a/src/partials.jl +++ b/src/partials.jl @@ -7,7 +7,7 @@ end ############################## @generated function single_seed(::Type{Partials{N,V}}, ::Val{i}) where {N,V,i} - ex = Expr(:tuple, [ifelse(i === j, :(one(V)), :(zero(V))) for j in 1:N]...) + ex = Expr(:tuple, [ifelse(i === j, :(oneunit(V)), :(zero(V))) for j in 1:N]...) return :(Partials($(ex))) end From 1fbd4c75933137a492bddf269c6c530e5cf9d5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Wed, 9 Aug 2023 00:42:17 -0400 Subject: [PATCH 3/6] add test with Measurements.jl --- test/MiscTest.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/MiscTest.jl b/test/MiscTest.jl index 2a22cb2f..d36968da 100644 --- a/test/MiscTest.jl +++ b/test/MiscTest.jl @@ -6,6 +6,7 @@ using Test using ForwardDiff using DiffTests using SparseArrays: sparse +using Measurements: Measurements include(joinpath(dirname(@__FILE__), "utils.jl")) @@ -158,4 +159,8 @@ end @test ForwardDiff.derivative(x -> rem2pi(x, RoundUp), rand()) == 1 @test ForwardDiff.derivative(x -> rem2pi(x, RoundDown), rand()) == 1 +#issue 651, using Measurements +f651(x) = 2.1*x + 1 +@test ForwardDiff.derivative(f651,Measurements.measurement(1.0, 0.001)) == 2.1 + end # module From f3b976e65ba5206f8f2ca5f79ff662311ed36c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Wed, 9 Aug 2023 01:18:58 -0400 Subject: [PATCH 4/6] add `oneunit(x::Dual)` --- src/dual.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dual.jl b/src/dual.jl index 5afb2144..21d470ba 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -360,6 +360,9 @@ end @inline Base.one(d::Dual) = one(typeof(d)) @inline Base.one(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(one(V), zero(Partials{N,V})) +@inline Base.oneunit(d::Dual) = oneunit(typeof(d)) +@inline Base.oneunit(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(oneunit(V), zero(Partials{N,V})) + @inline function Base.Int(d::Dual) all(iszero, partials(d)) || throw(InexactError(:Int, Int, d)) Int(value(d)) From 81c38910c5e43068b4bd3ff620defd3532c7b554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Wed, 9 Aug 2023 03:22:45 -0400 Subject: [PATCH 5/6] Update src/dual.jl Co-authored-by: David Widmann --- src/dual.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dual.jl b/src/dual.jl index 21d470ba..b7fd8e01 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -360,7 +360,7 @@ end @inline Base.one(d::Dual) = one(typeof(d)) @inline Base.one(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(one(V), zero(Partials{N,V})) -@inline Base.oneunit(d::Dual) = oneunit(typeof(d)) +@inline Base.oneunit(d::Dual{T}) where {T} = Dual{T}(oneunit(primal(d)), zero(partials(d))) @inline Base.oneunit(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(oneunit(V), zero(Partials{N,V})) @inline function Base.Int(d::Dual) From a897f71da14e5f9e8f2d0de530c7729a3b2df385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:22:57 -0400 Subject: [PATCH 6/6] primal -> value --- src/dual.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dual.jl b/src/dual.jl index b7fd8e01..06c3ed6d 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -360,7 +360,7 @@ end @inline Base.one(d::Dual) = one(typeof(d)) @inline Base.one(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(one(V), zero(Partials{N,V})) -@inline Base.oneunit(d::Dual{T}) where {T} = Dual{T}(oneunit(primal(d)), zero(partials(d))) +@inline Base.oneunit(d::Dual{T}) where {T} = Dual{T}(oneunit(value(d)), zero(partials(d))) @inline Base.oneunit(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(oneunit(V), zero(Partials{N,V})) @inline function Base.Int(d::Dual)