Skip to content

implement jacvec products #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 22, 2019
Merged

implement jacvec products #30

merged 8 commits into from
Jun 22, 2019

Conversation

ChrisRackauckas
Copy link
Member

No description provided.

@ChrisRackauckas
Copy link
Member Author

Includes two operators, one for JacVec and another for HesVec.

f(u) = sum(u.^2)
L = HesVec(f,x)
L*v # (d^2 f/ dx^2) * v

and is compatible with IterativeSolvers.jl for Newton-Krylov methods:

out = similar(v)
gmres!(out, L, v)

@pkofod

@ChrisRackauckas
Copy link
Member Author

using SparseDiffTools, BenchmarkTools
const A = rand(300,300)
f(u) = sum(abs2,u)
x = rand(300)
v = rand(300)
du = similar(x)
c1 = similar(x); c2 = similar(x); c3 = similar(x); c4 = similar(x)
cache1 = ForwardDiff.Dual{SparseDiffTools.DeivVecTag}.(x, v)
cache2 = ForwardDiff.Dual{SparseDiffTools.DeivVecTag}.(x, v)
config = ForwardDiff.GradientConfig(f,x)
@btime num_hesvec!($du, $f, $x, $v, $c1, $c3, $c4)
@btime numauto_hesvec!($du, $f, $x, $v, $config, $c1, $c2)
@btime autonum_hesvec!($du, $f, $x, $v, $c1, $cache1, $cache2)

shows

  49.863 μs (0 allocations: 0 bytes)
  26.216 μs (1 allocation: 16 bytes)
  198.425 μs (0 allocations: 0 bytes)

which ones to use :)

@pkofod
Copy link

pkofod commented Jun 22, 2019

Awesome. I’ll use this.

@pkofod
Copy link

pkofod commented Jun 22, 2019

Could there be a hessian one where the uset has the gradient function?

@ChrisRackauckas
Copy link
Member Author

HesVecGrad

@ChrisRackauckas ChrisRackauckas merged commit 0e6685d into master Jun 22, 2019
@ChrisRackauckas ChrisRackauckas deleted the jacvecs branch June 22, 2019 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants