Skip to content

Commit a370b9b

Browse files
authored
Merge pull request #230 from JuliaDiff/ox/relax
Relax type constraints to permit AbstractVectors
2 parents 99ad77f + 252d17b commit a370b9b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/grad.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Approximate the Jacobian of `f` at `x` using `fdm`. Results will be returned as
66
version of `x`, and `y_vec` the flattened version of `f(x...)`. Flattening performed by
77
[`to_vec`](@ref).
88
"""
9-
function jacobian(fdm, f, x::Vector{<:Real}; len=nothing)
9+
function jacobian(fdm, f, x::AbstractVector{<:Real}; len=nothing)
1010
len !== nothing && Base.depwarn(
1111
"`len` keyword argument to `jacobian` is no longer required " *
1212
"and will not be permitted in the future.",
@@ -40,11 +40,11 @@ end
4040
replace_arg(x, xs::Tuple, k::Int) = ntuple(p -> p == k ? x : xs[p], length(xs))
4141

4242
"""
43-
_jvp(fdm, f, x::Vector{<:Real}, ẋ::AbstractVector{<:Real})
43+
_jvp(fdm, f, x::AbstractVector{<:Real}, ẋ::AbstractVector{<:Real})
4444
4545
Convenience function to compute `jacobian(f, x) * ẋ`.
4646
"""
47-
function _jvp(fdm, f, x::Vector{<:Real}, ẋ::Vector{<:Real})
47+
function _jvp(fdm, f, x::AbstractVector{<:Real}, ẋ::AbstractVector{<:Real})
4848
return fdm-> f(x .+ ε .* ẋ), zero(eltype(x)))
4949
end
5050

@@ -79,7 +79,7 @@ end
7979

8080
j′vp(fdm, f, ȳ, xs...) = j′vp(fdm, xs->f(xs...), ȳ, xs)[1]
8181

82-
function _j′vp(fdm, f, ȳ::Vector{<:Real}, x::Vector{<:Real})
82+
function _j′vp(fdm, f, ȳ::AbstractVector{<:Real}, x::AbstractVector{<:Real})
8383
isempty(x) && return eltype(ȳ)[] # if x is empty, then so is the jacobian and x̄
8484
return transpose(first(jacobian(fdm, f, x))) *
8585
end

0 commit comments

Comments
 (0)