API Reference

DiffMatic.derivativeFunction
derivative(expr, wrt::Tensor)

Compute the derivative of expr with respect to wrt. Example:

@matrix A
@vector x

derivative(x' * x, x)

# output

2x₄
source
DiffMatic.gradientFunction
gradient(expr, wrt::Tensor)

Compute the gradient of expr with respect to wrt. expr must be a scalar and wrt a vector. Example:

@matrix A
@vector x

gradient(x' * A * x, x)

# output

x⁴A₄⁶ + A⁶⁵x₅
source
DiffMatic.jacobianFunction
jacobian(expr, wrt::Tensor)

Compute the jacobian of expr with respect to wrt. expr must be a column vector and wrt a vector. Example:

@matrix A
@vector x

jacobian(A * x, x)

# output

A¹₅
source
DiffMatic.hessianFunction
hessian(expr, wrt::Tensor)

Compute the hessian of expr with respect to wrt. expr must be a scalar and wrt a vector. Example:

@matrix A
@vector x

hessian(x' * A * x, x)

# output

A₇⁶ + A⁶₇
source
DiffMatic.to_stdFunction
to_std(expr; format = StdStr())

Convert the expression expr to standard notation.

  • format: Output format. Can be one of:

Examples:

@matrix A
@vector x

to_std(gradient(x' * A * x, x))

# output

"Aᵀx + Ax"
to_std(gradient(x' * A * x, x); format = JuliaFunc())

# output

quote
    #= ... =#
    function generated_function(A, x)
        #= ... =#
        #= ... =#
        return transpose(A) * x + A * x
    end
end
source