add docstring and update README
This commit is contained in:
parent
50b68996fc
commit
8ab3338517
2 changed files with 32 additions and 0 deletions
17
README.md
17
README.md
|
|
@ -1,3 +1,20 @@
|
||||||
# TaylorTest
|
# TaylorTest
|
||||||
|
|
||||||
Simple package to check derivatives
|
Simple package to check derivatives
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
```
|
||||||
|
check(f, Jf, x[, constant_components]; f_kwargs...)
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns true if `Jf` approximates the derivative/gradient/Jacobian of `f` at point `x` (along a random direction).
|
||||||
|
`f_kwargs` are keywords arguments to be passed to `f` and `Jf`.
|
||||||
|
`constant_components` is an optional `Vector{Int}` corresponding to components of the direction which should be set to zero,
|
||||||
|
effectively ignoring the dependency of `f` on these components.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
```julia-repl
|
||||||
|
julia> f = x -> cos(x); Jf = x -> -sin(x); check(f, Jf, rand())
|
||||||
|
true
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,21 @@ module TaylorTest
|
||||||
import LinearAlgebra: norm, dot
|
import LinearAlgebra: norm, dot
|
||||||
import TensorOperations: @tensor
|
import TensorOperations: @tensor
|
||||||
|
|
||||||
|
"""
|
||||||
|
check(f, Jf, x[, constant_components]; f_kwargs...)
|
||||||
|
|
||||||
|
Returns true if `Jf` approximates the derivative/gradient/Jacobian of `f` at point `x` (along a random direction).
|
||||||
|
`f_kwargs` are keywords arguments to be passed to `f` and `Jf`.
|
||||||
|
`constant_components` is an optional `Vector{Int}` corresponding to components of the direction which should be set to zero,
|
||||||
|
effectively ignoring the dependency of `f` on these components.
|
||||||
|
|
||||||
|
# Examples
|
||||||
|
```julia-repl
|
||||||
|
julia> f = x -> cos(x); Jf = x -> -sin(x); check(f, Jf, rand())
|
||||||
|
true
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
|
||||||
function check(f, Jf, x, constant_components::Vector{Int}=Int[]; f_kwargs...)
|
function check(f, Jf, x, constant_components::Vector{Int}=Int[]; f_kwargs...)
|
||||||
direction = 2 * (rand(size(x)...) .- 0.5)
|
direction = 2 * (rand(size(x)...) .- 0.5)
|
||||||
for cst in constant_components
|
for cst in constant_components
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue