Bug 1910200 [wpt PR 47316] - WPT: WebNN tests for logical operator broadcasting and types, a=testonly

Automatic update from web-platform-tests
WPT: WebNN tests for logical operator broadcasting and types

Validate that logical ops (equal, greater, etc) throw if the input
tensor shapes are not broadcastable, or if they don't have matching
data types.

Also, fix test case for logicalNot() (it was renamed), and fix the
validation test helpers to prevent that from happening in the future
for any other "throws" tests with a parameterized method name.

See: https://github.com/webmachinelearning/webnn/issues/378

Cq-Include-Trybots: luci.chromium.try​:win11-blink-rel,mac14.arm64-blink-rel,mac14-blink-rel,linux-blink-rel
Change-Id: I1862226a052ada0fd2c93338cf11c1f074e7e7fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5742615
Auto-Submit: Joshua Bell <jsbell@chromium.org>
Reviewed-by: Phillis Tang <phillis@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1333809}

--

wpt-commits: d40148d6ce23962bd33fe90927bbafe8cfa04b34
wpt-pr: 47316
This commit is contained in:
Joshua Bell 2024-07-30 15:54:01 +00:00 коммит произвёл moz-wptsync-bot
Родитель 1349753b65
Коммит 7e566d5e4b
2 изменённых файлов: 16 добавлений и 2 удалений

Просмотреть файл

@ -226,6 +226,7 @@ function validateTwoInputsBroadcastable(operationName) {
const unbroadcastableDimensionsArray = generateUnbroadcastableDimensionsArray(dimensions); const unbroadcastableDimensionsArray = generateUnbroadcastableDimensionsArray(dimensions);
for (let unbroadcastableDimensions of unbroadcastableDimensionsArray) { for (let unbroadcastableDimensions of unbroadcastableDimensionsArray) {
const inputB = builder.input(`inputB${++inputBIndex}`, {dataType, dimensions: unbroadcastableDimensions}); const inputB = builder.input(`inputB${++inputBIndex}`, {dataType, dimensions: unbroadcastableDimensions});
assert_equals(typeof builder[operationName], 'function');
assert_throws_js( assert_throws_js(
TypeError, () => builder[operationName](inputA, inputB)); TypeError, () => builder[operationName](inputA, inputB));
assert_throws_js( assert_throws_js(
@ -273,6 +274,7 @@ function validateTwoInputsOfSameDataType(operationName) {
} }
if (dataType !== dataTypeB) { if (dataType !== dataTypeB) {
const inputB = builder.input(`inputB${++inputBIndex}`, {dataType: dataTypeB, dimensions}); const inputB = builder.input(`inputB${++inputBIndex}`, {dataType: dataTypeB, dimensions});
assert_equals(typeof builder[subOperationName], 'function');
assert_throws_js( assert_throws_js(
TypeError, () => builder[subOperationName](inputA, inputB)); TypeError, () => builder[subOperationName](inputA, inputB));
} }
@ -320,6 +322,7 @@ function validateOptionsAxes(operationName) {
const input = const input =
builder.input(`input${++inputIndex}`, {dataType, dimensions}); builder.input(`input${++inputIndex}`, {dataType, dimensions});
for (let invalidAxis of invalidAxisArray) { for (let invalidAxis of invalidAxisArray) {
assert_equals(typeof builder[subOperationName], 'function');
assert_throws_js( assert_throws_js(
TypeError, TypeError,
() => builder[subOperationName](input, {axes: invalidAxis})); () => builder[subOperationName](input, {axes: invalidAxis}));
@ -328,6 +331,7 @@ function validateOptionsAxes(operationName) {
assert_false( assert_false(
typeof axis === 'number' && Number.isInteger(axis), typeof axis === 'number' && Number.isInteger(axis),
`[${subOperationName}] any of options.axes elements should be of 'unsigned long'`); `[${subOperationName}] any of options.axes elements should be of 'unsigned long'`);
assert_equals(typeof builder[subOperationName], 'function');
assert_throws_js( assert_throws_js(
TypeError, TypeError,
() => builder[subOperationName](input, {axes: [axis]})); () => builder[subOperationName](input, {axes: [axis]}));
@ -354,6 +358,7 @@ function validateOptionsAxes(operationName) {
if (rank >= 1) { if (rank >= 1) {
const input = const input =
builder.input(`input${++inputIndex}`, {dataType, dimensions}); builder.input(`input${++inputIndex}`, {dataType, dimensions});
assert_equals(typeof builder[subOperationName], 'function');
assert_throws_js( assert_throws_js(
TypeError, TypeError,
() => builder[subOperationName](input, {axes: [rank]})); () => builder[subOperationName](input, {axes: [rank]}));
@ -384,6 +389,7 @@ function validateOptionsAxes(operationName) {
const axesArrayContainSameValues = const axesArrayContainSameValues =
getAxesArrayContainSameValues(dimensions); getAxesArrayContainSameValues(dimensions);
for (let axes of axesArrayContainSameValues) { for (let axes of axesArrayContainSameValues) {
assert_equals(typeof builder[subOperationName], 'function');
assert_throws_js( assert_throws_js(
TypeError, () => builder[subOperationName](input, {axes})); TypeError, () => builder[subOperationName](input, {axes}));
} }
@ -418,6 +424,7 @@ function validateUnaryOperation(
} }
for (let dimensions of allWebNNDimensionsArray) { for (let dimensions of allWebNNDimensionsArray) {
const input = builder.input(`input`, {dataType, dimensions}); const input = builder.input(`input`, {dataType, dimensions});
assert_equals(typeof builder[operationName], 'function');
const output = builder[operationName](input); const output = builder[operationName](input);
assert_equals(output.dataType(), dataType); assert_equals(output.dataType(), dataType);
assert_array_equals(output.shape(), dimensions); assert_array_equals(output.shape(), dimensions);
@ -439,6 +446,7 @@ function validateUnaryOperation(
} }
for (let dimensions of allWebNNDimensionsArray) { for (let dimensions of allWebNNDimensionsArray) {
const input = builder.input(`input`, {dataType, dimensions}); const input = builder.input(`input`, {dataType, dimensions});
assert_equals(typeof builder[operationName], 'function');
assert_throws_js(TypeError, () => builder[operationName](input)); assert_throws_js(TypeError, () => builder[operationName](input));
} }
} }
@ -490,6 +498,7 @@ function validateSingleInputOperation(
} }
for (let dimensions of allWebNNDimensionsArray) { for (let dimensions of allWebNNDimensionsArray) {
const input = builder.input(`input`, {dataType, dimensions}); const input = builder.input(`input`, {dataType, dimensions});
assert_equals(typeof builder[operationName], 'function');
assert_throws_js(TypeError, () => builder[operationName](input)); assert_throws_js(TypeError, () => builder[operationName](input));
} }
} }
@ -517,6 +526,7 @@ function validateInputFromAnotherBuilder(operatorName, operatorDescriptor = {
multi_builder_test(async (t, builder, otherBuilder) => { multi_builder_test(async (t, builder, otherBuilder) => {
const inputFromOtherBuilder = const inputFromOtherBuilder =
otherBuilder.input('input', operatorDescriptor); otherBuilder.input('input', operatorDescriptor);
assert_equals(typeof builder[operatorName], 'function');
assert_throws_js( assert_throws_js(
TypeError, () => builder[operatorName](inputFromOtherBuilder)); TypeError, () => builder[operatorName](inputFromOtherBuilder));
}, `[${operatorName}] throw if input is from another builder`); }, `[${operatorName}] throw if input is from another builder`);
@ -535,6 +545,7 @@ function validateTwoInputsFromMultipleBuilders(operatorName) {
const inputFromOtherBuilder = otherBuilder.input('other', opDescriptor); const inputFromOtherBuilder = otherBuilder.input('other', opDescriptor);
const input = builder.input('input', opDescriptor); const input = builder.input('input', opDescriptor);
assert_equals(typeof builder[operatorName], 'function');
assert_throws_js( assert_throws_js(
TypeError, () => builder[operatorName](inputFromOtherBuilder, input)); TypeError, () => builder[operatorName](inputFromOtherBuilder, input));
}, `[${operatorName}] throw if first input is from another builder`); }, `[${operatorName}] throw if first input is from another builder`);
@ -543,6 +554,7 @@ function validateTwoInputsFromMultipleBuilders(operatorName) {
const inputFromOtherBuilder = otherBuilder.input('other', opDescriptor); const inputFromOtherBuilder = otherBuilder.input('other', opDescriptor);
const input = builder.input('input', opDescriptor); const input = builder.input('input', opDescriptor);
assert_equals(typeof builder[operatorName], 'function');
assert_throws_js( assert_throws_js(
TypeError, () => builder[operatorName](input, inputFromOtherBuilder)); TypeError, () => builder[operatorName](input, inputFromOtherBuilder));
}, `[${operatorName}] throw if second input is from another builder`); }, `[${operatorName}] throw if second input is from another builder`);

Просмотреть файл

@ -13,8 +13,10 @@ const kElementwiseLogicalBinaryOperators = [
]; ];
kElementwiseLogicalBinaryOperators.forEach((operatorName) => { kElementwiseLogicalBinaryOperators.forEach((operatorName) => {
validateTwoInputsOfSameDataType(operatorName);
validateTwoInputsFromMultipleBuilders(operatorName); validateTwoInputsFromMultipleBuilders(operatorName);
validateTwoInputsBroadcastable(operatorName);
}); });
// The `not()` operator is unary. // The `logicalNot()` operator is unary.
validateInputFromAnotherBuilder('not'); validateInputFromAnotherBuilder('logicalNot');