Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /webnn/conformance_tests/clamp.https.any.html?cpu - WPT Dashboard Interop Dashboard
- /webnn/conformance_tests/clamp.https.any.html?gpu - WPT Dashboard Interop Dashboard
- /webnn/conformance_tests/clamp.https.any.html?npu - WPT Dashboard Interop Dashboard
- /webnn/conformance_tests/clamp.https.any.worker.html?cpu - WPT Dashboard Interop Dashboard
- /webnn/conformance_tests/clamp.https.any.worker.html?gpu - WPT Dashboard Interop Dashboard
- /webnn/conformance_tests/clamp.https.any.worker.html?npu - WPT Dashboard Interop Dashboard
// META: title=test WebNN API clamp operation
// META: global=window,dedicatedworker
// META: variant=?cpu
// META: variant=?gpu
// META: variant=?npu
// META: script=../resources/utils.js
// META: timeout=long
'use strict';
// Clamp the input tensor element-wise within a range specified by the minimum
// and maximum values.
//
// dictionary MLClampOptions {
// MLNumber minValue;
// MLNumber maxValue;
// };
//
// MLOperand clamp(MLOperand input, optional MLClampOptions options = {});
const clampTests = [
{
'name': 'clamp float32 0D tensor default options',
'graph': {
'inputs': {
'clampInput': {
'data': [-9.817828178405762],
'descriptor': {shape: [], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [-9.817828178405762],
'descriptor': {shape: [], dataType: 'float32'}
}
}
}
},
{
'name': 'clamp float32 1D constant tensor default options',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [24], dataType: 'float32'},
'constant': true
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [24], dataType: 'float32'}
}
}
}
},
{
'name': 'clamp float32 1D tensor default options',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [24], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [24], dataType: 'float32'}
}
}
}
},
{
'name': 'clamp float16 1D tensor',
'graph': {
'inputs': {
'clampInput': {
'data': [NaN, -Infinity, Infinity, -64000, 64000, -2, 1, 0],
'descriptor': {shape: [8], dataType: 'float16'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}, {'options': {'minValue': -2}}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [NaN, -2, Infinity, -2, 64000, -2, 1, 0],
'descriptor': {shape: [8], dataType: 'float16'}
}
}
}
},
{
'name': 'clamp int8 1D tensor',
'graph': {
'inputs': {
'clampInput': {
'data': [-128, 127, -4, -2, 1, 0, 2, 4],
'descriptor': {shape: [8], dataType: 'int8'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'},
{'options': {'minValue': -2, 'maxValue': 125}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [-2, 125, -2, -2, 1, 0, 2, 4],
'descriptor': {shape: [8], dataType: 'int8'}
}
}
}
},
{
'name': 'clamp uint8 1D tensor',
'graph': {
'inputs': {
'clampInput': {
'data': [255, 127, 5, 0],
'descriptor': {shape: [4], dataType: 'uint8'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'}, {'options': {'minValue': 5, 'maxValue': 200}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [200, 127, 5, 5],
'descriptor': {shape: [4], dataType: 'uint8'}
}
}
}
},
{
'name': 'clamp int32 1D tensor',
'graph': {
'inputs': {
'clampInput': {
'data': [-2147483648, 2147483647, -4, -2, 1, 0, 2, 4],
'descriptor': {shape: [8], dataType: 'int32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'},
{'options': {'minValue': -2, 'maxValue': 2147483645}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [-2, 2147483645, -2, -2, 1, 0, 2, 4],
'descriptor': {shape: [8], dataType: 'int32'}
}
}
}
},
{
'name': 'clamp uint32 1D tensor',
'graph': {
'inputs': {
'clampInput': {
'data': [4294967295, 127, 5, 0],
'descriptor': {shape: [4], dataType: 'uint32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'},
{'options': {'minValue': 5, 'maxValue': 4294967290}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [4294967290, 127, 5, 5],
'descriptor': {shape: [4], dataType: 'uint32'}
}
}
}
},
{
'name': 'clamp int64 1D tensor',
'graph': {
'inputs': {
'clampInput': {
'data': [-4147483648, 4147483647, -4, -2, 1, 0, 2, 4],
'descriptor': {shape: [8], dataType: 'int64'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'},
{'options': {'minValue': -2, 'maxValue': 4147483645}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [-2, 4147483645, -2, -2, 1, 0, 2, 4],
'descriptor': {shape: [8], dataType: 'int64'}
}
}
}
},
{
'name': 'clamp uint64 1D tensor',
'graph': {
'inputs': {
'clampInput': {
'data': [5294967295, 127, 5, 0],
'descriptor': {shape: [4], dataType: 'uint64'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'},
{'options': {'minValue': 5, 'maxValue': 5294967290}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [5294967290, 127, 5, 5],
'descriptor': {shape: [4], dataType: 'uint64'}
}
}
}
},
{
'name': 'clamp float32 2D tensor default options',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [4, 6], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [4, 6], dataType: 'float32'}
}
}
}
},
{
'name': 'clamp float32 3D tensor default options',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
}
}
}
},
{
'name': 'clamp float32 4D tensor default options',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [3, 2, 2, 2], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [3, 2, 2, 2], dataType: 'float32'}
}
}
}
},
{
'name': 'clamp float32 5D tensor default options',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [4, 1, 1, 2, 3], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [4, 1, 1, 2, 3], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 4D tensor default options.maxValue and specified negative options.minValue',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}, {'options': {'minValue': -1}}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-1,
-1,
-1,
-1,
-1,
9.524681091308594,
3.7292487621307373,
6.481687068939209,
-1,
-1,
7.880751132965088,
-1,
6.3438639640808105,
5.525737762451172,
0.8433118462562561,
-1,
-1,
9.280223846435547,
-1,
9.549695014953613,
5.788925647735596,
5.549378395080566,
7.409400463104248,
-1
],
'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 3D tensor default options.maxValue and specified options.minValue=0.0',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [6, 2, 2], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}, {'options': {'minValue': 0}}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
0,
0,
0,
0,
0,
9.524681091308594,
3.7292487621307373,
6.481687068939209,
0,
0,
7.880751132965088,
0,
6.3438639640808105,
5.525737762451172,
0.8433118462562561,
0,
0,
9.280223846435547,
0,
9.549695014953613,
5.788925647735596,
5.549378395080566,
7.409400463104248,
0
],
'descriptor': {shape: [6, 2, 2], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 2D tensor default options.maxValue and specified positive options.minValue',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [3, 8], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}, {'options': {'minValue': 1}}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
1,
1,
1,
1,
1,
9.524681091308594,
3.7292487621307373,
6.481687068939209,
1,
1,
7.880751132965088,
1,
6.3438639640808105,
5.525737762451172,
1,
1,
1,
9.280223846435547,
1,
9.549695014953613,
5.788925647735596,
5.549378395080566,
7.409400463104248,
1
],
'descriptor': {shape: [3, 8], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 5D tensor default options.minValue and specified negative options.maxValue',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': -2}}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-9.817828178405762,
-6.024064064025879,
-4.0725626945495605,
-6.575078010559082,
-7.755683898925781,
-2,
-2,
-2,
-2,
-7.34310245513916,
-2,
-2.0564088821411133,
-2,
-2,
-2,
-8.199960708618164,
-7.786487102508545,
-2,
-2.3130595684051514,
-2,
-2,
-2,
-2,
-2.123614549636841
],
'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 1D tensor default options.minValue and specified options.maxValue=0.0',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [24], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': 0}}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-9.817828178405762,
-6.024064064025879,
-4.0725626945495605,
-6.575078010559082,
-7.755683898925781,
0,
0,
0,
-1.537420630455017,
-7.34310245513916,
0,
-2.0564088821411133,
0,
0,
0,
-8.199960708618164,
-7.786487102508545,
0,
-2.3130595684051514,
0,
0,
0,
0,
-2.123614549636841
],
'descriptor': {shape: [24], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 3D tensor default options.minValue and specified positive options.maxValue',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [3, 4, 2], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': 3}}],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-9.817828178405762,
-6.024064064025879,
-4.0725626945495605,
-6.575078010559082,
-7.755683898925781,
3,
3,
3,
-1.537420630455017,
-7.34310245513916,
3,
-2.0564088821411133,
3,
3,
0.8433118462562561,
-8.199960708618164,
-7.786487102508545,
3,
-2.3130595684051514,
3,
3,
3,
3,
-2.123614549636841
],
'descriptor': {shape: [3, 4, 2], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 5D tensor specified both negative options.minValue and options.maxValue',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [3, 2, 1, 1, 4], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'}, {'options': {'minValue': -8, 'maxValue': -1}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-8,
-6.024064064025879,
-4.0725626945495605,
-6.575078010559082,
-7.755683898925781,
-1,
-1,
-1,
-1.537420630455017,
-7.34310245513916,
-1,
-2.0564088821411133,
-1,
-1,
-1,
-8,
-7.786487102508545,
-1,
-2.3130595684051514,
-1,
-1,
-1,
-1,
-2.123614549636841
],
'descriptor': {shape: [3, 2, 1, 1, 4], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 4D tensor specified negative options.minValue and options.maxValue=0.0',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [1, 4, 3, 2], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'}, {'options': {'minValue': -6, 'maxValue': 0}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-6,
-6,
-4.0725626945495605,
-6,
-6,
0,
0,
0,
-1.537420630455017,
-6,
0,
-2.0564088821411133,
0,
0,
0,
-6,
-6,
0,
-2.3130595684051514,
0,
0,
0,
0,
-2.123614549636841
],
'descriptor': {shape: [1, 4, 3, 2], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 3D tensor specified negative options.minValue and positive options.maxValue',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [2, 6, 2], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'}, {'options': {'minValue': -3, 'maxValue': 4}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
-3,
-3,
-3,
-3,
-3,
4,
3.7292487621307373,
4,
-1.537420630455017,
-3,
4,
-2.0564088821411133,
4,
4,
0.8433118462562561,
-3,
-3,
4,
-2.3130595684051514,
4,
4,
4,
4,
-2.123614549636841
],
'descriptor': {shape: [2, 6, 2], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 2D tensor specified options.minValue=0.0 and positive options.maxValue',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [6, 4], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'}, {'options': {'minValue': 0, 'maxValue': 6}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
0,
0,
0,
0,
0,
6,
3.7292487621307373,
6,
0,
0,
6,
0,
6,
5.525737762451172,
0.8433118462562561,
0,
0,
6,
0,
6,
5.788925647735596,
5.549378395080566,
6,
0
],
'descriptor': {shape: [6, 4], dataType: 'float32'}
}
}
}
},
{
'name':
'clamp float32 1D tensor specified both positive options.minValue and options.maxValue',
'graph': {
'inputs': {
'clampInput': {
'data': [
-9.817828178405762, -6.024064064025879, -4.0725626945495605,
-6.575078010559082, -7.755683898925781, 9.524681091308594,
3.7292487621307373, 6.481687068939209, -1.537420630455017,
-7.34310245513916, 7.880751132965088, -2.0564088821411133,
6.3438639640808105, 5.525737762451172, 0.8433118462562561,
-8.199960708618164, -7.786487102508545, 9.280223846435547,
-2.3130595684051514, 9.549695014953613, 5.788925647735596,
5.549378395080566, 7.409400463104248, -2.123614549636841
],
'descriptor': {shape: [24], dataType: 'float32'}
}
},
'operators': [{
'name': 'clamp',
'arguments': [
{'input': 'clampInput'}, {'options': {'minValue': 2, 'maxValue': 7}}
],
'outputs': 'clampOutput'
}],
'expectedOutputs': {
'clampOutput': {
'data': [
2,
2,
2,
2,
2,
7,
3.7292487621307373,
6.481687068939209,
2,
2,
7,
2,
6.3438639640808105,
5.525737762451172,
2,
2,
2,
7,
2,
7,
5.788925647735596,
5.549378395080566,
7,
2
],
'descriptor': {shape: [24], dataType: 'float32'}
}
}
}
}
];
if (navigator.ml) {
clampTests.forEach((test) => {
webnn_conformance_test(buildAndExecuteGraph, getPrecisionTolerance, test);
});
} else {
test(() => assert_implements(navigator.ml, 'missing navigator.ml'));
}