Skip to content

Commit

Permalink
webnn: Enforce input data type constraints for some reduce operators
Browse files Browse the repository at this point in the history
As specified in webmachinelearning/webnn#646

Bug: 328567884
Change-Id: I5e600bdc791ecd4530408b65c15dd20611c211a3
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel
  • Loading branch information
lisa0314 authored and chromium-wpt-export-bot committed May 10, 2024
1 parent db7b1cf commit bcb4ce2
Showing 1 changed file with 52 additions and 11 deletions.
63 changes: 52 additions & 11 deletions webnn/validation_tests/reduction.https.any.js
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 bcb4ce2

Please sign in to comment.