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/sin.https.any.html?cpu - WPT Dashboard Interop Dashboard
- /webnn/conformance_tests/sin.https.any.html?gpu - WPT Dashboard Interop Dashboard
- /webnn/conformance_tests/sin.https.any.html?npu - WPT Dashboard Interop Dashboard
// META: title=test WebNN API element-wise sin operation
// META: global=window
// META: variant=?cpu
// META: variant=?gpu
// META: variant=?npu
// META: script=../resources/utils.js
// META: timeout=long
'use strict';
// Compute the sine of the input tensor, element-wise.
//
// MLOperand sin(MLOperand input);
const getSinPrecisionTolerance = (graphResources) => {
// Use the float accuracy for WGSL for float16:
const toleranceValueDict = {float32: 2 ** -10, float16: 2 ** -7};
const expectedDataType =
getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs);
return {metricType: 'ATOL', value: toleranceValueDict[expectedDataType]};
};
const sinTests = [
{
'name': 'sin float32 0D scalar',
'graph': {
'inputs': {
'sinInput': {
'data': [-1.9008227506588398],
'descriptor': {shape: [], dataType: 'float32'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [-0.946033775806427],
'descriptor': {shape: [], dataType: 'float32'}
}
}
}
},
{
'name': 'sin float32 1D constant tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.9008227506588398, -1.5429342746260417, -2.919790967326577,
-0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
2.39996318810816, 2.859002653752462, 2.3440884431888165,
-1.2528136412249964, 3.0537582715247, -3.0257774670813404,
-0.13451073966544413, -1.9820843219915147, -0.6088270346587095,
0.8576429843428386, -2.9220742702326064, -1.334865713166927,
-0.3998628457123843, -0.6352694035366753, -2.9027661165286602,
0.8664462884635995, -0.1507168293157335, 2.2272057850734086
],
'descriptor': {shape: [24], dataType: 'float32'},
'constant': true
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.946033775806427, -0.9996118545532227, -0.21998752653598785,
-0.22639396786689758, -0.2618238627910614, -0.9335716366767883,
0.6754903197288513, 0.27884384989738464, 0.7156150341033936,
-0.9498680830001831, 0.08772148936986923, -0.11555644869804382,
-0.13410548865795135, -0.9166066646575928, -0.5719056725502014,
0.7563026547431946, -0.21775959432125092, -0.9722972512245178,
-0.38929200172424316, -0.59339439868927, -0.23656263947486877,
0.7620325684547424, -0.15014687180519104, 0.7921885848045349
],
'descriptor': {shape: [24], dataType: 'float32'}
}
}
}
},
{
'name': 'sin float32 1D tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.9008227506588398, -1.5429342746260417, -2.919790967326577,
-0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
2.39996318810816, 2.859002653752462, 2.3440884431888165,
-1.2528136412249964, 3.0537582715247, -3.0257774670813404,
-0.13451073966544413, -1.9820843219915147, -0.6088270346587095,
0.8576429843428386, -2.9220742702326064, -1.334865713166927,
-0.3998628457123843, -0.6352694035366753, -2.9027661165286602,
0.8664462884635995, -0.1507168293157335, 2.2272057850734086
],
'descriptor': {shape: [24], dataType: 'float32'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.946033775806427, -0.9996118545532227, -0.21998752653598785,
-0.22639396786689758, -0.2618238627910614, -0.9335716366767883,
0.6754903197288513, 0.27884384989738464, 0.7156150341033936,
-0.9498680830001831, 0.08772148936986923, -0.11555644869804382,
-0.13410548865795135, -0.9166066646575928, -0.5719056725502014,
0.7563026547431946, -0.21775959432125092, -0.9722972512245178,
-0.38929200172424316, -0.59339439868927, -0.23656263947486877,
0.7620325684547424, -0.15014687180519104, 0.7921885848045349
],
'descriptor': {shape: [24], dataType: 'float32'}
}
}
}
},
{
'name': 'sin float32 2D tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.9008227506588398, -1.5429342746260417, -2.919790967326577,
-0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
2.39996318810816, 2.859002653752462, 2.3440884431888165,
-1.2528136412249964, 3.0537582715247, -3.0257774670813404,
-0.13451073966544413, -1.9820843219915147, -0.6088270346587095,
0.8576429843428386, -2.9220742702326064, -1.334865713166927,
-0.3998628457123843, -0.6352694035366753, -2.9027661165286602,
0.8664462884635995, -0.1507168293157335, 2.2272057850734086
],
'descriptor': {shape: [4, 6], dataType: 'float32'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.946033775806427, -0.9996118545532227, -0.21998752653598785,
-0.22639396786689758, -0.2618238627910614, -0.9335716366767883,
0.6754903197288513, 0.27884384989738464, 0.7156150341033936,
-0.9498680830001831, 0.08772148936986923, -0.11555644869804382,
-0.13410548865795135, -0.9166066646575928, -0.5719056725502014,
0.7563026547431946, -0.21775959432125092, -0.9722972512245178,
-0.38929200172424316, -0.59339439868927, -0.23656263947486877,
0.7620325684547424, -0.15014687180519104, 0.7921885848045349
],
'descriptor': {shape: [4, 6], dataType: 'float32'}
}
}
}
},
{
'name': 'sin float32 3D tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.9008227506588398, -1.5429342746260417, -2.919790967326577,
-0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
2.39996318810816, 2.859002653752462, 2.3440884431888165,
-1.2528136412249964, 3.0537582715247, -3.0257774670813404,
-0.13451073966544413, -1.9820843219915147, -0.6088270346587095,
0.8576429843428386, -2.9220742702326064, -1.334865713166927,
-0.3998628457123843, -0.6352694035366753, -2.9027661165286602,
0.8664462884635995, -0.1507168293157335, 2.2272057850734086
],
'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.946033775806427, -0.9996118545532227, -0.21998752653598785,
-0.22639396786689758, -0.2618238627910614, -0.9335716366767883,
0.6754903197288513, 0.27884384989738464, 0.7156150341033936,
-0.9498680830001831, 0.08772148936986923, -0.11555644869804382,
-0.13410548865795135, -0.9166066646575928, -0.5719056725502014,
0.7563026547431946, -0.21775959432125092, -0.9722972512245178,
-0.38929200172424316, -0.59339439868927, -0.23656263947486877,
0.7620325684547424, -0.15014687180519104, 0.7921885848045349
],
'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
}
}
}
},
{
'name': 'sin float32 4D tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.9008227506588398, -1.5429342746260417, -2.919790967326577,
-0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
2.39996318810816, 2.859002653752462, 2.3440884431888165,
-1.2528136412249964, 3.0537582715247, -3.0257774670813404,
-0.13451073966544413, -1.9820843219915147, -0.6088270346587095,
0.8576429843428386, -2.9220742702326064, -1.334865713166927,
-0.3998628457123843, -0.6352694035366753, -2.9027661165286602,
0.8664462884635995, -0.1507168293157335, 2.2272057850734086
],
'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.946033775806427, -0.9996118545532227, -0.21998752653598785,
-0.22639396786689758, -0.2618238627910614, -0.9335716366767883,
0.6754903197288513, 0.27884384989738464, 0.7156150341033936,
-0.9498680830001831, 0.08772148936986923, -0.11555644869804382,
-0.13410548865795135, -0.9166066646575928, -0.5719056725502014,
0.7563026547431946, -0.21775959432125092, -0.9722972512245178,
-0.38929200172424316, -0.59339439868927, -0.23656263947486877,
0.7620325684547424, -0.15014687180519104, 0.7921885848045349
],
'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'}
}
}
}
},
{
'name': 'sin float32 5D tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.9008227506588398, -1.5429342746260417, -2.919790967326577,
-0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
2.39996318810816, 2.859002653752462, 2.3440884431888165,
-1.2528136412249964, 3.0537582715247, -3.0257774670813404,
-0.13451073966544413, -1.9820843219915147, -0.6088270346587095,
0.8576429843428386, -2.9220742702326064, -1.334865713166927,
-0.3998628457123843, -0.6352694035366753, -2.9027661165286602,
0.8664462884635995, -0.1507168293157335, 2.2272057850734086
],
'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.946033775806427, -0.9996118545532227, -0.21998752653598785,
-0.22639396786689758, -0.2618238627910614, -0.9335716366767883,
0.6754903197288513, 0.27884384989738464, 0.7156150341033936,
-0.9498680830001831, 0.08772148936986923, -0.11555644869804382,
-0.13410548865795135, -0.9166066646575928, -0.5719056725502014,
0.7563026547431946, -0.21775959432125092, -0.9722972512245178,
-0.38929200172424316, -0.59339439868927, -0.23656263947486877,
0.7620325684547424, -0.15014687180519104, 0.7921885848045349
],
'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'}
}
}
}
},
// float16 tests
{
'name': 'sin float16 0D scalar',
'graph': {
'inputs': {
'sinInput':
{'data': [79.75], 'descriptor': {shape: [], dataType: 'float16'}}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [-0.935546875],
'descriptor': {shape: [], dataType: 'float16'}
}
}
}
},
{
'name': 'sin float16 1D constant tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.932, -1.549, -2.914, -0.2247, -0.2673, -1.939, 2.398, 2.86,
2.318, -1.252, 3.05, -3.027, -0.1329, -1.979, -0.615, 0.8613,
-2.92, -1.326, -0.4004, -0.6274, -2.88, 0.8613, -0.1504, 2.234
],
'descriptor': {shape: [24], dataType: 'float16'},
'constant': true
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.935546875, -0.99951171875, -0.2254638671875,
-0.2227783203125, -0.26416015625, -0.9326171875,
0.6767578125, 0.278564453125, 0.7333984375,
-0.94970703125, 0.0906982421875, -0.114013671875,
-0.1324462890625, -0.91796875, -0.5771484375,
0.7587890625, -0.219970703125, -0.97021484375,
-0.3896484375, -0.5869140625, -0.257568359375,
0.7587890625, -0.14990234375, 0.7880859375
],
'descriptor': {shape: [24], dataType: 'float16'}
}
}
}
},
{
'name': 'sin float16 1D tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.932, -1.549, -2.914, -0.2247, -0.2673, -1.939, 2.398, 2.86,
2.318, -1.252, 3.05, -3.027, -0.1329, -1.979, -0.615, 0.8613,
-2.92, -1.326, -0.4004, -0.6274, -2.88, 0.8613, -0.1504, 2.234
],
'descriptor': {shape: [24], dataType: 'float16'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.935546875, -0.99951171875, -0.2254638671875,
-0.2227783203125, -0.26416015625, -0.9326171875,
0.6767578125, 0.278564453125, 0.7333984375,
-0.94970703125, 0.0906982421875, -0.114013671875,
-0.1324462890625, -0.91796875, -0.5771484375,
0.7587890625, -0.219970703125, -0.97021484375,
-0.3896484375, -0.5869140625, -0.257568359375,
0.7587890625, -0.14990234375, 0.7880859375
],
'descriptor': {shape: [24], dataType: 'float16'}
}
}
}
},
{
'name': 'sin float16 2D tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.932, -1.549, -2.914, -0.2247, -0.2673, -1.939, 2.398, 2.86,
2.318, -1.252, 3.05, -3.027, -0.1329, -1.979, -0.615, 0.8613,
-2.92, -1.326, -0.4004, -0.6274, -2.88, 0.8613, -0.1504, 2.234
],
'descriptor': {shape: [4, 6], dataType: 'float16'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.935546875, -0.99951171875, -0.2254638671875,
-0.2227783203125, -0.26416015625, -0.9326171875,
0.6767578125, 0.278564453125, 0.7333984375,
-0.94970703125, 0.0906982421875, -0.114013671875,
-0.1324462890625, -0.91796875, -0.5771484375,
0.7587890625, -0.219970703125, -0.97021484375,
-0.3896484375, -0.5869140625, -0.257568359375,
0.7587890625, -0.14990234375, 0.7880859375
],
'descriptor': {shape: [4, 6], dataType: 'float16'}
}
}
}
},
{
'name': 'sin float16 3D tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.932, -1.549, -2.914, -0.2247, -0.2673, -1.939, 2.398, 2.86,
2.318, -1.252, 3.05, -3.027, -0.1329, -1.979, -0.615, 0.8613,
-2.92, -1.326, -0.4004, -0.6274, -2.88, 0.8613, -0.1504, 2.234
],
'descriptor': {shape: [2, 3, 4], dataType: 'float16'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.935546875, -0.99951171875, -0.2254638671875,
-0.2227783203125, -0.26416015625, -0.9326171875,
0.6767578125, 0.278564453125, 0.7333984375,
-0.94970703125, 0.0906982421875, -0.114013671875,
-0.1324462890625, -0.91796875, -0.5771484375,
0.7587890625, -0.219970703125, -0.97021484375,
-0.3896484375, -0.5869140625, -0.257568359375,
0.7587890625, -0.14990234375, 0.7880859375
],
'descriptor': {shape: [2, 3, 4], dataType: 'float16'}
}
}
}
},
{
'name': 'sin float16 4D tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.932, -1.549, -2.914, -0.2247, -0.2673, -1.939, 2.398, 2.86,
2.318, -1.252, 3.05, -3.027, -0.1329, -1.979, -0.615, 0.8613,
-2.92, -1.326, -0.4004, -0.6274, -2.88, 0.8613, -0.1504, 2.234
],
'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.935546875, -0.99951171875, -0.2254638671875,
-0.2227783203125, -0.26416015625, -0.9326171875,
0.6767578125, 0.278564453125, 0.7333984375,
-0.94970703125, 0.0906982421875, -0.114013671875,
-0.1324462890625, -0.91796875, -0.5771484375,
0.7587890625, -0.219970703125, -0.97021484375,
-0.3896484375, -0.5869140625, -0.257568359375,
0.7587890625, -0.14990234375, 0.7880859375
],
'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'}
}
}
}
},
{
'name': 'sin float16 5D tensor',
'graph': {
'inputs': {
'sinInput': {
'data': [
-1.932, -1.549, -2.914, -0.2247, -0.2673, -1.939, 2.398, 2.86,
2.318, -1.252, 3.05, -3.027, -0.1329, -1.979, -0.615, 0.8613,
-2.92, -1.326, -0.4004, -0.6274, -2.88, 0.8613, -0.1504, 2.234
],
'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'}
}
},
'operators': [{
'name': 'sin',
'arguments': [{'input': 'sinInput'}],
'outputs': 'sinOutput'
}],
'expectedOutputs': {
'sinOutput': {
'data': [
-0.935546875, -0.99951171875, -0.2254638671875,
-0.2227783203125, -0.26416015625, -0.9326171875,
0.6767578125, 0.278564453125, 0.7333984375,
-0.94970703125, 0.0906982421875, -0.114013671875,
-0.1324462890625, -0.91796875, -0.5771484375,
0.7587890625, -0.219970703125, -0.97021484375,
-0.3896484375, -0.5869140625, -0.257568359375,
0.7587890625, -0.14990234375, 0.7880859375
],
'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'}
}
}
}
}
];
webnn_conformance_test(
sinTests, buildAndExecuteGraph, getSinPrecisionTolerance);