Skip to content

Commit d3ac3c4

Browse files
authored
Replace NO_FIELDS by NoTangent() (#163)
1 parent 8dff2c1 commit d3ac3c4

3 files changed

Lines changed: 10 additions & 14 deletions

File tree

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FiniteDifferences"
22
uuid = "26cc04aa-876d-5657-8c51-4c34ba976000"
3-
version = "0.12.9"
3+
version = "0.12.10"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
@@ -11,7 +11,7 @@ Richardson = "708f8203-808e-40c0-ba2d-98a6953ed40d"
1111
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1212

1313
[compat]
14-
ChainRulesCore = "0.9.44"
14+
ChainRulesCore = "0.9.44, 0.10"
1515
Richardson = "1.2"
1616
StaticArrays = "0.12, 1.0"
1717
julia = "1"

src/rand_tangent.jl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,13 @@ function rand_tangent(rng::AbstractRNG, x::T) where {T}
3535
end
3636

3737
field_names = fieldnames(T)
38-
if length(field_names) > 0
39-
tangents = map(field_names) do field_name
40-
rand_tangent(rng, getfield(x, field_name))
41-
end
42-
if all(tangent isa NoTangent for tangent in tangents)
43-
# if none of my fields can be perturbed then I can't be perturbed
44-
return NoTangent()
45-
else
46-
Tangent{T}(; NamedTuple{field_names}(tangents)...)
47-
end
38+
tangents = map(field_names) do field_name
39+
rand_tangent(rng, getfield(x, field_name))
40+
end
41+
if all(tangent isa NoTangent for tangent in tangents)
42+
# if none of my fields can be perturbed then I can't be perturbed
43+
return NoTangent()
4844
else
49-
return NO_FIELDS
45+
Tangent{T}(; NamedTuple{field_names}(tangents)...)
5046
end
5147
end

test/rand_tangent.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ using FiniteDifferences: rand_tangent
4040
# structs.
4141
(Foo(5.0, 4, rand(rng, 3)), Tangent{Foo}),
4242
(Foo(4.0, 3, Foo(5.0, 2, 4)), Tangent{Foo}),
43-
(sin, typeof(NO_FIELDS)),
43+
(sin, NoTangent),
4444
# all fields NoTangent implies NoTangent
4545
(Pair(:a, "b"), NoTangent),
4646
(1:10, NoTangent),

0 commit comments

Comments
 (0)