diff options
| author | Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> | 2023-07-26 17:15:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-26 17:15:21 -0400 |
| commit | ba89fc84267bfd09f1c8abf10a5b85d09bbc79de (patch) | |
| tree | 2c79fc5dafb89a030d22fa86cd6fa3d69a89a785 /tests/autodiff/generic-impl-jvp.slang | |
| parent | b8ade05df10a2774d3da5ef1fb2c7479ff48989a (diff) | |
Refactor `dmul(This, Differential)` to `dmul<T:Real>(T, Differential)` (#3029)
* Refactor `dmul(This, Differential)` to `dmul<T:Real>(T, Differential)`
- Add AST synthesis support for generic containers
- Refactor relevant tests
* Merge dmul synthesis with dadd and dzero, and disambiguate using an enum
* Fix trailing spaces
Diffstat (limited to 'tests/autodiff/generic-impl-jvp.slang')
| -rw-r--r-- | tests/autodiff/generic-impl-jvp.slang | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/tests/autodiff/generic-impl-jvp.slang b/tests/autodiff/generic-impl-jvp.slang index 98adc4a7c..674d5c5ca 100644 --- a/tests/autodiff/generic-impl-jvp.slang +++ b/tests/autodiff/generic-impl-jvp.slang @@ -6,7 +6,7 @@ RWStructuredBuffer<float> outputBuffer; typedef float Real; -typealias IDFloat = IFloat & IDifferentiable; +typealias IDFloat = __BuiltinRealType & IDifferentiable; __generic<T : IDifferentiable, let N : int> struct dvector : IDifferentiable @@ -44,13 +44,13 @@ struct myvector : IDifferentiable } - static Differential dmul(This a, Differential b) + static Differential dmul<U: __BuiltinRealType>(U a, Differential b) { Differential output; for (int i = 0; i < N; i++) { - output.values[i] = T.dmul(a.values[i], b.values[i]); + output.values[i] = T.dmul<U>(a, b.values[i]); } return output; @@ -112,7 +112,7 @@ __generic<T : IDFloat, let N : int> [ForwardDerivative(dot_jvp)] T dot(myvector<T, N> a, myvector<T, N> b) { - T curr = (T)0.0; + T curr = __realCast<T, float>(0.f); [ForceUnroll] for (int i = 0; i < N; i++) { @@ -129,7 +129,7 @@ __generic<T : IDFloat, let N : int> DifferentialPair<T> dot_jvp(dpvector<T, N> a, dpvector<T, N> b) { T.Differential curr_d = (T.dzero()); - T curr_p = (T)0.0; + T curr_p = __realCast<T, float>(0.f); [ForceUnroll] for (int i = 0; i < N; i++) { @@ -137,8 +137,8 @@ DifferentialPair<T> dot_jvp(dpvector<T, N> a, dpvector<T, N> b) curr_d = T.dadd( curr_d, T.dadd( - T.dmul(a.p.values[i], b.d.values[i]), - T.dmul(b.p.values[i], a.d.values[i]))); + T.dmul<T>(a.p.values[i], b.d.values[i]), + T.dmul<T>(b.p.values[i], a.d.values[i]))); } return DifferentialPair<T>(curr_p, curr_d); @@ -203,9 +203,9 @@ struct linearvector : MyLinearArithmeticType, IDifferentiable return { myvector<Real, N>.dadd(a.val, b.val) }; } - static Differential dmul(This a, Differential b) + static Differential dmul<T: __BuiltinRealType>(T a, Differential b) { - return { myvector<Real, N>.dmul(a.val, b.val) }; + return { myvector<Real, N>.dmul<T>(a, b.val) }; } [ForwardDifferentiable] |
