diff options
Diffstat (limited to 'testing/web-platform/tests/webnn/validation_tests/transpose.https.any.js')
-rw-r--r-- | testing/web-platform/tests/webnn/validation_tests/transpose.https.any.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webnn/validation_tests/transpose.https.any.js b/testing/web-platform/tests/webnn/validation_tests/transpose.https.any.js index 9ea5a5dcf8..3475a427d7 100644 --- a/testing/web-platform/tests/webnn/validation_tests/transpose.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/transpose.https.any.js @@ -5,3 +5,54 @@ 'use strict'; validateInputFromAnotherBuilder('transpose'); + +const tests = [ + { + name: '[transpose] Test building transpose with default options.', + input: {dataType: 'float32', dimensions: [1, 2, 3, 4]}, + output: {dataType: 'float32', dimensions: [4, 3, 2, 1]} + }, + { + name: '[transpose] Test building transpose with permutation=[0, 2, 3, 1].', + input: {dataType: 'float32', dimensions: [1, 2, 3, 4]}, + options: {permutation: [0, 2, 3, 1]}, + output: {dataType: 'float32', dimensions: [1, 3, 4, 2]} + }, + { + name: + '[transpose] Throw if permutation\'s size is not the same as input\'s rank.', + input: {dataType: 'int32', dimensions: [1, 2, 4]}, + options: {permutation: [0, 2, 3, 1]}, + }, + { + name: '[transpose] Throw if two values in permutation are same.', + input: {dataType: 'int32', dimensions: [1, 2, 3, 4]}, + options: {permutation: [0, 2, 3, 2]}, + }, + { + name: + '[transpose] Throw if any value in permutation is not in the range [0,input\'s rank).', + input: {dataType: 'int32', dimensions: [1, 2, 3, 4]}, + options: {permutation: [0, 1, 2, 4]}, + }, + { + name: '[transpose] Throw if any value in permutation is negative.', + input: {dataType: 'int32', dimensions: [1, 2, 3, 4]}, + options: {permutation: [0, -1, 2, 3]}, + } +]; + +tests.forEach( + test => promise_test(async t => { + const input = builder.input( + 'input', + {dataType: test.input.dataType, dimensions: test.input.dimensions}); + if (test.output) { + const output = builder.transpose(input, test.options); + assert_equals(output.dataType(), test.output.dataType); + assert_array_equals(output.shape(), test.output.dimensions); + } else { + assert_throws_js( + TypeError, () => builder.transpose(input, test.options)); + } + }, test.name)); |