diff options
Diffstat (limited to 'tests/autodiff')
| -rw-r--r-- | tests/autodiff/differential-type-constructor.slang | 6 | ||||
| -rw-r--r-- | tests/autodiff/generic-constructor.slang | 10 | ||||
| -rw-r--r-- | tests/autodiff/generic-impl-jvp.slang | 26 | ||||
| -rw-r--r-- | tests/autodiff/self-differential-generic-type-synthesis.slang | 2 | ||||
| -rw-r--r-- | tests/autodiff/self-differential-type-synthesis.slang | 2 |
5 files changed, 39 insertions, 7 deletions
diff --git a/tests/autodiff/differential-type-constructor.slang b/tests/autodiff/differential-type-constructor.slang index 9afff878d..96cf1272e 100644 --- a/tests/autodiff/differential-type-constructor.slang +++ b/tests/autodiff/differential-type-constructor.slang @@ -14,12 +14,12 @@ RWStructuredBuffer<float> outputBuffer; void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) { { - var dp = diffPair(MyStruct(), MyStruct.Differential()); + var dp = diffPair(MyStruct(0.0, 0), MyStruct.Differential(0.0)); outputBuffer[0] = dp.d.a; - var dp2 = diffPair<MyStruct>(MyStruct(), MyStruct.Differential(1.f)); + var dp2 = diffPair<MyStruct>(MyStruct(0.0, 0), MyStruct.Differential(1.f)); outputBuffer[1] = dp2.d.a; } -}
\ No newline at end of file +} diff --git a/tests/autodiff/generic-constructor.slang b/tests/autodiff/generic-constructor.slang index aad9824ec..a5b098ac2 100644 --- a/tests/autodiff/generic-constructor.slang +++ b/tests/autodiff/generic-constructor.slang @@ -19,6 +19,16 @@ struct Impl : IFoo { x = v.x; } + + // We have to add this __init so that the following code can still work: + // Impl.Differential v0 = { (float)x }; + // because when there is a explicit constructor defined, we will not fall back + // to legacy constructor. So this construction will fail. + [Differentiable] + __init(float v) + { + x = v; + } } [Differentiable] diff --git a/tests/autodiff/generic-impl-jvp.slang b/tests/autodiff/generic-impl-jvp.slang index e5999b4ae..000c14248 100644 --- a/tests/autodiff/generic-impl-jvp.slang +++ b/tests/autodiff/generic-impl-jvp.slang @@ -161,6 +161,16 @@ struct lineardvector : IDifferentiable val.values[i] = a[i]; } } + + // Add a new constructor for dadd() function. + __init(Real a[N]) + { + [ForceUnroll] + for (int i = 0; i < N; i++) + { + val.values[i] = a[i]; + } + } }; __generic<let N : int> @@ -204,12 +214,24 @@ struct linearvector : MyLinearArithmeticType, IDifferentiable static Differential dadd(Differential a, Differential b) { - return { myvector<Real, N>.dadd(a.val, b.val) }; + // return { myvector<Real, N>.dadd(a.val, b.val) }; + // + // Above code will not work because + // myvector<Real, N>.dadd will return dvector<T.Differential, N> type + // while Differential == lineardvector<N> type + // and the constructor of lineardvector<N> requires a vector<Real.Differential, N> type + // and dvector<T.Differential, N> != vector<Real.Differential, N>, though they have the + // same members. + // + // In our new design, generic will not be C-Style struct anymore. + dvector<Real.Differential, N> d = myvector<Real, N>.dadd(a.val, b.val); + return {d.values}; } static Differential dmul<T: __BuiltinRealType>(T a, Differential b) { - return { myvector<Real, N>.dmul<T>(a, b.val) }; + dvector<Real.Differential, N> d = myvector<Real, N>.dmul<T>(a, b.val); + return {d.values}; } [ForwardDifferentiable] diff --git a/tests/autodiff/self-differential-generic-type-synthesis.slang b/tests/autodiff/self-differential-generic-type-synthesis.slang index 8d225dec2..7883188f6 100644 --- a/tests/autodiff/self-differential-generic-type-synthesis.slang +++ b/tests/autodiff/self-differential-generic-type-synthesis.slang @@ -17,7 +17,7 @@ struct Ray<let N: int> : IDifferentiable { [numthreads(1, 1, 1)] void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) { - Ray<4> ray = Ray<4>(); + Ray<4> ray = Ray<4>(0.0, float4(0.0), float4(0.0));; Ray<4>.Differential ray2; ray.a = 1.f; diff --git a/tests/autodiff/self-differential-type-synthesis.slang b/tests/autodiff/self-differential-type-synthesis.slang index 7f95891c6..6faa2175a 100644 --- a/tests/autodiff/self-differential-type-synthesis.slang +++ b/tests/autodiff/self-differential-type-synthesis.slang @@ -17,7 +17,7 @@ struct Ray : IDifferentiable { [numthreads(1, 1, 1)] void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) { - Ray ray = Ray(); + Ray ray = {}; Ray.Differential ray2; ray.a = 1.f; |
