diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_l1.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_l1.json index c3f2b618e9b0e..7637c02be23ce 100644 --- a/testing/web-platform/tests/webnn/resources/test_data/reduce_l1.json +++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_l1.json @@ -1,5 +1,44 @@ { "tests": [ + { + "name": "reduceL1 float32 0D constant tensor default options", // default options: {axes: null, keepDimensions: false} + "inputs": { + "input": { + "shape": [], + "data": [ + 5.50882625579834 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 5.50882625579834, + "type": "float32" + } + }, + { + "name": "reduceL1 float32 0D constant tensor empty axes", + "inputs": { + "input": { + "shape": [], + "data": [ + 5.50882625579834 + ], + "type": "float32", + "constant": true + } + }, + "options": { + "axes": [] + }, + "expected": { + "name": "output", + "data": 5.50882625579834, + "type": "float32" + } + }, { "name": "reduceL1 float32 1D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} "inputs": { diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_l2.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_l2.json index d83eea9dfb93e..b4d270a701927 100644 --- a/testing/web-platform/tests/webnn/resources/test_data/reduce_l2.json +++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_l2.json @@ -1,5 +1,44 @@ { "tests": [ + { + "name": "reduceL2 float32 0D constant tensor default options", // default options: {axes: null, keepDimensions: false} + "inputs": { + "input": { + "shape": [], + "data": [ + 4.860228061676025 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 4.860228061676025, + "type": "float32" + } + }, + { + "name": "reduceL2 float32 0D constant tensor empty axes", + "inputs": { + "input": { + "shape": [], + "data": [ + 4.860228061676025 + ], + "type": "float32", + "constant": true + } + }, + "options": { + "axes": [] + }, + "expected": { + "name": "output", + "data": 4.860228061676025, + "type": "float32" + } + }, { "name": "reduceL2 float32 1D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} "inputs": { diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum.json index 061e12ad51652..f3de240e458ea 100644 --- a/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum.json +++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum.json @@ -1,5 +1,44 @@ { "tests": [ + { + "name": "reduceLogSum float32 0D constant tensor default options", // default options: {axes: null, keepDimensions: false} + "inputs": { + "input": { + "shape": [], + "data": [ + 64.54827117919922 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 4.167413234710693, + "type": "float32" + } + }, + { + "name": "reduceLogSum float32 0D constant tensor empty axes", + "inputs": { + "input": { + "shape": [], + "data": [ + 64.54827117919922 + ], + "type": "float32", + "constant": true + } + }, + "options": { + "axes": [] + }, + "expected": { + "name": "output", + "data": 4.167413234710693, + "type": "float32" + } + }, { "name": "reduceLogSum float32 1D constant tensor all non-negative default options", // default options: {axes: null, keepDimensions: false} "inputs": { diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum_exp.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum_exp.json index 3577d6aa9ee52..b999a567aa5bb 100644 --- a/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum_exp.json +++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum_exp.json @@ -1,5 +1,44 @@ { "tests": [ + { + "name": "reduceLogSumExp float32 0D constant tensor default options", // default options: {axes: null, keepDimensions: false} + "inputs": { + "input": { + "shape": [], + "data": [ + 0.7974132895469666 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 0.7974132895469666, + "type": "float32" + } + }, + { + "name": "reduceLogSumExp float32 0D constant tensor empty axes", + "inputs": { + "input": { + "shape": [], + "data": [ + 0.7974132895469666 + ], + "type": "float32", + "constant": true + } + }, + "options": { + "axes": [] + }, + "expected": { + "name": "output", + "data": 0.7974132895469666, + "type": "float32" + } + }, { "name": "reduceLogSumExp float32 1D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} "inputs": { diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_max.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_max.json index 11ed0ed919147..6cd55492692dc 100644 --- a/testing/web-platform/tests/webnn/resources/test_data/reduce_max.json +++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_max.json @@ -1,5 +1,44 @@ { "tests": [ + { + "name": "reduceMax float32 0D constant tensor default options", + "inputs": { + "input": { + "shape": [], + "data": [ + 32.16658401489258 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 32.16658401489258, + "type": "float32" + } + }, + { + "name": "reduceMax float32 0D constant tensor empty axes", + "inputs": { + "input": { + "shape": [], + "data": [ + 32.16658401489258 + ], + "type": "float32", + "constant": true + } + }, + "options": { + "axes": [] + }, + "expected": { + "name": "output", + "data": 32.16658401489258, + "type": "float32" + } + }, { "name": "reduceMax float32 1D constant tensor default options", "inputs": { diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_mean.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_mean.json index 8c26d0a5623e5..b990b0f93bba1 100644 --- a/testing/web-platform/tests/webnn/resources/test_data/reduce_mean.json +++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_mean.json @@ -1,5 +1,44 @@ { "tests": [ + { + "name": "reduceMean float32 0D constant tensor default options", + "inputs": { + "input": { + "shape": [], + "data": [ + 95.84498596191406 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 95.84498596191406, + "type": "float32" + } + }, + { + "name": "reduceMean float32 0D constant tensor empty axes", + "inputs": { + "input": { + "shape": [], + "data": [ + 95.84498596191406 + ], + "type": "float32", + "constant": true + } + }, + "options": { + "axes": [] + }, + "expected": { + "name": "output", + "data": 95.84498596191406, + "type": "float32" + } + }, { "name": "reduceMean float32 1D constant tensor all positive default options", "inputs": { diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_min.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_min.json index 6c26df5db16d9..4d91480bb95a0 100644 --- a/testing/web-platform/tests/webnn/resources/test_data/reduce_min.json +++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_min.json @@ -1,5 +1,44 @@ { "tests": [ + { + "name": "reduceMin float32 0D constant tensor default options", + "inputs": { + "input": { + "shape": [], + "data": [ + -58.76195526123047 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": -58.76195526123047, + "type": "float32" + } + }, + { + "name": "reduceMin float32 0D constant tensor empty axes", + "inputs": { + "input": { + "shape": [], + "data": [ + -58.76195526123047 + ], + "type": "float32", + "constant": true + } + }, + "options": { + "axes": [] + }, + "expected": { + "name": "output", + "data": -58.76195526123047, + "type": "float32" + } + }, { "name": "reduceMin float32 1D constant tensor default options", "inputs": { diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_product.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_product.json index d58af30ec1af6..e9b2dc34c2689 100644 --- a/testing/web-platform/tests/webnn/resources/test_data/reduce_product.json +++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_product.json @@ -1,5 +1,44 @@ { "tests": [ + { + "name": "reduceProduct float32 0D constant tensor default options", + "inputs": { + "input": { + "shape": [], + "data": [ + -68.75911712646484 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": -68.75911712646484, + "type": "float32" + } + }, + { + "name": "reduceProduct float32 0D constant tensor empty axes", + "inputs": { + "input": { + "shape": [], + "data": [ + -68.75911712646484 + ], + "type": "float32", + "constant": true + } + }, + "options": { + "axes": [] + }, + "expected": { + "name": "output", + "data": -68.75911712646484, + "type": "float32" + } + }, { "name": "reduceProduct float32 1D constant tensor default options", "inputs": { diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_sum.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_sum.json index 7027d38b67699..fd93e131b3e29 100644 --- a/testing/web-platform/tests/webnn/resources/test_data/reduce_sum.json +++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_sum.json @@ -1,5 +1,44 @@ { "tests": [ + { + "name": "reduceSum float32 0D constant tensor default options", + "inputs": { + "input": { + "shape": [], + "data": [ + 69.6038589477539 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 69.6038589477539, + "type": "float32" + } + }, + { + "name": "reduceSum float32 0D constant tensor empty axes", + "inputs": { + "input": { + "shape": [], + "data": [ + 69.6038589477539 + ], + "type": "float32", + "constant": true + } + }, + "options": { + "axes": [] + }, + "expected": { + "name": "output", + "data": 69.6038589477539, + "type": "float32" + } + }, { "name": "reduceSum float32 1D constant tensor all positive default options", "inputs": { diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_sum_square.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_sum_square.json index bd2ebb341a7c0..d308cad463a29 100644 --- a/testing/web-platform/tests/webnn/resources/test_data/reduce_sum_square.json +++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_sum_square.json @@ -1,5 +1,44 @@ { "tests": [ + { + "name": "reduceSumSquare float32 0D constant tensor default options", + "inputs": { + "input": { + "shape": [], + "data": [ + 52.5615348815918 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 2762.71484375, + "type": "float32" + } + }, + { + "name": "reduceSumSquare float32 0D constant tensor empty axes", + "inputs": { + "input": { + "shape": [], + "data": [ + 52.5615348815918 + ], + "type": "float32", + "constant": true + } + }, + "options": { + "axes": [] + }, + "expected": { + "name": "output", + "data": 2762.71484375, + "type": "float32" + } + }, { "name": "reduceSumSquare float32 1D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} "inputs": { diff --git a/testing/web-platform/tests/webnn/resources/utils.js b/testing/web-platform/tests/webnn/resources/utils.js index c231f46bcf522..0d3443b3dc955 100644 --- a/testing/web-platform/tests/webnn/resources/utils.js +++ b/testing/web-platform/tests/webnn/resources/utils.js @@ -274,9 +274,9 @@ const getReductionPrecisionTolerance = (resources, operationName) => { } else { sizes = inputShape; } - const reducedElementCount = sizes.reduce( - (accumulator, currentValue) => accumulator * currentValue - ); + const reducedElementCount = sizes.length ? + sizes.reduce((accumulator, currentValue) => accumulator * currentValue) : + 1; let tolerance; switch (operationName) { case 'reduceL1':