Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /webnn/conformance_tests/round_even.https.any.html?cpu - WPT Dashboard Interop Dashboard
- /webnn/conformance_tests/round_even.https.any.html?gpu - WPT Dashboard Interop Dashboard
- /webnn/conformance_tests/round_even.https.any.html?npu - WPT Dashboard Interop Dashboard
// META: title=test WebNN API element-wise roundEven operation
// META: global=window
// META: variant=?cpu
// META: variant=?gpu
// META: variant=?npu
// META: script=../resources/utils.js
// META: timeout=long
'use strict';
// Round the input tensor with halves to the nearest even value, element-wise.
//
// MLOperand roundEven(MLOperand input);
const getRoundEvenPrecisionTolerance = () => {
return {metricType: 'ULP', value: 0};
};
const roundEvenTests = [
// roundEven tests
{
'name': 'roundEven float32 positive 0D scalar',
'graph': {
'inputs': {
'roundEvenInput': {
'data': [1.5],
'descriptor': {shape: [], dataType: 'float32'}
}
},
'operators': [{
'name': 'roundEven',
'arguments': [{'input': 'roundEvenInput'}],
'outputs': 'roundEvenOutput'
}],
'expectedOutputs': {
'roundEvenOutput': {
'data': [2],
'descriptor': {shape: [], dataType: 'float32'}
}
}
}
},
{
'name': 'roundEven float32 negative 1D tensor',
'graph': {
'inputs': {
'roundEvenInput': {
'data': [-1.5],
'descriptor': {shape: [1], dataType: 'float32'}
}
},
'operators': [{
'name': 'roundEven',
'arguments': [{'input': 'roundEvenInput'}],
'outputs': 'roundEvenOutput'
}],
'expectedOutputs': {
'roundEvenOutput': {
'data': [-2],
'descriptor': {shape: [1], dataType: 'float32'}
}
}
}
},
{
'name': 'roundEven float32 2D tensor',
'graph': {
'inputs': {
'roundEvenInput': {
'data': [-1.5, 0.5],
'descriptor': {shape: [1, 2], dataType: 'float32'}
}
},
'operators': [{
'name': 'roundEven',
'arguments': [{'input': 'roundEvenInput'}],
'outputs': 'roundEvenOutput'
}],
'expectedOutputs': {
'roundEvenOutput': {
'data': [-2, 0],
'descriptor': {shape: [1, 2], dataType: 'float32'}
}
}
}
},
{
'name': 'roundEven float32 3D tensor',
'graph': {
'inputs': {
'roundEvenInput': {
'data': [-2.5, -1.5, 0.5, 1.5],
'descriptor': {shape: [1, 2, 2], dataType: 'float32'}
}
},
'operators': [{
'name': 'roundEven',
'arguments': [{'input': 'roundEvenInput'}],
'outputs': 'roundEvenOutput'
}],
'expectedOutputs': {
'roundEvenOutput': {
'data': [-2, -2, 0, 2],
'descriptor': {shape: [1, 2, 2], dataType: 'float32'}
}
}
}
},
{
'name': 'roundEven float32 4D tensor',
'graph': {
'inputs': {
'roundEvenInput': {
'data': [-2.5, -1.5, 0.5, 1.5],
'descriptor': {shape: [1, 2, 1, 2], dataType: 'float32'}
}
},
'operators': [{
'name': 'roundEven',
'arguments': [{'input': 'roundEvenInput'}],
'outputs': 'roundEvenOutput'
}],
'expectedOutputs': {
'roundEvenOutput': {
'data': [-2, -2, 0, 2],
'descriptor': {shape: [1, 2, 1, 2], dataType: 'float32'}
}
}
}
},
// float16 tests
{
'name': 'roundEven float16 positive 0D scalar',
'graph': {
'inputs': {
'roundEvenInput': {
'data': [1.5],
'descriptor': {shape: [], dataType: 'float16'}
}
},
'operators': [{
'name': 'roundEven',
'arguments': [{'input': 'roundEvenInput'}],
'outputs': 'roundEvenOutput'
}],
'expectedOutputs': {
'roundEvenOutput': {
'data': [2],
'descriptor': {shape: [], dataType: 'float16'}
}
}
}
},
{
'name': 'roundEven float16 negative 1D tensor',
'graph': {
'inputs': {
'roundEvenInput': {
'data': [-1.5],
'descriptor': {shape: [1], dataType: 'float16'}
}
},
'operators': [{
'name': 'roundEven',
'arguments': [{'input': 'roundEvenInput'}],
'outputs': 'roundEvenOutput'
}],
'expectedOutputs': {
'roundEvenOutput': {
'data': [-2],
'descriptor': {shape: [1], dataType: 'float16'}
}
}
}
},
{
'name': 'roundEven float16 2D tensor',
'graph': {
'inputs': {
'roundEvenInput': {
'data': [-1.5, 0.5],
'descriptor': {shape: [1, 2], dataType: 'float16'}
}
},
'operators': [{
'name': 'roundEven',
'arguments': [{'input': 'roundEvenInput'}],
'outputs': 'roundEvenOutput'
}],
'expectedOutputs': {
'roundEvenOutput': {
'data': [-2, 0],
'descriptor': {shape: [1, 2], dataType: 'float16'}
}
}
}
},
{
'name': 'roundEven float16 3D tensor',
'graph': {
'inputs': {
'roundEvenInput': {
'data': [-2.5, -1.5, 0.5, 1.5],
'descriptor': {shape: [1, 2, 2], dataType: 'float16'}
}
},
'operators': [{
'name': 'roundEven',
'arguments': [{'input': 'roundEvenInput'}],
'outputs': 'roundEvenOutput'
}],
'expectedOutputs': {
'roundEvenOutput': {
'data': [-2, -2, 0, 2],
'descriptor': {shape: [1, 2, 2], dataType: 'float16'}
}
}
}
},
{
'name': 'roundEven float16 4D tensor',
'graph': {
'inputs': {
'roundEvenInput': {
'data': [-2.5, -1.5, 0.5, 1.5],
'descriptor': {shape: [1, 2, 1, 2], dataType: 'float16'}
}
},
'operators': [{
'name': 'roundEven',
'arguments': [{'input': 'roundEvenInput'}],
'outputs': 'roundEvenOutput'
}],
'expectedOutputs': {
'roundEvenOutput': {
'data': [-2, -2, 0, 2],
'descriptor': {shape: [1, 2, 1, 2], dataType: 'float16'}
}
}
}
},
]
if (navigator.ml) {
roundEvenTests.filter(isTargetTest).forEach((test) => {
webnn_conformance_test(
buildAndExecuteGraph, getRoundEvenPrecisionTolerance, test);
});
} else {
test(() => assert_implements(navigator.ml, 'missing navigator.ml'));
}