Skip to content

Commit faef826

Browse files
committed
Simply rand_tangent(::AbstractArray)
1 parent b892def commit faef826

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ChainRulesTestUtils"
22
uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a"
3-
version = "1.2.3"
3+
version = "1.3.0"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
@@ -11,7 +11,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1111
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1212

1313
[compat]
14-
ChainRulesCore = "1"
14+
ChainRulesCore = "1.2"
1515
Compat = "3"
1616
FiniteDifferences = "0.12.12"
1717
julia = "1"

src/rand_tangent.jl

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,7 @@ end
2222
# multiply by 9 to give a bigger range of values tested: no so tightly clustered around 0.
2323
rand_tangent(rng::AbstractRNG, ::BigFloat) = round(big(9 * randn(rng)), digits=5, base=2)
2424

25-
rand_tangent(rng::AbstractRNG, x::Array{<:Any, 0}) = _compress_notangent(fill(rand_tangent(rng, x[])))
26-
rand_tangent(rng::AbstractRNG, x::Array) = _compress_notangent(rand_tangent.(Ref(rng), x))
27-
28-
# All other AbstractArray's can be handled using the ProjectTo mechanics.
29-
# and follow the same requirements
30-
function rand_tangent(rng::AbstractRNG, x::AbstractArray)
31-
return _compress_notangent(ProjectTo(x)(rand_tangent(rng, collect(x))))
32-
end
33-
34-
# TODO: arguably ProjectTo should handle this for us for AbstactArrays
35-
# https://github.com/JuliaDiff/ChainRulesCore.jl/issues/410
36-
_compress_notangent(::AbstractArray{NoTangent}) = NoTangent()
37-
_compress_notangent(x) = x
25+
rand_tangent(rng::AbstractRNG, x::AbstractArray) = ProjectTo(x)(rand_tangent.(Ref(rng), x))
3826

3927
function rand_tangent(rng::AbstractRNG, x::T) where {T}
4028
if !isstructtype(T)

0 commit comments

Comments
 (0)