Skip to content

Commit

Permalink
Bug 1893873 [wpt PR 45947] - webnn: Enforce input data type constrain…
Browse files Browse the repository at this point in the history
…ts for prelu, a=testonly

Automatic update from web-platform-tests
webnn: Enforce input data type constraints for prelu

As specified in webmachinelearning/webnn#646.

Besides, this CL also fixes the throwing TypeError and migrates the unit
tests to WPT for prelu.

Bug: 328567884, 327337526, 328026885
Change-Id: I2c6c0097b8d4fdc8c92bd66d21abd2cbda91e030
Cq-Include-Trybots: luci.chromium.try​:win11-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5495874
Reviewed-by: Austin Sullivan <[email protected]>
Reviewed-by: ningxin hu <[email protected]>
Commit-Queue: Lisha Guo <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1297344}

--

wpt-commits: f409c99393325cfd014ff2002d84b6bb8f5afcbb
wpt-pr: 45947
  • Loading branch information
lisa0314 authored and moz-wptsync-bot committed May 14, 2024
1 parent f29ea17 commit 48bf9b8
Showing 1 changed file with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,87 @@
'use strict';

validateTwoInputsFromMultipleBuilders('prelu');

const tests = [
{
name:
'[prelu] Test slope\'s shape = [3, 2, 5] which is the same as input\'s shape.',
input: {dataType: 'float32', dimensions: [3, 2, 5]},
slope: {dataType: 'float32', dimensions: [3, 2, 5]},
output: {dataType: 'float32', dimensions: [3, 2, 5]},
},
{
name:
'[prelu] Test slope\'s shape = [5] which is unidirectionally broadcastable to input\'s shape.',
input: {dataType: 'float32', dimensions: [3, 2, 5]},
slope: {dataType: 'float32', dimensions: [5]},
output: {dataType: 'float32', dimensions: [3, 2, 5]},
},
{
name:
'[prelu] Test slope\'s shape = [] which is unidirectionally broadcastable to input\'s shape.',
input: {dataType: 'float32', dimensions: [3, 2, 5]},
slope: {dataType: 'float32', dimensions: []},
output: {dataType: 'float32', dimensions: [3, 2, 5]},
},
{
name:
'[prelu] Test slope\'s shape = [2, 5] which is unidirectionally broadcastable to input\'s shape.',
input: {dataType: 'float32', dimensions: [3, 2, 5]},
slope: {dataType: 'float32', dimensions: [2, 5]},
output: {dataType: 'float32', dimensions: [3, 2, 5]},
},
{
name:
'[prelu] Test with input\'s dataType = int32 and slope\'s dataType = int32.',
input: {dataType: 'int32', dimensions: [3, 2, 5]},
slope: {dataType: 'int32', dimensions: [2, 5]},
output: {dataType: 'int32', dimensions: [3, 2, 5]},
},
{
name:
'[prelu] Test with input\'s dataType = int8 and slope\'s dataType = int8.',
input: {dataType: 'int8', dimensions: [3, 2, 5]},
slope: {dataType: 'int8', dimensions: [2, 5]},
output: {dataType: 'int8', dimensions: [3, 2, 5]},
},
{
name:
'[prelu] Throw if the shape of slope is not broadcastable to the shape of input.',
input: {dataType: 'float32', dimensions: [3, 2, 5]},
slope: {dataType: 'float32', dimensions: [2]},
},
{
name:
'[prelu] Throw if the data type of slope does not match the data type of input.',
input: {dataType: 'float32', dimensions: [3, 2, 5]},
slope: {dataType: 'int32', dimensions: [3, 2, 5]},
},
{
name: '[prelu] Throw if the data type of input is int64.',
input: {dataType: 'int64', dimensions: [3, 2, 5]},
slope: {dataType: 'int64', dimensions: [3, 2, 5]},
},
{
name: '[prelu] Throw if the data type of input is uint32.',
input: {dataType: 'uint32', dimensions: [3, 2, 5]},
slope: {dataType: 'uint32', dimensions: [3, 2, 5]},
},
];

tests.forEach(
test => promise_test(async t => {
const input = builder.input(
'input',
{dataType: test.input.dataType, dimensions: test.input.dimensions});
const slope = builder.input(
'input',
{dataType: test.slope.dataType, dimensions: test.slope.dimensions});
if (test.output) {
const output = builder.prelu(input, slope);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.dimensions);
} else {
assert_throws_js(TypeError, () => builder.prelu(input, slope));
}
}, test.name));

0 comments on commit 48bf9b8

Please sign in to comment.