From 2571a16d959002b98e7359022336a7ad557485a7 Mon Sep 17 00:00:00 2001 From: jacobusmmsmit Date: Tue, 13 Feb 2024 12:57:57 +0000 Subject: [PATCH] Document the interaction behaviour of `@grad` and `compile`. --- src/macros.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/macros.jl b/src/macros.jl index 458d8735..42fa2445 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -174,7 +174,12 @@ end xv = ReverseDiff.value(x) return dot(xv, xv), Δ -> (Δ * 2 * xv,) end -The `@grad` macro provides a way for the users to define custom adjoints for single-output functions wrt to their input numbers or arrays. +The `@grad` macro provides a way for the users to define custom adjoints for +single-output functions wrt to their input numbers or arrays. The function that +`@grad` is applied to should return a two-element tuple containing the primal +value and the adjoint function. Note that if an adjoint function is compiled +using `compile`, any variables defined outside of the returned adjoint function +are "frozen" at their compiled values. """ macro grad(expr) d = MacroTools.splitdef(expr)