From a20f6a03062d72135ae046319c378709fe2a8df6 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 4 Nov 2022 17:06:29 -0700 Subject: Use property for `DifferentialPair` accessors. (#2493) --- source/slang/diff.meta.slang | 54 +++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'source') diff --git a/source/slang/diff.meta.slang b/source/slang/diff.meta.slang index ae4db603e..2625d79b0 100644 --- a/source/slang/diff.meta.slang +++ b/source/slang/diff.meta.slang @@ -70,22 +70,34 @@ struct DifferentialPair : IDifferentiable __intrinsic_op($(kIROp_MakeDifferentialPair)) __init(T _primal, T.Differential _differential); - __intrinsic_op($(kIROp_DifferentialPairGetDifferential)) - T.Differential d(); + property p : T + { + __intrinsic_op($(kIROp_DifferentialPairGetPrimal)) + get; + } + + property v : T + { + __intrinsic_op($(kIROp_DifferentialPairGetPrimal)) + get; + } + + property d : T.Differential + { + __intrinsic_op($(kIROp_DifferentialPairGetDifferential)) + get; + } [__unsafeForceInlineEarly] T.Differential getDifferential() { - return d(); + return d; } - __intrinsic_op($(kIROp_DifferentialPairGetPrimal)) - T p(); - [__unsafeForceInlineEarly] T getPrimal() { - return p(); + return p; } [__unsafeForceInlineEarly] @@ -99,18 +111,18 @@ struct DifferentialPair : IDifferentiable { return Differential( T.dadd( - a.p(), - b.p() + a.p, + b.p ), - T.Differential.dadd(a.d(), b.d())); + T.Differential.dadd(a.d, b.d)); } [__unsafeForceInlineEarly] static Differential dmul(This a, Differential b) { return Differential( - T.dmul(a.p(), b.p()), - T.Differential.dmul(a.d(), b.d())); + T.dmul(a.p, b.p), + T.Differential.dmul(a.d, b.d)); } }; @@ -135,8 +147,8 @@ namespace dstd DifferentialPair d_exp(DifferentialPair dpx) { return DifferentialPair( - exp(dpx.p()), - T.dmul(exp(dpx.p()), dpx.d())); + exp(dpx.p), + T.dmul(exp(dpx.p), dpx.d)); } // Sine @@ -153,8 +165,8 @@ namespace dstd DifferentialPair d_sin(DifferentialPair dpx) { return DifferentialPair( - sin(dpx.p()), - T.dmul(cos(dpx.p()), dpx.d())); + sin(dpx.p), + T.dmul(cos(dpx.p), dpx.d)); } // Cosine @@ -171,8 +183,8 @@ namespace dstd DifferentialPair d_cos(DifferentialPair dpx) { return DifferentialPair( - cos(dpx.p()), - T.dmul(-sin(dpx.p()), dpx.d())); + cos(dpx.p), + T.dmul(-sin(dpx.p), dpx.d)); } __generic @@ -192,9 +204,9 @@ namespace dstd vector.Differential d_result; for(int i = 0; i < N; ++i) { - DifferentialPair dpexp = dstd.d_exp(DifferentialPair(dpx.p()[i], dpx.d()[i])); - result[i] = dpexp.p(); - d_result[i] = dpexp.d(); + DifferentialPair dpexp = dstd.d_exp(DifferentialPair(dpx.p[i], dpx.d[i])); + result[i] = dpexp.p; + d_result[i] = dpexp.d; } return DifferentialPair>(result, d_result); -- cgit v1.2.3