Skip to content

Commit 9afe916

Browse files
authored
use oneunit(T) in construct_seeds
1 parent 382363a commit 9afe916

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
4040
DiffTests = "de460e47-3fe3-5279-bb4a-814414816d5d"
4141
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
4242
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"
43+
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
4344
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
4445
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
4546
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4647

4748
[targets]
48-
test = ["Calculus", "DiffTests", "IrrationalConstants", "SparseArrays", "StaticArrays", "Test", "InteractiveUtils"]
49+
test = ["Calculus", "DiffTests", "IrrationalConstants", "Measurements", "SparseArrays", "StaticArrays", "Test", "InteractiveUtils"]

src/dual.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ end
359359
@inline Base.one(d::Dual) = one(typeof(d))
360360
@inline Base.one(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(one(V), zero(Partials{N,V}))
361361

362+
@inline Base.oneunit(d::Dual{T}) where {T} = Dual{T}(oneunit(value(d)), zero(partials(d)))
363+
@inline Base.oneunit(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(oneunit(V), zero(Partials{N,V}))
364+
362365
@inline function Base.Int(d::Dual)
363366
all(iszero, partials(d)) || throw(InexactError(:Int, Int, d))
364367
Int(value(d))

src/partials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ end
77
##############################
88

99
@generated function single_seed(::Type{Partials{N,V}}, ::Val{i}) where {N,V,i}
10-
ex = Expr(:tuple, [ifelse(i === j, :(one(V)), :(zero(V))) for j in 1:N]...)
10+
ex = Expr(:tuple, [ifelse(i === j, :(oneunit(V)), :(zero(V))) for j in 1:N]...)
1111
return :(Partials($(ex)))
1212
end
1313

test/MiscTest.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using SparseArrays: sparse
99
using StaticArrays
1010
using IrrationalConstants
1111
using LinearAlgebra
12+
using Measurements: Measurements
1213

1314
include(joinpath(dirname(@__FILE__), "utils.jl"))
1415

@@ -219,4 +220,8 @@ end
219220
@test B_mmatrix == B
220221
end
221222

223+
#issue 651, using Measurements
224+
f651(x) = 2.1*x + 1
225+
@test ForwardDiff.derivative(f651,Measurements.measurement(1.0, 0.001)) == 2.1
226+
222227
end # module

0 commit comments

Comments
 (0)