API Reference
DiffMatic.@matrix — Macro
DiffMatic.@vector — Macro
DiffMatic.@scalar — Macro
DiffMatic.derivative — Function
derivative(expr, wrt::Tensor)Compute the derivative of expr with respect to wrt. Example:
@matrix A
@vector x
derivative(x' * x, x)
# output
2x₄sourceDiffMatic.gradient — Function
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₅sourceDiffMatic.jacobian — Function
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¹₅sourceDiffMatic.hessian — Function
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⁶₇sourceDiffMatic.JuliaFunc — Type
JuliaFunc([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 — Type
DiffMatic.to_std — Function
to_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
endsource