API Reference
DiffMatic.@matrix — Macro@matrix(ids...)Create one or more matrices. Example:
@matrix A XDiffMatic.@vector — Macro@vector(ids...)Create one or more vectors. Example:
@vector x yDiffMatic.@scalar — Macro@scalar(ids...)Create one or more scalars. Example:
@scalar a βDiffMatic.derivative — Functionderivative(expr, wrt::Tensor)Compute the derivative of expr with respect to wrt. Example:
@matrix A
@vector x
derivative(x' * x, x)
# output
2x₄DiffMatic.gradient — Functiongradient(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₅DiffMatic.jacobian — Functionjacobian(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¹₅DiffMatic.hessian — Functionhessian(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⁶₇DiffMatic.JuliaFunc — TypeJuliaFunc([args=AbstractVector{Variable},])Julia function that evaluates an expression in standard form. The optional argument args can be used for specifying order of the arguments in the function signature. If args is given, then each variable must occur exactly once.
DiffMatic.StdStr — TypeStdStr()String format of an expression in standard form.
DiffMatic.to_std — Functionto_std(expr; format = StdStr())Convert the expression expr to standard notation.
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