API Reference
DiffMatic.@matrix
— Macro@matrix(ids...)
Create one or more matrices. Example:
@matrix A X
DiffMatic.@vector
— Macro@vector(ids...)
Create one or more vectors. Example:
@vector x y
DiffMatic.@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()
Julia function that evaluates an expression in standard form.
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