# DerivableFunctionsBase

This is the documentation for DerivableFunctionsBase.jl.

This package provides the base functionality of DerivableFunctions.jl without loading all the backends, i.e. only for ForwardDiff.jl.

For in-depth examples and explanations, please see the Documentation of main package DerivableFunctions.jl.

DerivableFunctionsBase.DerivableFunctionType
DerivableFunction(F::Function; ADmode::Union{Val,Symbol}=Val(:Symbolic))
DerivableFunction(F::Function, dF::Function, ddF::Function)

Stores derivatives of a given function (as well as input-output dimensions) for potentially faster computations when derivatives are known.

DerivableFunctionsBase.BuilderMethod
Builder(Fexpr::Union{<:AbstractVector{<:Num},<:Num}, args...; inplace::Bool=false, parallel::Bool=false, kwargs...)

Builds RuntimeGeneratedFunctions from expressions via build_function().

DerivableFunctionsBase.GetArgLengthMethod
GetArgLength(F::Function; max::Int=100) -> Int

Attempts to determine input structure of F, i.e. whether it accepts Numbers or AbstractVectors and of what length. This is achieved by successively evaluating the function on rand(i) until the evaluation no longer throws errors. As a result, GetArgLength will be unable to determine the correct input structure if F errors on rand(i).

Note

Does NOT discriminate between Real and Vector{Real} of length one, i.e. Real+1. To disciminate between these two options, use _GetArgLength() instead.

DerivableFunctionsBase.GetDerivMethod
GetDeriv(ADmode::Val, F::Function; kwargs...) -> Function

Returns a function which computes the scalar derivative of F out-of-place via a backend specified by ADmode.

Example:

Derivative = GetDeriv(Val(:ForwardDiff), x->exp(-x^2))
Derivative(5.0)

For available backends, see diff_backends().

DerivableFunctionsBase.GetDoubleJacFunction
GetDoubleJac(ADmode::Val, F::Function; kwargs...) -> Function

Returns a function which computes the Jacobian of the Jacobian for a vector-valued function F out-of-place via a backend specified by ADmode.

Example:

DoubleJacobian = GetDoubleJac(Val(:ForwardDiff), x->[x[1]^2, x[1]*x[2]^3])
DoubleJacobian(rand(2))

For available backends, see diff_backends().

DerivableFunctionsBase.GetGrad!Method
GetGrad!(ADmode::Val, F::Function; kwargs...) -> Function

Returns a function which computes gradients in-place via a backend specified by ADmode. The function returned by GetGrad! has argument structure (Y::AbstractVector, X::AbstractVector) where the gradient of F evaluated at X is saved into Y.

Example:

Gradient! = GetGrad!(Val(:ForwardDiff), x->x[1]^2 - x[2]^3)
Y = Vector{Float64}(undef, 2)
Gradient!(Y, rand(2))

For available backends, see diff_backends().

DerivableFunctionsBase.GetGradMethod
GetGrad(ADmode::Val, F::Function; kwargs...) -> Function

Returns a function which computes the gradient of F out-of-place via a backend specified by ADmode.

Example:

Gradient = GetGrad(Val(:ForwardDiff), x->x[1]^2 - x[2]^3)
Gradient(rand(2))

For available backends, see diff_backends().

DerivableFunctionsBase.GetHess!Method
GetHess!(ADmode::Val, F::Function; kwargs...) -> Function

Returns a function which computes Hessians in-place via a backend specified by ADmode. The function returned by GetHess! has argument structure (Y::AbstractMatrix, X::AbstractVector) where the Hessian of F evaluated at X is saved into Y.

Example:

Hessian! = GetHess!(Val(:ForwardDiff), x->x[1]^2 -x[2]^3 + x[1]*x[2])
Y = Matrix{Float64}(undef, 2, 2)
Hessian!(Y, rand(2))

For available backends, see diff_backends().

DerivableFunctionsBase.GetHessMethod
GetHess(ADmode::Val, F::Function; kwargs...) -> Function

Returns a function which computes the Hessian of F out-of-place via a backend specified by ADmode.

Example:

Hessian = GetHess(Val(:ForwardDiff), x->x[1]^2 -x[2]^3 + x[1]*x[2])
Hessian(rand(2))

For available backends, see diff_backends().

DerivableFunctionsBase.GetJac!Method
GetJac!(ADmode::Val, F::Function; kwargs...) -> Function

Returns a function which computes Jacobians in-place via a backend specified by ADmode. The function returned by GetJac! has argument structure (Y::AbstractMatrix, X::AbstractVector) where the Jacobian of F evaluated at X is saved into Y.

Example:

Jacobian! = GetJac!(Val(:ForwardDiff), x->[x[1]^2, -x[2]^3, x[1]*x[2]])
Y = Matrix{Float64}(undef, 3, 2)
Jacobian!(Y, rand(2))

For available backends, see diff_backends().

DerivableFunctionsBase.GetJacMethod
GetJac(ADmode::Val, F::Function; kwargs...) -> Function

Returns a function which computes the Jacobian of F out-of-place via a backend specified by ADmode.

Example:

Jacobian = GetJac(Val(:ForwardDiff), x->[x[1]^2, -x[2]^3, x[1]*x[2]])
Jacobian(rand(2))

For available backends, see diff_backends().

DerivableFunctionsBase.GetMatrixJacFunction
GetMatrixJac(ADmode::Val, F::Function; kwargs...) -> Function

Returns a function which computes the Jacobian of an array-valued function F out-of-place via a backend specified by ADmode.

Example:

Jacobian = GetMatrixJac(Val(:ForwardDiff), x->[x[1]^2 x[2]^3; x[1]*x[2] 2])
Jacobian(rand(2))

For available backends, see diff_backends().

DerivableFunctionsBase.GetMatrixJac!Method
GetMatrixJac!(ADmode::Val, F::Function; kwargs...) -> Function

Returns a function which computes Jacobians in-place for array-valued functions via a backend specified by ADmode. The function returned by GetMatrixJac! has argument structure (Y::AbstractArray, X::AbstractVector) where the Jacobian of F evaluated at X is saved into Y.

Example:

Jacobian! = GetMatrixJac!(Val(:ForwardDiff), x->[x[1]^2 x[2]^3; x[1]*x[2] 2])
Y = Array{Float64}(undef, 2, 2, 2)
Jacobian!(Y, rand(2))

For available backends, see diff_backends().

DerivableFunctionsBase.GetOutLengthMethod
GetOutLength(F::Function, input::Union{Number,AbstractVector{<:Number}})

Returns output dimensions of given F. If it outputs arrays of more than one dimension, a tuple is returned. This can also be used to determine the approximate size of the input for mutating F which accept 2 arguments.

Note

Discriminates between Real and Vector{Real} of length one, i.e.: Real-1 and x::AbstractVector{<:Real}length(x).

DerivableFunctionsBase.GetSymbolicDerivativeFunction
GetSymbolicDerivative(F::Function, inputdim::Int=GetArgLength(F), deriv::Symbol=:jacobian; timeout::Real=5, inplace::Bool=false, parallel::Bool=false)

Computes symbolic derivatives, including :jacobian, :gradient, :hessian and :derivative which are specified via deriv. Special care has to be taken that the correct inputdim is specified! Silent errors may occur otherwise.

DerivableFunctionsBase.KillAfterMethod
KillAfter(F::Function, args...; timeout::Real=5, verbose::Bool=false, kwargs...)

Tries to evaluate a given function F before a set timeout limit is reached and interrupts the evaluation and returns nothing if necessary. NOTE: The given function is evaluated via F(args...; kwargs...).

DerivableFunctionsBase.MaximalNumberOfArgumentsMethod
MaximalNumberOfArguments(F::Function) -> Int

Infers argument structure of given function, i.e. whether it is of the form F(x) or F(x,y) or F(x,y,z) etc. and returns maximal number of accepted arguments of all overloads of F as integer.

DerivableFunctionsBase._GetArgLengthMethod
_GetArgLength(F::Function; max::Int=100) -> Int
Note

Discriminates between Real and Vector{Real} of length one, i.e.: Real-1 and x::AbstractVector{<:Real}length(x).

DerivableFunctionsBase.suffMethod
suff(x) -> Type

If x stores BigFloats, suff returns BigFloat, else suff returns Float64.