diff options
| author | Yong He <yonghe@outlook.com> | 2025-04-30 14:17:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-30 14:17:45 -0700 |
| commit | 7f1df9d0b31413e59846cc955d2a955d3f361e2a (patch) | |
| tree | 8cfcb7b6dde96f90e9581f9a904a25158a7358cb /tests/language-feature/lambda/lambda-1.slang | |
| parent | 678de6547bc8cac15e31de30b400e9a3b45c216f (diff) | |
Initial support for immutable lambda expressions. (#6914)
* Initial support for immutable lambda expressions.
* More diagnostics, and langauge server fix.
* Language server fix.
* Fix bug identified in review.
* Add expected result.
* Update expected result.
Diffstat (limited to 'tests/language-feature/lambda/lambda-1.slang')
| -rw-r--r-- | tests/language-feature/lambda/lambda-1.slang | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/language-feature/lambda/lambda-1.slang b/tests/language-feature/lambda/lambda-1.slang new file mode 100644 index 000000000..66f68d334 --- /dev/null +++ b/tests/language-feature/lambda/lambda-1.slang @@ -0,0 +1,47 @@ + +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type + +//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4) +RWStructuredBuffer<float> outputBuffer; + +struct Matrix +{ + float data[16]; + + [mutating] + void map(IFunc<float, float> f) + { + for (int i = 0; i < 16; ++i) + { + data[i] = f(data[i]); + } + } +} + +struct Applier +{ + float c; + void apply(inout Matrix m) + { + m.map((float x) => + { + if (x > 2.5) + return x * c; + else + return x + c; + }); + } +} + +[numthreads(1,1,1)] +void computeMain() +{ + Matrix m = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Applier applier = { 1.5 }; + applier.apply(m); + outputBuffer[0] = m.data[1]; + // CHECK: 3.5 + outputBuffer[1] = m.data[3]; + // CHECK: 6.0 +}
\ No newline at end of file |
