From 111de4d5527a07877edd971e8be335e067ff9a1b Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 3 Nov 2023 14:40:18 -0700 Subject: Update 07-autodiff.md --- docs/user-guide/07-autodiff.md | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'docs/user-guide') diff --git a/docs/user-guide/07-autodiff.md b/docs/user-guide/07-autodiff.md index 1f6cb06af..0751d4296 100644 --- a/docs/user-guide/07-autodiff.md +++ b/docs/user-guide/07-autodiff.md @@ -585,6 +585,15 @@ float fwd_derivative(float a, DifferentialPair x); void back_prop(float a, inout DifferentialPair x, float d_y); ``` +By default, the implicit `this` parameter will be treated as differentiable if the enclosing type of the member method is differentiable. If you wish to exclude `this` parameter from differentiation, use `[NoDiffThis]` attribute on the method: +```csharp +struct MyDifferentiableType : IDifferentiable +{ + [NoDiffThis] // Make `this` parameter `no_diff`. + float compute(float x) { ... } +} +``` + ### Excluding Struct Members from Differentiation When using automatic `IDifferentiable` conformance synthesis for a `struct` type, Slang will by-default treat all struct members that have a differentiable type as differentiable, and thus include a corresponding field in the generated `Differential` type for the struct. -- cgit v1.2.3