# Efficient Vector^T \* Jacobian matrix?

**URL:** <https://discourse.julialang.org/t/efficient-vector-t-jacobian-matrix/21329>\
**Category:** Numerics\
**Created:** [March 1, 2019, 5:42am UTC](https://discourse.julialang.org/t/efficient-vector-t-jacobian-matrix/21329 "2019-03-01T05:42:23Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [March 1, 2019, 6:50am UTC](https://discourse.julialang.org/t/efficient-vector-t-jacobian-matrix/21329/3 "2019-03-01T06:50:05Z")

</div>

I think you can use something like

```julia
function vjp(f::Function, x::AbstractVector, v::AbstractVector)
    g(y) = dot(v, f(y))
    ForwardDiff.gradient(g, x)
end

```

Though reverse mode autodiff would be much more efficient unless your vector `x` is short.

[Edit: Although it looks nice, I think this formulation amounts to computing the full Jacobian internally (possibly in batches when `x` is long… but nevertheless).]

---

_[View the full topic](https://discourse.julialang.org/t/efficient-vector-t-jacobian-matrix/21329)._
