From 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:33 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../webnn/validation_tests/gather.https.any.js | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 testing/web-platform/tests/webnn/validation_tests/gather.https.any.js (limited to 'testing/web-platform/tests/webnn/validation_tests/gather.https.any.js') diff --git a/testing/web-platform/tests/webnn/validation_tests/gather.https.any.js b/testing/web-platform/tests/webnn/validation_tests/gather.https.any.js new file mode 100644 index 0000000000..67ac7d7be3 --- /dev/null +++ b/testing/web-platform/tests/webnn/validation_tests/gather.https.any.js @@ -0,0 +1,62 @@ +// META: title=validation tests for WebNN API gather operation +// META: global=window,dedicatedworker +// META: script=../resources/utils_validation.js +// META: timeout=long + +'use strict'; + +const tests = [ + { + name: '[gather] Test gather with default options and 0-D indices', + input: {dataType: 'int32', dimensions: [3]}, + indices: {dataType: 'uint64', dimensions: []}, + output: {dataType: 'int32', dimensions: []} + }, + { + name: '[gather] Test gather with axis = 2', + input: {dataType: 'float32', dimensions: [1, 2, 3, 4]}, + indices: {dataType: 'int64', dimensions: [5, 6]}, + axis: 2, + output: {dataType: 'float32', dimensions: [1, 2, 5, 6, 4]} + }, + { + name: '[gather] TypeError is expected if the input is a scalar', + input: {dataType: 'float16', dimensions: []}, + indices: {dataType: 'int64', dimensions: [1]} + }, + { + name: '[gather] TypeError is expected if the axis is greater than the rank of input', + input: {dataType: 'float16', dimensions: [1, 2, 3]}, + indices: {dataType: 'int32', dimensions: [5, 6]}, + axis: 4 + }, + { + name: '[gather] TypeError is expected if the data type of indices is invalid', + input: {dataType: 'float16', dimensions: [1, 2, 3, 4]}, + indices: {dataType: 'float32', dimensions: [5, 6]} + } +]; + +tests.forEach( + test => promise_test(async t => { + const input = builder.input( + 'input', + {dataType: test.input.dataType, dimensions: test.input.dimensions}); + const indices = builder.input( + 'indices', + {dataType: test.indices.dataType, dimensions: test.indices.dimensions}); + + const options = {}; + if (test.axis) { + options.axis = test.axis; + } + + if (test.output) { + const output = builder.gather(input, indices, options); + assert_equals(output.dataType(), test.output.dataType); + assert_array_equals(output.shape(), test.output.dimensions); + } else { + assert_throws_js( + TypeError, () => builder.gather(input, indices, options)); + } + }, test.name)); -- cgit v1.2.3