Skip to content

Commit

Permalink
Bug 1895839 [wpt PR 46180] - webnn: Enforce input data type constrain…
Browse files Browse the repository at this point in the history
…ts for some reduce operators, a=testonly

Automatic update from web-platform-tests
webnn: Enforce input data type constraints for some reduce operators

As specified in webmachinelearning/webnn#646

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

--

wpt-commits: 0fa5e3bc5d097d84c074bc138271d8999277a50c
wpt-pr: 46180
  • Loading branch information
lisa0314 authored and moz-wptsync-bot committed May 23, 2024
1 parent 25e2c58 commit 1573967
Showing 1 changed file with 52 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ const kFloatRestrictReductionOperators = [
'reduceMean',
];

const kFloatAllowReductionOperators = [
const kFloatInt32Uint32RestrictReductionOperators = [
'reduceL1',
'reduceMax',
'reduceMin',
'reduceProduct',
'reduceSum',
'reduceSumSquare',
];

const kNoTypeRestrictReductionOperators = [
'reduceMax',
'reduceMin',
];

const allReductionOperatorsTests = [
{
name: '[reduce] Test reduce with default options.',
Expand Down Expand Up @@ -76,22 +79,56 @@ const allReductionOperatorsTests = [

const kFloatRestrictOperatorsTests = [
{
name:
'[reduce] Throw if the input data type is not one of the floating point.',
name: '[reduce] Throw if the input data type is int32.',
input: {dataType: 'int32', dimensions: [1, 2, 5, 5]},
options: {
axes: [0, 1],
},
},
];

const kFloatAllowOperatorsTests = [
const kFloatInt32Uint32RestrictOperatorsTests = [
{
name:
'[reduce] Test when the input data type is not one of the floating point.',
input: {dataType: 'int32', dimensions: [1, 3, 4, 4]},
name: '[reduce] Test reduce when input\'s datatype is int32.',
input: {dataType: 'int32', dimensions: [1, 2, 5, 5]},
output: {dataType: 'int32', dimensions: []}
},
{
name: '[reduce] Test reduce when input\'s datatype is uint32.',
input: {dataType: 'uint32', dimensions: [1, 2, 5, 5]},
output: {dataType: 'uint32', dimensions: []}
},
{
name:
'[reduce] Throw if the input data type is not one of the {float32, float16, int32, uint32}.',
input: {dataType: 'int64', dimensions: [1, 2, 5, 5]},
options: {
axes: [0, 1],
},
},
];

const kNoTypeRestrictOperatorsTests = [
{
name: '[reduce] Test reduce when input\'s datatype is int64.',
input: {dataType: 'int64', dimensions: [1, 3, 4, 4]},
output: {dataType: 'int64', dimensions: []}
},
{
name: '[reduce] Test reduce when input\'s datatype is uint64.',
input: {dataType: 'uint64', dimensions: [1, 3, 4, 4]},
output: {dataType: 'uint64', dimensions: []}
},
{
name: '[reduce] Test reduce when input\'s datatype is int8.',
input: {dataType: 'int8', dimensions: [1, 3, 4, 4]},
output: {dataType: 'int8', dimensions: []}
},
{
name: '[reduce] Test reduce when input\'s datatype is uint8.',
input: {dataType: 'uint8', dimensions: [1, 3, 4, 4]},
output: {dataType: 'uint8', dimensions: []}
},
];

function runReductionTests(operatorName, tests) {
Expand Down Expand Up @@ -122,6 +159,10 @@ kFloatRestrictReductionOperators.forEach((operatorName) => {
runReductionTests(operatorName, kFloatRestrictOperatorsTests);
});

kFloatAllowReductionOperators.forEach((operatorName) => {
runReductionTests(operatorName, kFloatAllowOperatorsTests);
kFloatInt32Uint32RestrictReductionOperators.forEach((operatorName) => {
runReductionTests(operatorName, kFloatInt32Uint32RestrictOperatorsTests);
});

kNoTypeRestrictReductionOperators.forEach((operatorName) => {
runReductionTests(operatorName, kNoTypeRestrictOperatorsTests);
});

0 comments on commit 1573967

Please sign in to comment.