Skip to content

Commit 266d6fa

Browse files
mzgubicoxinabox
andauthored
rename differentials (#162)
* ignore dev * bump version, compat * rename DoesNotExist * rename Composite to Tangent * rename Zero to ZeroTangent * update docs * docs manifest * Update docs/Project.toml Co-authored-by: Lyndon White <oxinabox@ucc.asn.au> Co-authored-by: Lyndon White <oxinabox@ucc.asn.au>
1 parent b96f892 commit 266d6fa

8 files changed

Lines changed: 137 additions & 75 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.jl.*.cov
33
*.jl.mem
44
/Manifest.toml
5+
dev/
56

67
# Docs:
78
docs/build/

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.6"
3+
version = "0.12.7"
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"
14+
ChainRulesCore = "0.9.44"
1515
Richardson = "1.2"
1616
StaticArrays = "0.12, 1.0"
1717
julia = "1"

docs/Manifest.toml

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,59 @@
11
# This file is machine-generated - editing it directly is not advised
22

3+
[[ArgTools]]
4+
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
5+
6+
[[Artifacts]]
7+
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
8+
39
[[Base64]]
410
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
511

612
[[ChainRulesCore]]
7-
deps = ["LinearAlgebra", "MuladdMacro", "SparseArrays"]
8-
git-tree-sha1 = "15081c431bb25848ad9b0d172a65794f3a3e197a"
13+
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
14+
git-tree-sha1 = "b391f22252b8754f4440de1f37ece49d8a7314bb"
915
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
10-
version = "0.9.24"
16+
version = "0.9.44"
17+
18+
[[Compat]]
19+
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
20+
git-tree-sha1 = "e4e2b39db08f967cc1360951f01e8a75ec441cab"
21+
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
22+
version = "3.30.0"
1123

1224
[[Dates]]
1325
deps = ["Printf"]
1426
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
1527

28+
[[DelimitedFiles]]
29+
deps = ["Mmap"]
30+
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
31+
1632
[[Distributed]]
1733
deps = ["Random", "Serialization", "Sockets"]
1834
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1935

2036
[[DocStringExtensions]]
2137
deps = ["LibGit2", "Markdown", "Pkg", "Test"]
22-
git-tree-sha1 = "50ddf44c53698f5e784bbebb3f4b21c5807401b1"
38+
git-tree-sha1 = "9d4f64f79012636741cf01133158a54b24924c32"
2339
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
24-
version = "0.8.3"
40+
version = "0.8.4"
2541

2642
[[Documenter]]
2743
deps = ["Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
2844
git-tree-sha1 = "a4875e0763112d6d017126f3944f4133abb342ae"
2945
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3046
version = "0.25.5"
3147

48+
[[Downloads]]
49+
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
50+
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
51+
3252
[[FiniteDifferences]]
3353
deps = ["ChainRulesCore", "LinearAlgebra", "Printf", "Random", "Richardson", "StaticArrays"]
3454
path = ".."
3555
uuid = "26cc04aa-876d-5657-8c51-4c34ba976000"
36-
version = "0.11.5"
56+
version = "0.12.7"
3757

3858
[[IOCapture]]
3959
deps = ["Logging"]
@@ -51,10 +71,22 @@ git-tree-sha1 = "81690084b6198a2e1da36fcfda16eeca9f9f24e4"
5171
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
5272
version = "0.21.1"
5373

74+
[[LibCURL]]
75+
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
76+
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
77+
78+
[[LibCURL_jll]]
79+
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
80+
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
81+
5482
[[LibGit2]]
55-
deps = ["Printf"]
83+
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
5684
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
5785

86+
[[LibSSH2_jll]]
87+
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
88+
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
89+
5890
[[Libdl]]
5991
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
6092

@@ -69,30 +101,35 @@ uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
69101
deps = ["Base64"]
70102
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
71103

104+
[[MbedTLS_jll]]
105+
deps = ["Artifacts", "Libdl"]
106+
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
107+
72108
[[Mmap]]
73109
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
74110

75-
[[MuladdMacro]]
76-
git-tree-sha1 = "c6190f9a7fc5d9d5915ab29f2134421b12d24a68"
77-
uuid = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
78-
version = "0.2.2"
111+
[[MozillaCACerts_jll]]
112+
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
113+
114+
[[NetworkOptions]]
115+
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
79116

80117
[[Parsers]]
81118
deps = ["Dates"]
82-
git-tree-sha1 = "50c9a9ed8c714945e01cd53a21007ed3865ed714"
119+
git-tree-sha1 = "c8abc88faa3f7a3950832ac5d6e690881590d6dc"
83120
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
84-
version = "1.0.15"
121+
version = "1.1.0"
85122

86123
[[Pkg]]
87-
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
124+
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
88125
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
89126

90127
[[Printf]]
91128
deps = ["Unicode"]
92129
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
93130

94131
[[REPL]]
95-
deps = ["InteractiveUtils", "Markdown", "Sockets"]
132+
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
96133
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
97134

98135
[[Random]]
@@ -111,6 +148,10 @@ uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
111148
[[Serialization]]
112149
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
113150

151+
[[SharedArrays]]
152+
deps = ["Distributed", "Mmap", "Random", "Serialization"]
153+
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
154+
114155
[[Sockets]]
115156
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
116157

@@ -120,16 +161,24 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
120161

121162
[[StaticArrays]]
122163
deps = ["LinearAlgebra", "Random", "Statistics"]
123-
git-tree-sha1 = "9da72ed50e94dbff92036da395275ed114e04d49"
164+
git-tree-sha1 = "c635017268fd51ed944ec429bcc4ad010bcea900"
124165
uuid = "90137ffa-7385-5640-81b9-e52037218182"
125-
version = "1.0.1"
166+
version = "1.2.0"
126167

127168
[[Statistics]]
128169
deps = ["LinearAlgebra", "SparseArrays"]
129170
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
130171

172+
[[TOML]]
173+
deps = ["Dates"]
174+
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
175+
176+
[[Tar]]
177+
deps = ["ArgTools", "SHA"]
178+
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
179+
131180
[[Test]]
132-
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
181+
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
133182
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
134183

135184
[[UUIDs]]
@@ -138,3 +187,15 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
138187

139188
[[Unicode]]
140189
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
190+
191+
[[Zlib_jll]]
192+
deps = ["Libdl"]
193+
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
194+
195+
[[nghttp2_jll]]
196+
deps = ["Artifacts", "Libdl"]
197+
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
198+
199+
[[p7zip_jll]]
200+
deps = ["Artifacts", "Libdl"]
201+
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"

src/difference.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ If `(y - x) / ε` is defined, then this operation is equivalent to doing that. F
1111
where these operations aren't defined, `difference` can still be defined without commiting
1212
type piracy while `-` and `/` cannot.
1313
"""
14-
difference(::Real, ::T, ::T) where {T<:Symbol} = DoesNotExist()
15-
difference(::Real, ::T, ::T) where {T<:AbstractChar} = DoesNotExist()
16-
difference(::Real, ::T, ::T) where {T<:AbstractString} = DoesNotExist()
17-
difference(::Real, ::T, ::T) where {T<:Integer} = DoesNotExist()
14+
difference(::Real, ::T, ::T) where {T<:Symbol} = NoTangent()
15+
difference(::Real, ::T, ::T) where {T<:AbstractChar} = NoTangent()
16+
difference(::Real, ::T, ::T) where {T<:AbstractString} = NoTangent()
17+
difference(::Real, ::T, ::T) where {T<:Integer} = NoTangent()
1818

1919
difference::Real, y::T, x::T) where {T<:Number} = (y - x) / ε
2020

2121
difference::Real, y::T, x::T) where {T<:StridedArray} = difference.(ε, y, x)
2222

2323
function difference::Real, y::T, x::T) where {T<:Tuple}
24-
return Composite{T}(difference.(ε, y, x)...)
24+
return Tangent{T}(difference.(ε, y, x)...)
2525
end
2626

2727
function difference::Real, ys::T, xs::T) where {T<:NamedTuple}
28-
return Composite{T}(; map((y, x) -> difference(ε, y, x), ys, xs)...)
28+
return Tangent{T}(; map((y, x) -> difference(ε, y, x), ys, xs)...)
2929
end
3030

3131
function difference::Real, y::T, x::T) where {T}
@@ -38,7 +38,7 @@ function difference(ε::Real, y::T, x::T) where {T}
3838
tangents = map(field_names) do field_name
3939
difference(ε, getfield(y, field_name), getfield(x, field_name))
4040
end
41-
return Composite{T}(; NamedTuple{field_names}(tangents)...)
41+
return Tangent{T}(; NamedTuple{field_names}(tangents)...)
4242
else
4343
return NO_FIELDS
4444
end

src/rand_tangent.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ Returns a randomly generated tangent vector appropriate for the primal value `x`
55
"""
66
rand_tangent(x) = rand_tangent(Random.GLOBAL_RNG, x)
77

8-
rand_tangent(rng::AbstractRNG, x::Symbol) = DoesNotExist()
9-
rand_tangent(rng::AbstractRNG, x::AbstractChar) = DoesNotExist()
10-
rand_tangent(rng::AbstractRNG, x::AbstractString) = DoesNotExist()
8+
rand_tangent(rng::AbstractRNG, x::Symbol) = NoTangent()
9+
rand_tangent(rng::AbstractRNG, x::AbstractChar) = NoTangent()
10+
rand_tangent(rng::AbstractRNG, x::AbstractString) = NoTangent()
1111

12-
rand_tangent(rng::AbstractRNG, x::Integer) = DoesNotExist()
12+
rand_tangent(rng::AbstractRNG, x::Integer) = NoTangent()
1313

1414
rand_tangent(rng::AbstractRNG, x::T) where {T<:Number} = randn(rng, T)
1515

@@ -20,11 +20,11 @@ rand_tangent(rng::AbstractRNG, ::BigFloat) = big(randn(rng))
2020
rand_tangent(rng::AbstractRNG, x::StridedArray) = rand_tangent.(Ref(rng), x)
2121

2222
function rand_tangent(rng::AbstractRNG, x::T) where {T<:Tuple}
23-
return Composite{T}(rand_tangent.(Ref(rng), x)...)
23+
return Tangent{T}(rand_tangent.(Ref(rng), x)...)
2424
end
2525

2626
function rand_tangent(rng::AbstractRNG, xs::T) where {T<:NamedTuple}
27-
return Composite{T}(; map(x -> rand_tangent(rng, x), xs)...)
27+
return Tangent{T}(; map(x -> rand_tangent(rng, x), xs)...)
2828
end
2929

3030
function rand_tangent(rng::AbstractRNG, x::T) where {T}
@@ -37,11 +37,11 @@ function rand_tangent(rng::AbstractRNG, x::T) where {T}
3737
tangents = map(field_names) do field_name
3838
rand_tangent(rng, getfield(x, field_name))
3939
end
40-
if all(tangent isa DoesNotExist for tangent in tangents)
40+
if all(tangent isa NoTangent for tangent in tangents)
4141
# if none of my fields can be perturbed then I can't be perturbed
42-
return DoesNotExist()
42+
return NoTangent()
4343
else
44-
Composite{T}(; NamedTuple{field_names}(tangents)...)
44+
Tangent{T}(; NamedTuple{field_names}(tangents)...)
4545
end
4646
else
4747
return NO_FIELDS

src/to_vec.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ end
176176

177177

178178
# ChainRulesCore Differentials
179-
function FiniteDifferences.to_vec(x::Composite{P}) where{P}
179+
function FiniteDifferences.to_vec(x::Tangent{P}) where{P}
180180
x_canon = canonicalize(x) # to be safe, fill in every field and put in primal order.
181181
x_inner = ChainRulesCore.backing(x_canon)
182182
x_vec, back_inner = FiniteDifferences.to_vec(x_inner)
183-
function Composite_from_vec(y_vec)
183+
function Tangent_from_vec(y_vec)
184184
y_back = back_inner(y_vec)
185-
return Composite{P, typeof(y_back)}(y_back)
185+
return Tangent{P, typeof(y_back)}(y_back)
186186
end
187-
return x_vec, Composite_from_vec
187+
return x_vec, Tangent_from_vec
188188
end
189189

190190
function FiniteDifferences.to_vec(x::AbstractZero)

0 commit comments

Comments
 (0)