From c6e6b7a9177bf4f7fc2f05da36c5952979006d78 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 4 Nov 2022 09:36:23 -0700 Subject: Higher order differentiation. (#2487) Co-authored-by: Yong He --- tests/autodiff/high-order-forward-diff.slang | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'tests/autodiff/high-order-forward-diff.slang') diff --git a/tests/autodiff/high-order-forward-diff.slang b/tests/autodiff/high-order-forward-diff.slang index fde659227..94b4d2a0d 100644 --- a/tests/autodiff/high-order-forward-diff.slang +++ b/tests/autodiff/high-order-forward-diff.slang @@ -1,15 +1,21 @@ -//DTEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type -//DTEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer outputBuffer; [ForwardDifferentiable] -float f(float x) +float mySqr(float x) { return x * x; } +[ForwardDifferentiable] +float f(float x) +{ + return mySqr(x * x); +} + [ForwardDifferentiable] float df(float x) { @@ -19,5 +25,8 @@ float df(float x) [numthreads(1, 1, 1)] void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) { - outputBuffer[0] = __fwd_diff(df)(DifferentialPair(1.0, 1.0)).d(); // Expect: 2.0 + // Given f(x) = x^4, + // f''(x) = 12 * x^2 + // Expect f''(4) = 192 + outputBuffer[0] = __fwd_diff(df)(DifferentialPair(4.0, 1.0)).d(); } -- cgit v1.2.3