Skip to content

Commit 1bdc82c

Browse files
authored
Merge pull request #194 from JuliaDiff/mz/datatype
Implement `to_vec` for `DataType`s
2 parents 5b7d8f1 + 2182591 commit 1bdc82c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
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.18"
3+
version = "0.12.19"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/to_vec.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ function to_vec(d::Dict)
235235
return d_vec, Dict_from_vec
236236
end
237237

238+
# types
239+
function FiniteDifferences.to_vec(x::DataType)
240+
function DataType_from_vec(x_vec::Vector)
241+
return x
242+
end
243+
return Bool[], DataType_from_vec
244+
end
238245

239246
# ChainRulesCore Differentials
240247
function FiniteDifferences.to_vec(x::Tangent{P}) where{P}

test/to_vec.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ end
195195
end
196196
end
197197

198+
@testset "DataType" begin
199+
test_to_vec(Float64; check_inferred=false) # isa DataType
200+
test_to_vec(Vector; check_inferred=false) # isa UnionAll
201+
end
202+
198203
@testset "ChainRulesCore Differentials" begin
199204
@testset "Tangent{Tuple}" begin
200205
@testset "basic" begin

0 commit comments

Comments
 (0)