Skip to content

Commit 89133ec

Browse files
committed
=Make rand_tangent on adjoint an transpose return natural
1 parent ebff52d commit 89133ec

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/rand_tangent.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ rand_tangent(rng::AbstractRNG, x::Integer) = NoTangent()
1313

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

16-
# TODO: right now Julia don't allow `randn(rng, BigFloat)`
16+
# TODO: right now Julia don't allow `randn(rng, BigFloat)`
1717
# see: https://github.com/JuliaLang/julia/issues/17629
1818
rand_tangent(rng::AbstractRNG, ::BigFloat) = big(randn(rng))
1919

2020
rand_tangent(rng::AbstractRNG, x::StridedArray) = rand_tangent.(Ref(rng), x)
21+
rand_tangent(rng::AbstractRNG, x::Adjoint) = adjoint(rand_tangent(rng, parent(x)))
22+
rand_tangent(rng::AbstractRNG, x::Tangent) = tangent(rand_tangent(rng, parent(x)))
2123

2224
function rand_tangent(rng::AbstractRNG, x::T) where {T<:Tuple}
2325
return Tangent{T}(rand_tangent.(Ref(rng), x)...)

test/rand_tangent.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ using FiniteDifferences: rand_tangent
2424
(randn(Complex{Float32}, 5, 4), Matrix{Complex{Float32}}),
2525
([randn(5, 4), 4.0], Vector{Any}),
2626

27+
# Wrapper Arrays
28+
(randn(5, 4)', Adjoint{Float64, Matrix{Float64}},
29+
(transpose(randn(5, 4)), Transpose{Float64, Matrix{Float64}},
30+
31+
2732
# Tuples.
2833
((4.0, ), Tangent{Tuple{Float64}}),
2934
((5.0, randn(3)), Tangent{Tuple{Float64, Vector{Float64}}}),

0 commit comments

Comments
 (0)