diff options
| author | winmad <winmad.wlf@gmail.com> | 2022-12-02 01:01:58 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-02 01:01:58 -0800 |
| commit | 30b5335fed9524101d980618b0749dcaf546c319 (patch) | |
| tree | 2a87d1423d8497bafda55ee80ef99ad6458793a5 /source | |
| parent | 1562e73dfa3e4c1283811e478af25c6447a528c0 (diff) | |
Add helper functions to update DifferentialPair (#2547)
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/diff.meta.slang | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/source/slang/diff.meta.slang b/source/slang/diff.meta.slang index 033c173ab..a97ab9eaf 100644 --- a/source/slang/diff.meta.slang +++ b/source/slang/diff.meta.slang @@ -92,6 +92,24 @@ struct DifferentialPair : IDifferentiable } }; +[ForceInline] +void updatePrimal<T : IDifferentiable>(inout DifferentialPair<T> p, T newPrimal) +{ + p = DifferentialPair<T>(newPrimal, p.d); +} + +[ForceInline] +void updateDiff<T : IDifferentiable>(inout DifferentialPair<T> p, T.Differential newDiff) +{ + p = DifferentialPair<T>(p.p, newDiff); +} + +[ForceInline] +void updatePair<T : IDifferentiable>(inout DifferentialPair<T> p, T newPrimal, T.Differential newDiff) +{ + p = DifferentialPair<T>(newPrimal, newDiff); +} + #define VECTOR_MAP_D_UNARY(TYPE, COUNT, D_FUNC, VALUE) \ vector<TYPE, COUNT> result; \ |
