From 69ccf50d2e420af8f28612c52ba8f9ec62028eb3 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Wed, 9 Jun 2021 16:33:53 +0100 Subject: [PATCH] Revert "Revert "Add `rand_tangent` for types (#172)"" This reverts commit 65ab55c5feca11b0f33f668c958ed065c146bd47. --- Project.toml | 2 +- src/rand_tangent.jl | 3 +++ test/rand_tangent.jl | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 51354aa..cda4584 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "FiniteDifferences" uuid = "26cc04aa-876d-5657-8c51-4c34ba976000" -version = "0.12.11" +version = "0.12.12" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" diff --git a/src/rand_tangent.jl b/src/rand_tangent.jl index 930a3c7..96d4b6a 100644 --- a/src/rand_tangent.jl +++ b/src/rand_tangent.jl @@ -57,3 +57,6 @@ function rand_tangent(rng::AbstractRNG, x::T) where {T} Tangent{T}(; NamedTuple{field_names}(tangents)...) end end + +rand_tangent(rng::AbstractRNG, ::Type) = NoTangent() +rand_tangent(rng::AbstractRNG, ::Module) = NoTangent() diff --git a/test/rand_tangent.jl b/test/rand_tangent.jl index f5815e8..a7f861c 100644 --- a/test/rand_tangent.jl +++ b/test/rand_tangent.jl @@ -11,6 +11,15 @@ using FiniteDifferences: rand_tangent (:a, NoTangent), (true, NoTangent), (4, NoTangent), + (FiniteDifferences, NoTangent), # Module object + # Types (not instances of type) + (Foo, NoTangent), + (Union{Int, Foo}, NoTangent), + (Union{Int, Foo}, NoTangent), + (Vector, NoTangent), + (Vector{Float64}, NoTangent), + (Integer, NoTangent), + (Type{<:Real}, NoTangent), # Numbers. (5.0, Float64),