From 9a222ab4faf2bde193a7e44bc5b0364c19545111 Mon Sep 17 00:00:00 2001 From: BruceDai Date: Mon, 9 Dec 2024 20:14:10 +0800 Subject: [PATCH] address comments --- test/tools/README.md | 4 +- test/tools/gen-operator-with-single-input.js | 17 +- test/tools/resources/gelu.json | 116 +-- test/tools/resources/softsign.json | 122 +-- test/tools/test-data-wpt/gelu.json | 784 ---------------- test/tools/test-data-wpt/softsign.json | 884 ------------------- test/tools/test-data/gelu-data.json | 93 -- test/tools/test-data/softsign-data.json | 240 ----- test/tools/utils.js | 175 ++-- 9 files changed, 255 insertions(+), 2180 deletions(-) delete mode 100644 test/tools/test-data-wpt/gelu.json delete mode 100644 test/tools/test-data-wpt/softsign.json delete mode 100644 test/tools/test-data/gelu-data.json delete mode 100644 test/tools/test-data/softsign-data.json diff --git a/test/tools/README.md b/test/tools/README.md index b4058d5..b4fad0e 100644 --- a/test/tools/README.md +++ b/test/tools/README.md @@ -17,8 +17,8 @@ Take an example for softsign operator tests: node gen-operator-with-single-input.js resources\softsign.json ``` -then, you can find two generated folders named 'test-data' and -'test-data-wpt'. There're raw test data as being +Then you can find two generated folders named 'test-data' and +'test-data-wpt'. They're raw test data as being ./test-data/softsign-data.json, and raw WPT test-data file as being ./test-data-wpt/softsign.json. diff --git a/test/tools/gen-operator-with-single-input.js b/test/tools/gen-operator-with-single-input.js index 6725aee..102d7bb 100644 --- a/test/tools/gen-operator-with-single-input.js +++ b/test/tools/gen-operator-with-single-input.js @@ -15,8 +15,7 @@ import {utils} from './utils.js'; 'softsign': softsign, }; const inputTensor = new Tensor(input.shape, input.data); - const outputTensor = - operatorMappingDict[operatorName](inputTensor, options); + const outputTensor = operatorMappingDict[operatorName](inputTensor, options); return outputTensor.data; } @@ -28,21 +27,20 @@ import {utils} from './utils.js'; `${operatorString}-data.json`); const jsonDict = utils.readJsonFile(process.argv[2]); const inputsDataInfo = jsonDict.inputsData; - const inputsDataRange = jsonDict.inputsDataRange; const toSaveDataDict = utils.prepareInputsData( - inputsDataInfo, savedDataFile, inputsDataRange.min, inputsDataRange.max); + inputsDataInfo, savedDataFile, jsonDict.inputsDataRange); toSaveDataDict['expectedData'] = {}; const tests = jsonDict.tests; const wptTests = JSON.parse(JSON.stringify(tests)); for (const test of tests) { - console.log(`name ${test.name}`); + console.log(`Test case name: ${test.name}`); const precisionDataInput = utils.getPrecisionDataFromDataDict( toSaveDataDict['inputsData'], test.inputs.input.data, - test.inputs.input.type); + test.inputs.input.dataType); const input = {shape: test.inputs.input.shape, data: precisionDataInput}; const result = computeBySingleInput(operatorString, input, test.options); toSaveDataDict['expectedData'][test.expected.data] = - utils.getPrecisionData(result, test.expected.type); + utils.getPrecisionData(result, test.expected.dataType); } utils.writeJsonFile(toSaveDataDict, savedDataFile); @@ -59,7 +57,7 @@ import {utils} from './utils.js'; test.inputs[inputName].data : utils.getPrecisionDataFromDataDict( toSaveDataDict['inputsData'], test.inputs[inputName].data, - test.inputs[inputName].type); + test.inputs[inputName].dataType); } // update weights (scale, bias, and etc.) data of options if (test.options) { @@ -74,9 +72,10 @@ import {utils} from './utils.js'; test.expected.data = toSaveDataDict['expectedData'][test.expected.data]; wptConformanceTestsDict.tests.push(test); } + const savedWPTDataFile = path.join( path.dirname(process.argv[1]), 'test-data-wpt', `${operatorString}.json`); utils.writeJsonFile(wptConformanceTestsDict, savedWPTDataFile); - console.log(`[ Done ] Generate test data file for WPT tests.`); + console.log(`[ Done ] Generate test data file ${savedWPTDataFile} for WPT tests.`); })(); diff --git a/test/tools/resources/gelu.json b/test/tools/resources/gelu.json index be2d0ce..1314ae0 100644 --- a/test/tools/resources/gelu.json +++ b/test/tools/resources/gelu.json @@ -5,15 +5,15 @@ "inputs": { "input": { "shape": [], - "data": "float64DataScalar", - "type": "float32" + "data": "float32DataScalarInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [], - "data": "float32DataScalar", - "type": "float32" + "data": "float32DataScalarOutput", + "dataType": "float32" } }, { @@ -21,15 +21,15 @@ "inputs": { "input": { "shape": [], - "data": "float64DataScalar", - "type": "float16" + "data": "float16DataScalarInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [], - "data": "float16DataScalar", - "type": "float16" + "data": "float16DataScalarOutput", + "dataType": "float16" } }, { @@ -37,15 +37,15 @@ "inputs": { "input": { "shape": [24], - "data": "float64Data", - "type": "float32" + "data": "float32DataInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [24], - "data": "float32Data", - "type": "float32" + "data": "float32DataOutput", + "dataType": "float32" } }, { @@ -53,15 +53,15 @@ "inputs": { "input": { "shape": [24], - "data": "float64Data", - "type": "float16" + "data": "float16DataInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [24], - "data": "float16Data", - "type": "float16" + "data": "float16DataOutput", + "dataType": "float16" } }, { @@ -69,15 +69,15 @@ "inputs": { "input": { "shape": [4, 6], - "data": "float64Data", - "type": "float32" + "data": "float32DataInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [4, 6], - "data": "float32Data", - "type": "float32" + "data": "float32DataOutput", + "dataType": "float32" } }, { @@ -85,15 +85,15 @@ "inputs": { "input": { "shape": [4, 6], - "data": "float64Data", - "type": "float16" + "data": "float16DataInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [4, 6], - "data": "float16Data", - "type": "float16" + "data": "float16DataOutput", + "dataType": "float16" } }, { @@ -101,15 +101,15 @@ "inputs": { "input": { "shape": [2, 3, 4], - "data": "float64Data", - "type": "float32" + "data": "float32DataInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [2, 3, 4], - "data": "float32Data", - "type": "float32" + "data": "float32DataOutput", + "dataType": "float32" } }, { @@ -117,15 +117,15 @@ "inputs": { "input": { "shape": [2, 3, 4], - "data": "float64Data", - "type": "float16" + "data": "float16DataInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [2, 3, 4], - "data": "float16Data", - "type": "float16" + "data": "float16DataOutput", + "dataType": "float16" } }, { @@ -133,15 +133,15 @@ "inputs": { "input": { "shape": [2, 2, 2, 3], - "data": "float64Data", - "type": "float32" + "data": "float32DataInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [2, 2, 2, 3], - "data": "float32Data", - "type": "float32" + "data": "float32DataOutput", + "dataType": "float32" } }, { @@ -149,15 +149,15 @@ "inputs": { "input": { "shape": [2, 2, 2, 3], - "data": "float64Data", - "type": "float16" + "data": "float16DataInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [2, 2, 2, 3], - "data": "float16Data", - "type": "float16" + "data": "float16DataOutput", + "dataType": "float16" } }, { @@ -165,15 +165,15 @@ "inputs": { "input": { "shape": [2, 1, 4, 1, 3], - "data": "float64Data", - "type": "float32" + "data": "float32DataInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [2, 1, 4, 1, 3], - "data": "float32Data", - "type": "float32" + "data": "float32DataOutput", + "dataType": "float32" } }, { @@ -181,30 +181,38 @@ "inputs": { "input": { "shape": [2, 1, 4, 1, 3], - "data": "float64Data", - "type": "float16" + "data": "float16DataInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [2, 1, 4, 1, 3], - "data": "float16Data", - "type": "float16" + "data": "float16DataOutput", + "dataType": "float16" } } ], "inputsData": { - "float64DataScalar": { + "float32DataScalarInput": { "shape": [1], - "type": "float64" + "dataType": "float32" + }, + "float32DataInput": { + "shape": [24], + "dataType": "float32" + }, + "float16DataScalarInput": { + "shape": [1], + "dataType": "float16" }, - "float64Data": { + "float16DataInput": { "shape": [24], - "type": "float64" + "dataType": "float16" } }, "inputsDataRange": { - "max": 1, - "min": -1 + "max": 1, + "min": -1 } } \ No newline at end of file diff --git a/test/tools/resources/softsign.json b/test/tools/resources/softsign.json index b103cfa..590fc00 100644 --- a/test/tools/resources/softsign.json +++ b/test/tools/resources/softsign.json @@ -5,15 +5,15 @@ "inputs": { "input": { "shape": [24], - "data": "float641DPositiveInput", - "type": "float32" + "data": "float32_1DPositiveInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [24], - "data": "float321DPositiveDefault", - "type": "float32" + "data": "float32_1DPositiveDefault", + "dataType": "float32" } }, { @@ -21,15 +21,15 @@ "inputs": { "input": { "shape": [24], - "data": "float641DNegativeInput", - "type": "float32" + "data": "float32_1DNegativeInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [24], - "data": "float321DNegativeDefault", - "type": "float32" + "data": "float32_1DNegativeDefault", + "dataType": "float32" } }, { @@ -37,15 +37,15 @@ "inputs": { "input": { "shape": [4, 6], - "data": "float642DInput", - "type": "float32" + "data": "float32_2DInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [4, 6], - "data": "float322DDefault", - "type": "float32" + "data": "float32_2DDefault", + "dataType": "float32" } }, { @@ -53,15 +53,15 @@ "inputs": { "input": { "shape": [2, 3, 4], - "data": "float642DInput", - "type": "float32" + "data": "float32_2DInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [2, 3, 4], - "data": "float322DDefault", - "type": "float32" + "data": "float32_2DDefault", + "dataType": "float32" } }, { @@ -69,15 +69,15 @@ "inputs": { "input": { "shape": [1, 2, 3, 4], - "data": "float642DInput", - "type": "float32" + "data": "float32_2DInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [1, 2, 3, 4], - "data": "float322DDefault", - "type": "float32" + "data": "float32_2DDefault", + "dataType": "float32" } }, { @@ -85,15 +85,15 @@ "inputs": { "input": { "shape": [1, 2, 1, 3, 4], - "data": "float642DInput", - "type": "float32" + "data": "float32_2DInput", + "dataType": "float32" } }, "expected": { "name": "output", "shape": [1, 2, 1, 3, 4], - "data": "float322DDefault", - "type": "float32" + "data": "float32_2DDefault", + "dataType": "float32" } }, { @@ -101,15 +101,15 @@ "inputs": { "input": { "shape": [24], - "data": "float641DPositiveInput", - "type": "float16" + "data": "float16_1DPositiveInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [24], - "data": "float161DPositiveDefault", - "type": "float16" + "data": "float16_1DPositiveDefault", + "dataType": "float16" } }, { @@ -117,15 +117,15 @@ "inputs": { "input": { "shape": [24], - "data": "float641DNegativeInput", - "type": "float16" + "data": "float16_1DNegativeInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [24], - "data": "float161DNegativeDefault", - "type": "float16" + "data": "float16_1DNegativeDefault", + "dataType": "float16" } }, { @@ -133,15 +133,15 @@ "inputs": { "input": { "shape": [4, 6], - "data": "float642DInput", - "type": "float16" + "data": "float16_2DInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [4, 6], - "data": "float162DDefault", - "type": "float16" + "data": "float16_2DDefault", + "dataType": "float16" } }, { @@ -149,15 +149,15 @@ "inputs": { "input": { "shape": [2, 3, 4], - "data": "float642DInput", - "type": "float16" + "data": "float16_2DInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [2, 3, 4], - "data": "float162DDefault", - "type": "float16" + "data": "float16_2DDefault", + "dataType": "float16" } }, { @@ -165,15 +165,15 @@ "inputs": { "input": { "shape": [1, 2, 3, 4], - "data": "float642DInput", - "type": "float16" + "data": "float16_2DInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [1, 2, 3, 4], - "data": "float162DDefault", - "type": "float16" + "data": "float16_2DDefault", + "dataType": "float16" } }, { @@ -181,32 +181,46 @@ "inputs": { "input": { "shape": [1, 2, 1, 3, 4], - "data": "float642DInput", - "type": "float16" + "data": "float16_2DInput", + "dataType": "float16" } }, "expected": { "name": "output", "shape": [1, 2, 1, 3, 4], - "data": "float162DDefault", - "type": "float16" + "data": "float16_2DDefault", + "dataType": "float16" } } ], "inputsData": { - "float641DPositiveInput": { + "float32_1DPositiveInput": { "shape": [24], - "type": "float64", + "dataType": "float32", "sign": "positive" }, - "float641DNegativeInput": { + "float32_1DNegativeInput": { "shape": [24], - "type": "float64", + "dataType": "float32", "sign": "negative" }, - "float642DInput": { + "float32_2DInput": { "shape": [24], - "type": "float64" + "dataType": "float32" + }, + "float16_1DPositiveInput": { + "shape": [24], + "dataType": "float16", + "sign": "positive" + }, + "float16_1DNegativeInput": { + "shape": [24], + "dataType": "float16", + "sign": "negative" + }, + "float16_2DInput": { + "shape": [24], + "dataType": "float16" } }, "inputsDataRange": { diff --git a/test/tools/test-data-wpt/gelu.json b/test/tools/test-data-wpt/gelu.json deleted file mode 100644 index a22684b..0000000 --- a/test/tools/test-data-wpt/gelu.json +++ /dev/null @@ -1,784 +0,0 @@ -{ - "tests": [ - { - "name": "gelu float32 0D scalar", - "inputs": { - "input": { - "shape": [], - "data": [ - -0.044885843992233276 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [], - "data": [ - -0.021639423444867134 - ], - "type": "float32" - } - }, - { - "name": "gelu float16 0D scalar", - "inputs": { - "input": { - "shape": [], - "data": [ - -0.044891357421875 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [], - "data": [ - -0.021636962890625 - ], - "type": "float16" - } - }, - { - "name": "gelu float32 1D tensor", - "inputs": { - "input": { - "shape": [ - 24 - ], - "data": [ - 0.878292441368103, - -0.09706497937440872, - 0.1367187649011612, - 0.46406492590904236, - -0.26635801792144775, - -0.8252315521240234, - 0.8530909419059753, - 0.3846154808998108, - 0.6772316694259644, - -0.4811072051525116, - 0.2983909249305725, - 0.6777864098548889, - -0.526228129863739, - 0.3497541546821594, - -0.12918996810913086, - 0.5853934288024902, - -0.8950720429420471, - 0.028302494436502457, - -0.09901237487792969, - -0.8838679790496826, - -0.596120297908783, - 0.31863871216773987, - 0.4794037640094757, - -0.06489315629005432 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 24 - ], - "data": [ - 0.7115113139152527, - -0.0447796992957592, - 0.07579325884580612, - 0.3149605691432953, - -0.10520657151937485, - -0.16885890066623688, - 0.6851989030838013, - 0.24989959597587585, - 0.508513331413269, - -0.1516546905040741, - 0.18419598042964935, - 0.509049117565155, - -0.15753419697284698, - 0.22270187735557556, - -0.05795508995652199, - 0.42198580503463745, - -0.1659233123064041, - 0.014470770955085754, - -0.04560155048966408, - -0.1665063202381134, - -0.1642593890428543, - 0.19914908707141876, - 0.3279957175254822, - -0.030767757445573807 - ], - "type": "float32" - } - }, - { - "name": "gelu float16 1D tensor", - "inputs": { - "input": { - "shape": [ - 24 - ], - "data": [ - 0.87841796875, - -0.0970458984375, - 0.13671875, - 0.464111328125, - -0.266357421875, - -0.8251953125, - 0.85302734375, - 0.384521484375, - 0.67724609375, - -0.481201171875, - 0.29833984375, - 0.677734375, - -0.5263671875, - 0.349853515625, - -0.129150390625, - 0.58544921875, - -0.89501953125, - 0.0283050537109375, - -0.0989990234375, - -0.8837890625, - -0.59619140625, - 0.318603515625, - 0.4794921875, - -0.06488037109375 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 24 - ], - "data": [ - 0.71142578125, - -0.044769287109375, - 0.0758056640625, - 0.31494140625, - -0.105224609375, - -0.1688232421875, - 0.68505859375, - 0.2498779296875, - 0.50830078125, - -0.151611328125, - 0.1842041015625, - 0.5087890625, - -0.1575927734375, - 0.2227783203125, - -0.057952880859375, - 0.422119140625, - -0.1658935546875, - 0.01447296142578125, - -0.04559326171875, - -0.16650390625, - -0.164306640625, - 0.1990966796875, - 0.328125, - -0.03076171875 - ], - "type": "float16" - } - }, - { - "name": "gelu float32 2D tensor", - "inputs": { - "input": { - "shape": [ - 4, - 6 - ], - "data": [ - 0.878292441368103, - -0.09706497937440872, - 0.1367187649011612, - 0.46406492590904236, - -0.26635801792144775, - -0.8252315521240234, - 0.8530909419059753, - 0.3846154808998108, - 0.6772316694259644, - -0.4811072051525116, - 0.2983909249305725, - 0.6777864098548889, - -0.526228129863739, - 0.3497541546821594, - -0.12918996810913086, - 0.5853934288024902, - -0.8950720429420471, - 0.028302494436502457, - -0.09901237487792969, - -0.8838679790496826, - -0.596120297908783, - 0.31863871216773987, - 0.4794037640094757, - -0.06489315629005432 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 4, - 6 - ], - "data": [ - 0.7115113139152527, - -0.0447796992957592, - 0.07579325884580612, - 0.3149605691432953, - -0.10520657151937485, - -0.16885890066623688, - 0.6851989030838013, - 0.24989959597587585, - 0.508513331413269, - -0.1516546905040741, - 0.18419598042964935, - 0.509049117565155, - -0.15753419697284698, - 0.22270187735557556, - -0.05795508995652199, - 0.42198580503463745, - -0.1659233123064041, - 0.014470770955085754, - -0.04560155048966408, - -0.1665063202381134, - -0.1642593890428543, - 0.19914908707141876, - 0.3279957175254822, - -0.030767757445573807 - ], - "type": "float32" - } - }, - { - "name": "gelu float16 2D tensor", - "inputs": { - "input": { - "shape": [ - 4, - 6 - ], - "data": [ - 0.87841796875, - -0.0970458984375, - 0.13671875, - 0.464111328125, - -0.266357421875, - -0.8251953125, - 0.85302734375, - 0.384521484375, - 0.67724609375, - -0.481201171875, - 0.29833984375, - 0.677734375, - -0.5263671875, - 0.349853515625, - -0.129150390625, - 0.58544921875, - -0.89501953125, - 0.0283050537109375, - -0.0989990234375, - -0.8837890625, - -0.59619140625, - 0.318603515625, - 0.4794921875, - -0.06488037109375 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 4, - 6 - ], - "data": [ - 0.71142578125, - -0.044769287109375, - 0.0758056640625, - 0.31494140625, - -0.105224609375, - -0.1688232421875, - 0.68505859375, - 0.2498779296875, - 0.50830078125, - -0.151611328125, - 0.1842041015625, - 0.5087890625, - -0.1575927734375, - 0.2227783203125, - -0.057952880859375, - 0.422119140625, - -0.1658935546875, - 0.01447296142578125, - -0.04559326171875, - -0.16650390625, - -0.164306640625, - 0.1990966796875, - 0.328125, - -0.03076171875 - ], - "type": "float16" - } - }, - { - "name": "gelu float32 3D tensor", - "inputs": { - "input": { - "shape": [ - 2, - 3, - 4 - ], - "data": [ - 0.878292441368103, - -0.09706497937440872, - 0.1367187649011612, - 0.46406492590904236, - -0.26635801792144775, - -0.8252315521240234, - 0.8530909419059753, - 0.3846154808998108, - 0.6772316694259644, - -0.4811072051525116, - 0.2983909249305725, - 0.6777864098548889, - -0.526228129863739, - 0.3497541546821594, - -0.12918996810913086, - 0.5853934288024902, - -0.8950720429420471, - 0.028302494436502457, - -0.09901237487792969, - -0.8838679790496826, - -0.596120297908783, - 0.31863871216773987, - 0.4794037640094757, - -0.06489315629005432 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 2, - 3, - 4 - ], - "data": [ - 0.7115113139152527, - -0.0447796992957592, - 0.07579325884580612, - 0.3149605691432953, - -0.10520657151937485, - -0.16885890066623688, - 0.6851989030838013, - 0.24989959597587585, - 0.508513331413269, - -0.1516546905040741, - 0.18419598042964935, - 0.509049117565155, - -0.15753419697284698, - 0.22270187735557556, - -0.05795508995652199, - 0.42198580503463745, - -0.1659233123064041, - 0.014470770955085754, - -0.04560155048966408, - -0.1665063202381134, - -0.1642593890428543, - 0.19914908707141876, - 0.3279957175254822, - -0.030767757445573807 - ], - "type": "float32" - } - }, - { - "name": "gelu float16 3D tensor", - "inputs": { - "input": { - "shape": [ - 2, - 3, - 4 - ], - "data": [ - 0.87841796875, - -0.0970458984375, - 0.13671875, - 0.464111328125, - -0.266357421875, - -0.8251953125, - 0.85302734375, - 0.384521484375, - 0.67724609375, - -0.481201171875, - 0.29833984375, - 0.677734375, - -0.5263671875, - 0.349853515625, - -0.129150390625, - 0.58544921875, - -0.89501953125, - 0.0283050537109375, - -0.0989990234375, - -0.8837890625, - -0.59619140625, - 0.318603515625, - 0.4794921875, - -0.06488037109375 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 2, - 3, - 4 - ], - "data": [ - 0.71142578125, - -0.044769287109375, - 0.0758056640625, - 0.31494140625, - -0.105224609375, - -0.1688232421875, - 0.68505859375, - 0.2498779296875, - 0.50830078125, - -0.151611328125, - 0.1842041015625, - 0.5087890625, - -0.1575927734375, - 0.2227783203125, - -0.057952880859375, - 0.422119140625, - -0.1658935546875, - 0.01447296142578125, - -0.04559326171875, - -0.16650390625, - -0.164306640625, - 0.1990966796875, - 0.328125, - -0.03076171875 - ], - "type": "float16" - } - }, - { - "name": "gelu float32 4D tensor", - "inputs": { - "input": { - "shape": [ - 2, - 2, - 2, - 3 - ], - "data": [ - 0.878292441368103, - -0.09706497937440872, - 0.1367187649011612, - 0.46406492590904236, - -0.26635801792144775, - -0.8252315521240234, - 0.8530909419059753, - 0.3846154808998108, - 0.6772316694259644, - -0.4811072051525116, - 0.2983909249305725, - 0.6777864098548889, - -0.526228129863739, - 0.3497541546821594, - -0.12918996810913086, - 0.5853934288024902, - -0.8950720429420471, - 0.028302494436502457, - -0.09901237487792969, - -0.8838679790496826, - -0.596120297908783, - 0.31863871216773987, - 0.4794037640094757, - -0.06489315629005432 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 2, - 2, - 2, - 3 - ], - "data": [ - 0.7115113139152527, - -0.0447796992957592, - 0.07579325884580612, - 0.3149605691432953, - -0.10520657151937485, - -0.16885890066623688, - 0.6851989030838013, - 0.24989959597587585, - 0.508513331413269, - -0.1516546905040741, - 0.18419598042964935, - 0.509049117565155, - -0.15753419697284698, - 0.22270187735557556, - -0.05795508995652199, - 0.42198580503463745, - -0.1659233123064041, - 0.014470770955085754, - -0.04560155048966408, - -0.1665063202381134, - -0.1642593890428543, - 0.19914908707141876, - 0.3279957175254822, - -0.030767757445573807 - ], - "type": "float32" - } - }, - { - "name": "gelu float16 4D tensor", - "inputs": { - "input": { - "shape": [ - 2, - 2, - 2, - 3 - ], - "data": [ - 0.87841796875, - -0.0970458984375, - 0.13671875, - 0.464111328125, - -0.266357421875, - -0.8251953125, - 0.85302734375, - 0.384521484375, - 0.67724609375, - -0.481201171875, - 0.29833984375, - 0.677734375, - -0.5263671875, - 0.349853515625, - -0.129150390625, - 0.58544921875, - -0.89501953125, - 0.0283050537109375, - -0.0989990234375, - -0.8837890625, - -0.59619140625, - 0.318603515625, - 0.4794921875, - -0.06488037109375 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 2, - 2, - 2, - 3 - ], - "data": [ - 0.71142578125, - -0.044769287109375, - 0.0758056640625, - 0.31494140625, - -0.105224609375, - -0.1688232421875, - 0.68505859375, - 0.2498779296875, - 0.50830078125, - -0.151611328125, - 0.1842041015625, - 0.5087890625, - -0.1575927734375, - 0.2227783203125, - -0.057952880859375, - 0.422119140625, - -0.1658935546875, - 0.01447296142578125, - -0.04559326171875, - -0.16650390625, - -0.164306640625, - 0.1990966796875, - 0.328125, - -0.03076171875 - ], - "type": "float16" - } - }, - { - "name": "gelu float32 5D tensor", - "inputs": { - "input": { - "shape": [ - 2, - 1, - 4, - 1, - 3 - ], - "data": [ - 0.878292441368103, - -0.09706497937440872, - 0.1367187649011612, - 0.46406492590904236, - -0.26635801792144775, - -0.8252315521240234, - 0.8530909419059753, - 0.3846154808998108, - 0.6772316694259644, - -0.4811072051525116, - 0.2983909249305725, - 0.6777864098548889, - -0.526228129863739, - 0.3497541546821594, - -0.12918996810913086, - 0.5853934288024902, - -0.8950720429420471, - 0.028302494436502457, - -0.09901237487792969, - -0.8838679790496826, - -0.596120297908783, - 0.31863871216773987, - 0.4794037640094757, - -0.06489315629005432 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 2, - 1, - 4, - 1, - 3 - ], - "data": [ - 0.7115113139152527, - -0.0447796992957592, - 0.07579325884580612, - 0.3149605691432953, - -0.10520657151937485, - -0.16885890066623688, - 0.6851989030838013, - 0.24989959597587585, - 0.508513331413269, - -0.1516546905040741, - 0.18419598042964935, - 0.509049117565155, - -0.15753419697284698, - 0.22270187735557556, - -0.05795508995652199, - 0.42198580503463745, - -0.1659233123064041, - 0.014470770955085754, - -0.04560155048966408, - -0.1665063202381134, - -0.1642593890428543, - 0.19914908707141876, - 0.3279957175254822, - -0.030767757445573807 - ], - "type": "float32" - } - }, - { - "name": "gelu float16 5D tensor", - "inputs": { - "input": { - "shape": [ - 2, - 1, - 4, - 1, - 3 - ], - "data": [ - 0.87841796875, - -0.0970458984375, - 0.13671875, - 0.464111328125, - -0.266357421875, - -0.8251953125, - 0.85302734375, - 0.384521484375, - 0.67724609375, - -0.481201171875, - 0.29833984375, - 0.677734375, - -0.5263671875, - 0.349853515625, - -0.129150390625, - 0.58544921875, - -0.89501953125, - 0.0283050537109375, - -0.0989990234375, - -0.8837890625, - -0.59619140625, - 0.318603515625, - 0.4794921875, - -0.06488037109375 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 2, - 1, - 4, - 1, - 3 - ], - "data": [ - 0.71142578125, - -0.044769287109375, - 0.0758056640625, - 0.31494140625, - -0.105224609375, - -0.1688232421875, - 0.68505859375, - 0.2498779296875, - 0.50830078125, - -0.151611328125, - 0.1842041015625, - 0.5087890625, - -0.1575927734375, - 0.2227783203125, - -0.057952880859375, - 0.422119140625, - -0.1658935546875, - 0.01447296142578125, - -0.04559326171875, - -0.16650390625, - -0.164306640625, - 0.1990966796875, - 0.328125, - -0.03076171875 - ], - "type": "float16" - } - } - ] -} \ No newline at end of file diff --git a/test/tools/test-data-wpt/softsign.json b/test/tools/test-data-wpt/softsign.json deleted file mode 100644 index e185e3d..0000000 --- a/test/tools/test-data-wpt/softsign.json +++ /dev/null @@ -1,884 +0,0 @@ -{ - "tests": [ - { - "name": "softsign positive float32 1D tensor", - "inputs": { - "input": { - "shape": [ - 24 - ], - "data": [ - 1.5834133625030518, - 4.078719139099121, - 8.883357048034668, - 8.070859909057617, - 8.211773872375488, - 2.4554004669189453, - 0.653374195098877, - 7.866281032562256, - 3.123955249786377, - 8.013792037963867, - 3.940986156463623, - 1.813172698020935, - 2.3906760215759277, - 1.335968017578125, - 9.416410446166992, - 0.4432569146156311, - 5.236661911010742, - 9.42424201965332, - 7.816190242767334, - 5.849185943603516, - 8.780370712280273, - 5.120515823364258, - 7.117222309112549, - 4.599106788635254 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 24 - ], - "data": [ - 0.6129152178764343, - 0.8030999898910522, - 0.8988198041915894, - 0.8897568583488464, - 0.8914432525634766, - 0.7105979323387146, - 0.3951762318611145, - 0.8872131109237671, - 0.7575143575668335, - 0.8890588879585266, - 0.7976112365722656, - 0.6445294618606567, - 0.7050735354423523, - 0.5719119310379028, - 0.9039976596832275, - 0.30712267756462097, - 0.8396578431129456, - 0.9040697813034058, - 0.8865723013877869, - 0.8539972305297852, - 0.8977543711662292, - 0.8366150856018066, - 0.8768051266670227, - 0.8214001059532166 - ], - "type": "float32" - } - }, - { - "name": "softsign negative float32 1D tensor", - "inputs": { - "input": { - "shape": [ - 24 - ], - "data": [ - -2.597844123840332, - -0.4449555575847626, - -9.095475196838379, - -3.7480077743530273, - -1.3867290019989014, - -8.220329284667969, - -3.538342237472534, - -9.364588737487793, - -6.283252239227295, - -5.002012252807617, - -8.245729446411133, - -3.775470495223999, - -4.087255001068115, - -7.381676197052002, - -5.8829216957092285, - -8.338910102844238, - -6.60154914855957, - -4.491941928863525, - -3.5247786045074463, - -4.43991231918335, - -5.234262466430664, - -1.5911732912063599, - -9.106277465820312, - -8.523774147033691 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 24 - ], - "data": [ - -0.7220557928085327, - -0.3079372048377991, - -0.9009457230567932, - -0.7893853783607483, - -0.5810165405273438, - -0.891543984413147, - -0.7796552181243896, - -0.9035176634788513, - -0.8626986742019653, - -0.8333892226219177, - -0.8918419480323792, - -0.7905965447425842, - -0.8034303188323975, - -0.8806921243667603, - -0.8547128438949585, - -0.8929211497306824, - -0.8684478402137756, - -0.8179150223731995, - -0.7789947390556335, - -0.8161734938621521, - -0.8395960927009583, - -0.6140744686126709, - -0.9010515809059143, - -0.894999623298645 - ], - "type": "float32" - } - }, - { - "name": "softsign float32 2D tensor", - "inputs": { - "input": { - "shape": [ - 4, - 6 - ], - "data": [ - -8.343496322631836, - -6.920152187347412, - 2.699638843536377, - -8.663105010986328, - -3.1905343532562256, - 7.657886981964111, - 6.650215148925781, - 6.058011054992676, - 0.6634320616722107, - 5.8058037757873535, - -0.32821124792099, - 1.2704304456710815, - -9.946120262145996, - 6.905375003814697, - -0.031071536242961884, - -3.9696409702301025, - 6.270823001861572, - -2.639260768890381, - 3.0513505935668945, - 7.426476955413818, - -8.454667091369629, - 7.135868072509766, - -4.986093997955322, - -7.859614849090576 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 4, - 6 - ], - "data": [ - -0.8929736614227295, - -0.8737397789955139, - 0.7297033667564392, - -0.8965135812759399, - -0.7613669633865356, - 0.8844983577728271, - 0.8692847490310669, - 0.8583170175552368, - 0.3988332748413086, - 0.8530665636062622, - -0.24710771441459656, - 0.5595548748970032, - -0.9086434245109558, - 0.8735038042068481, - -0.03013519011437893, - -0.798778235912323, - 0.8624640107154846, - -0.7252188920974731, - 0.7531687617301941, - 0.88132643699646, - -0.8942321538925171, - 0.8770874738693237, - -0.8329461812973022, - -0.8871282935142517 - ], - "type": "float32" - } - }, - { - "name": "softsign float32 3D tensor", - "inputs": { - "input": { - "shape": [ - 2, - 3, - 4 - ], - "data": [ - -8.343496322631836, - -6.920152187347412, - 2.699638843536377, - -8.663105010986328, - -3.1905343532562256, - 7.657886981964111, - 6.650215148925781, - 6.058011054992676, - 0.6634320616722107, - 5.8058037757873535, - -0.32821124792099, - 1.2704304456710815, - -9.946120262145996, - 6.905375003814697, - -0.031071536242961884, - -3.9696409702301025, - 6.270823001861572, - -2.639260768890381, - 3.0513505935668945, - 7.426476955413818, - -8.454667091369629, - 7.135868072509766, - -4.986093997955322, - -7.859614849090576 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 2, - 3, - 4 - ], - "data": [ - -0.8929736614227295, - -0.8737397789955139, - 0.7297033667564392, - -0.8965135812759399, - -0.7613669633865356, - 0.8844983577728271, - 0.8692847490310669, - 0.8583170175552368, - 0.3988332748413086, - 0.8530665636062622, - -0.24710771441459656, - 0.5595548748970032, - -0.9086434245109558, - 0.8735038042068481, - -0.03013519011437893, - -0.798778235912323, - 0.8624640107154846, - -0.7252188920974731, - 0.7531687617301941, - 0.88132643699646, - -0.8942321538925171, - 0.8770874738693237, - -0.8329461812973022, - -0.8871282935142517 - ], - "type": "float32" - } - }, - { - "name": "softsign float32 4D tensor", - "inputs": { - "input": { - "shape": [ - 1, - 2, - 3, - 4 - ], - "data": [ - -8.343496322631836, - -6.920152187347412, - 2.699638843536377, - -8.663105010986328, - -3.1905343532562256, - 7.657886981964111, - 6.650215148925781, - 6.058011054992676, - 0.6634320616722107, - 5.8058037757873535, - -0.32821124792099, - 1.2704304456710815, - -9.946120262145996, - 6.905375003814697, - -0.031071536242961884, - -3.9696409702301025, - 6.270823001861572, - -2.639260768890381, - 3.0513505935668945, - 7.426476955413818, - -8.454667091369629, - 7.135868072509766, - -4.986093997955322, - -7.859614849090576 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 1, - 2, - 3, - 4 - ], - "data": [ - -0.8929736614227295, - -0.8737397789955139, - 0.7297033667564392, - -0.8965135812759399, - -0.7613669633865356, - 0.8844983577728271, - 0.8692847490310669, - 0.8583170175552368, - 0.3988332748413086, - 0.8530665636062622, - -0.24710771441459656, - 0.5595548748970032, - -0.9086434245109558, - 0.8735038042068481, - -0.03013519011437893, - -0.798778235912323, - 0.8624640107154846, - -0.7252188920974731, - 0.7531687617301941, - 0.88132643699646, - -0.8942321538925171, - 0.8770874738693237, - -0.8329461812973022, - -0.8871282935142517 - ], - "type": "float32" - } - }, - { - "name": "softsign float32 5D tensor", - "inputs": { - "input": { - "shape": [ - 1, - 2, - 1, - 3, - 4 - ], - "data": [ - -8.343496322631836, - -6.920152187347412, - 2.699638843536377, - -8.663105010986328, - -3.1905343532562256, - 7.657886981964111, - 6.650215148925781, - 6.058011054992676, - 0.6634320616722107, - 5.8058037757873535, - -0.32821124792099, - 1.2704304456710815, - -9.946120262145996, - 6.905375003814697, - -0.031071536242961884, - -3.9696409702301025, - 6.270823001861572, - -2.639260768890381, - 3.0513505935668945, - 7.426476955413818, - -8.454667091369629, - 7.135868072509766, - -4.986093997955322, - -7.859614849090576 - ], - "type": "float32" - } - }, - "expected": { - "name": "output", - "shape": [ - 1, - 2, - 1, - 3, - 4 - ], - "data": [ - -0.8929736614227295, - -0.8737397789955139, - 0.7297033667564392, - -0.8965135812759399, - -0.7613669633865356, - 0.8844983577728271, - 0.8692847490310669, - 0.8583170175552368, - 0.3988332748413086, - 0.8530665636062622, - -0.24710771441459656, - 0.5595548748970032, - -0.9086434245109558, - 0.8735038042068481, - -0.03013519011437893, - -0.798778235912323, - 0.8624640107154846, - -0.7252188920974731, - 0.7531687617301941, - 0.88132643699646, - -0.8942321538925171, - 0.8770874738693237, - -0.8329461812973022, - -0.8871282935142517 - ], - "type": "float32" - } - }, - { - "name": "softsign positive float16 1D tensor", - "inputs": { - "input": { - "shape": [ - 24 - ], - "data": [ - 1.5830078125, - 4.078125, - 8.8828125, - 8.0703125, - 8.2109375, - 2.455078125, - 0.6533203125, - 7.8671875, - 3.123046875, - 8.015625, - 3.94140625, - 1.8134765625, - 2.390625, - 1.3359375, - 9.4140625, - 0.443359375, - 5.23828125, - 9.421875, - 7.81640625, - 5.84765625, - 8.78125, - 5.12109375, - 7.1171875, - 4.59765625 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 24 - ], - "data": [ - 0.61279296875, - 0.80322265625, - 0.89892578125, - 0.8896484375, - 0.8916015625, - 0.71044921875, - 0.395263671875, - 0.88720703125, - 0.75732421875, - 0.88916015625, - 0.7978515625, - 0.64453125, - 0.705078125, - 0.57177734375, - 0.90380859375, - 0.30712890625, - 0.83984375, - 0.90380859375, - 0.88671875, - 0.85400390625, - 0.89794921875, - 0.83642578125, - 0.876953125, - 0.8212890625 - ], - "type": "float16" - } - }, - { - "name": "softsign negative float16 1D tensor", - "inputs": { - "input": { - "shape": [ - 24 - ], - "data": [ - -2.59765625, - -0.445068359375, - -9.09375, - -3.748046875, - -1.38671875, - -8.21875, - -3.5390625, - -9.3671875, - -6.28515625, - -5.00390625, - -8.2421875, - -3.775390625, - -4.0859375, - -7.3828125, - -5.8828125, - -8.3359375, - -6.6015625, - -4.4921875, - -3.525390625, - -4.44140625, - -5.234375, - -1.5908203125, - -9.109375, - -8.5234375 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 24 - ], - "data": [ - -0.72216796875, - -0.30810546875, - -0.90087890625, - -0.78955078125, - -0.5810546875, - -0.8916015625, - -0.77978515625, - -0.9033203125, - -0.86279296875, - -0.83349609375, - -0.8916015625, - -0.79052734375, - -0.80322265625, - -0.880859375, - -0.8544921875, - -0.89306640625, - -0.86865234375, - -0.81787109375, - -0.77880859375, - -0.81640625, - -0.83935546875, - -0.6142578125, - -0.90087890625, - -0.89501953125 - ], - "type": "float16" - } - }, - { - "name": "softsign float16 2D tensor", - "inputs": { - "input": { - "shape": [ - 4, - 6 - ], - "data": [ - -8.34375, - -6.921875, - 2.69921875, - -8.6640625, - -3.19140625, - 7.65625, - 6.6484375, - 6.05859375, - 0.66357421875, - 5.8046875, - -0.328125, - 1.2705078125, - -9.9453125, - 6.90625, - -0.03106689453125, - -3.96875, - 6.26953125, - -2.638671875, - 3.05078125, - 7.42578125, - -8.453125, - 7.13671875, - -4.984375, - -7.859375 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 4, - 6 - ], - "data": [ - -0.89306640625, - -0.87353515625, - 0.7294921875, - -0.896484375, - -0.76123046875, - 0.88427734375, - 0.869140625, - 0.8583984375, - 0.39892578125, - 0.85302734375, - -0.2470703125, - 0.5595703125, - -0.90869140625, - 0.87353515625, - -0.0301361083984375, - -0.798828125, - 0.8623046875, - -0.72509765625, - 0.7529296875, - 0.88134765625, - -0.89404296875, - 0.876953125, - -0.8330078125, - -0.88720703125 - ], - "type": "float16" - } - }, - { - "name": "softsign float16 3D tensor", - "inputs": { - "input": { - "shape": [ - 2, - 3, - 4 - ], - "data": [ - -8.34375, - -6.921875, - 2.69921875, - -8.6640625, - -3.19140625, - 7.65625, - 6.6484375, - 6.05859375, - 0.66357421875, - 5.8046875, - -0.328125, - 1.2705078125, - -9.9453125, - 6.90625, - -0.03106689453125, - -3.96875, - 6.26953125, - -2.638671875, - 3.05078125, - 7.42578125, - -8.453125, - 7.13671875, - -4.984375, - -7.859375 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 2, - 3, - 4 - ], - "data": [ - -0.89306640625, - -0.87353515625, - 0.7294921875, - -0.896484375, - -0.76123046875, - 0.88427734375, - 0.869140625, - 0.8583984375, - 0.39892578125, - 0.85302734375, - -0.2470703125, - 0.5595703125, - -0.90869140625, - 0.87353515625, - -0.0301361083984375, - -0.798828125, - 0.8623046875, - -0.72509765625, - 0.7529296875, - 0.88134765625, - -0.89404296875, - 0.876953125, - -0.8330078125, - -0.88720703125 - ], - "type": "float16" - } - }, - { - "name": "softsign float16 4D tensor", - "inputs": { - "input": { - "shape": [ - 1, - 2, - 3, - 4 - ], - "data": [ - -8.34375, - -6.921875, - 2.69921875, - -8.6640625, - -3.19140625, - 7.65625, - 6.6484375, - 6.05859375, - 0.66357421875, - 5.8046875, - -0.328125, - 1.2705078125, - -9.9453125, - 6.90625, - -0.03106689453125, - -3.96875, - 6.26953125, - -2.638671875, - 3.05078125, - 7.42578125, - -8.453125, - 7.13671875, - -4.984375, - -7.859375 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 1, - 2, - 3, - 4 - ], - "data": [ - -0.89306640625, - -0.87353515625, - 0.7294921875, - -0.896484375, - -0.76123046875, - 0.88427734375, - 0.869140625, - 0.8583984375, - 0.39892578125, - 0.85302734375, - -0.2470703125, - 0.5595703125, - -0.90869140625, - 0.87353515625, - -0.0301361083984375, - -0.798828125, - 0.8623046875, - -0.72509765625, - 0.7529296875, - 0.88134765625, - -0.89404296875, - 0.876953125, - -0.8330078125, - -0.88720703125 - ], - "type": "float16" - } - }, - { - "name": "softsign float16 5D tensor", - "inputs": { - "input": { - "shape": [ - 1, - 2, - 1, - 3, - 4 - ], - "data": [ - -8.34375, - -6.921875, - 2.69921875, - -8.6640625, - -3.19140625, - 7.65625, - 6.6484375, - 6.05859375, - 0.66357421875, - 5.8046875, - -0.328125, - 1.2705078125, - -9.9453125, - 6.90625, - -0.03106689453125, - -3.96875, - 6.26953125, - -2.638671875, - 3.05078125, - 7.42578125, - -8.453125, - 7.13671875, - -4.984375, - -7.859375 - ], - "type": "float16" - } - }, - "expected": { - "name": "output", - "shape": [ - 1, - 2, - 1, - 3, - 4 - ], - "data": [ - -0.89306640625, - -0.87353515625, - 0.7294921875, - -0.896484375, - -0.76123046875, - 0.88427734375, - 0.869140625, - 0.8583984375, - 0.39892578125, - 0.85302734375, - -0.2470703125, - 0.5595703125, - -0.90869140625, - 0.87353515625, - -0.0301361083984375, - -0.798828125, - 0.8623046875, - -0.72509765625, - 0.7529296875, - 0.88134765625, - -0.89404296875, - 0.876953125, - -0.8330078125, - -0.88720703125 - ], - "type": "float16" - } - } - ] -} \ No newline at end of file diff --git a/test/tools/test-data/gelu-data.json b/test/tools/test-data/gelu-data.json deleted file mode 100644 index 534f2bf..0000000 --- a/test/tools/test-data/gelu-data.json +++ /dev/null @@ -1,93 +0,0 @@ -{ - "inputsData": { - "float64DataScalar": [ - -0.044885845624167864 - ], - "float64Data": [ - 0.8782924345704477, - -0.09706497776701806, - 0.1367187672039556, - 0.46406491981662557, - -0.26635802629759375, - -0.8252315662130498, - 0.853090918197347, - 0.3846154905320942, - 0.6772316793454944, - -0.4811071995656535, - 0.29839091278502794, - 0.6777863973820542, - -0.5262281183797937, - 0.3497541608592383, - -0.12918996895751977, - 0.5853934375200058, - -0.8950720643968815, - 0.028302494550672908, - -0.0990123770792839, - -0.8838679808470014, - -0.5961202846499938, - 0.3186387025271662, - 0.4794037697361717, - -0.06489315429048403 - ] - }, - "expectedData": { - "float32DataScalar": [ - -0.021639423444867134 - ], - "float16DataScalar": [ - -0.021636962890625 - ], - "float32Data": [ - 0.7115113139152527, - -0.0447796992957592, - 0.07579325884580612, - 0.3149605691432953, - -0.10520657151937485, - -0.16885890066623688, - 0.6851989030838013, - 0.24989959597587585, - 0.508513331413269, - -0.1516546905040741, - 0.18419598042964935, - 0.509049117565155, - -0.15753419697284698, - 0.22270187735557556, - -0.05795508995652199, - 0.42198580503463745, - -0.1659233123064041, - 0.014470770955085754, - -0.04560155048966408, - -0.1665063202381134, - -0.1642593890428543, - 0.19914908707141876, - 0.3279957175254822, - -0.030767757445573807 - ], - "float16Data": [ - 0.71142578125, - -0.044769287109375, - 0.0758056640625, - 0.31494140625, - -0.105224609375, - -0.1688232421875, - 0.68505859375, - 0.2498779296875, - 0.50830078125, - -0.151611328125, - 0.1842041015625, - 0.5087890625, - -0.1575927734375, - 0.2227783203125, - -0.057952880859375, - 0.422119140625, - -0.1658935546875, - 0.01447296142578125, - -0.04559326171875, - -0.16650390625, - -0.164306640625, - 0.1990966796875, - 0.328125, - -0.03076171875 - ] - } -} \ No newline at end of file diff --git a/test/tools/test-data/softsign-data.json b/test/tools/test-data/softsign-data.json deleted file mode 100644 index d12f0e1..0000000 --- a/test/tools/test-data/softsign-data.json +++ /dev/null @@ -1,240 +0,0 @@ -{ - "inputsData": { - "float641DPositiveInput": [ - 1.5834133593790956, - 4.0787189411490115, - 8.883356617490337, - 8.070860233252166, - 8.211773633019915, - 2.4554003891197818, - 0.653374178120758, - 7.866281154604682, - 3.1239552336192666, - 8.013792390668268, - 3.9409862749371283, - 1.8131727337833081, - 2.390676102273188, - 1.3359680092645565, - 9.416410839467265, - 0.44325690899325254, - 5.236662013213598, - 9.424242359034539, - 7.816190418459348, - 5.849185795081855, - 8.780370640491928, - 5.1205157788312246, - 7.1172223514005095, - 4.59910661262345 - ], - "float641DNegativeInput": [ - -2.5978440095516913, - -0.4449555447737712, - -9.095475232407683, - -3.7480076975512873, - -1.3867289790255697, - -8.220328902868987, - -3.538342320320556, - -9.364588742025619, - -6.283252341501335, - -5.0020120266550006, - -8.245729151019969, - -3.775470497728266, - -4.087254829132392, - -7.3816760861585795, - -5.882921529710956, - -8.338910337100263, - -6.6015492897072185, - -4.491942000901396, - -3.524778486355298, - -4.439912258765581, - -5.2342625634221225, - -1.5911732471016933, - -9.106277545690418, - -8.523774275382141 - ], - "float642DInput": [ - -8.343496173533422, - -6.92015211612679, - 2.699638761922575, - -8.663104577031863, - -3.190534368785616, - 7.657887080586452, - 6.650215091182602, - 6.058011004380681, - 0.6634320403254037, - 5.805803683155526, - -0.32821124531446344, - 1.270430403469046, - -9.946119978610852, - 6.905375202832072, - -0.031071535439890496, - -3.9696409293645862, - 6.270823207970878, - -2.6392608577007914, - 3.051350503137261, - 7.42647683445869, - -8.454667518154086, - 7.135868292466057, - -4.9860941550065885, - -7.859615086397076 - ] - }, - "expectedData": { - "float321DPositiveDefault": [ - 0.6129152178764343, - 0.8030999898910522, - 0.8988198041915894, - 0.8897568583488464, - 0.8914432525634766, - 0.7105979323387146, - 0.3951762318611145, - 0.8872131109237671, - 0.7575143575668335, - 0.8890588879585266, - 0.7976112365722656, - 0.6445294618606567, - 0.7050735354423523, - 0.5719119310379028, - 0.9039976596832275, - 0.30712267756462097, - 0.8396578431129456, - 0.9040697813034058, - 0.8865723013877869, - 0.8539972305297852, - 0.8977543711662292, - 0.8366150856018066, - 0.8768051266670227, - 0.8214001059532166 - ], - "float321DNegativeDefault": [ - -0.7220557928085327, - -0.3079372048377991, - -0.9009457230567932, - -0.7893853783607483, - -0.5810165405273438, - -0.891543984413147, - -0.7796552181243896, - -0.9035176634788513, - -0.8626986742019653, - -0.8333892226219177, - -0.8918419480323792, - -0.7905965447425842, - -0.8034303188323975, - -0.8806921243667603, - -0.8547128438949585, - -0.8929211497306824, - -0.8684478402137756, - -0.8179150223731995, - -0.7789947390556335, - -0.8161734938621521, - -0.8395960927009583, - -0.6140744686126709, - -0.9010515809059143, - -0.894999623298645 - ], - "float322DDefault": [ - -0.8929736614227295, - -0.8737397789955139, - 0.7297033667564392, - -0.8965135812759399, - -0.7613669633865356, - 0.8844983577728271, - 0.8692847490310669, - 0.8583170175552368, - 0.3988332748413086, - 0.8530665636062622, - -0.24710771441459656, - 0.5595548748970032, - -0.9086434245109558, - 0.8735038042068481, - -0.03013519011437893, - -0.798778235912323, - 0.8624640107154846, - -0.7252188920974731, - 0.7531687617301941, - 0.88132643699646, - -0.8942321538925171, - 0.8770874738693237, - -0.8329461812973022, - -0.8871282935142517 - ], - "float161DPositiveDefault": [ - 0.61279296875, - 0.80322265625, - 0.89892578125, - 0.8896484375, - 0.8916015625, - 0.71044921875, - 0.395263671875, - 0.88720703125, - 0.75732421875, - 0.88916015625, - 0.7978515625, - 0.64453125, - 0.705078125, - 0.57177734375, - 0.90380859375, - 0.30712890625, - 0.83984375, - 0.90380859375, - 0.88671875, - 0.85400390625, - 0.89794921875, - 0.83642578125, - 0.876953125, - 0.8212890625 - ], - "float161DNegativeDefault": [ - -0.72216796875, - -0.30810546875, - -0.90087890625, - -0.78955078125, - -0.5810546875, - -0.8916015625, - -0.77978515625, - -0.9033203125, - -0.86279296875, - -0.83349609375, - -0.8916015625, - -0.79052734375, - -0.80322265625, - -0.880859375, - -0.8544921875, - -0.89306640625, - -0.86865234375, - -0.81787109375, - -0.77880859375, - -0.81640625, - -0.83935546875, - -0.6142578125, - -0.90087890625, - -0.89501953125 - ], - "float162DDefault": [ - -0.89306640625, - -0.87353515625, - 0.7294921875, - -0.896484375, - -0.76123046875, - 0.88427734375, - 0.869140625, - 0.8583984375, - 0.39892578125, - 0.85302734375, - -0.2470703125, - 0.5595703125, - -0.90869140625, - 0.87353515625, - -0.0301361083984375, - -0.798828125, - 0.8623046875, - -0.72509765625, - 0.7529296875, - 0.88134765625, - -0.89404296875, - 0.876953125, - -0.8330078125, - -0.88720703125 - ] - } -} \ No newline at end of file diff --git a/test/tools/utils.js b/test/tools/utils.js index a00bfec..713bd27 100644 --- a/test/tools/utils.js +++ b/test/tools/utils.js @@ -13,7 +13,7 @@ import {transpose} from '../../src/transpose.js'; * Convert data as required precision type. * @param {Array} input * @param {String} precisionType - * @return {Array} + * @return {(Array|Number)} */ function getPrecisionData(input, precisionType) { let data; @@ -21,43 +21,48 @@ function getPrecisionData(input, precisionType) { if (isNumber) { input = [input]; } + switch (precisionType) { - case 'float32': - data = new Float32Array(input); - break; case 'float16': data = new Float16Array(input); break; - case 'float64': - data = new Float64Array(input); + case 'float32': + data = new Float32Array(input); + break; + case 'int8': + data = new Int8Array(input); break; case 'uint8': data = new Uint8Array(input); break; + case 'int32': + data = new Int32Array(input); + break; case 'uint32': data = new Uint32Array(input); break; case 'int64': - // data = new BigInt64Array(input.map(x => BigInt(x))); - // data = new Array(input.map(x => BigInt(x).toString())); - data = new Int32Array(input); + data = new BigInt64Array(input.map((x) => BigInt(x))); + break; + case 'uint64': + data = new BigUint64Array(input.map((x) => BigInt(x))); break; default: break; } + if (isNumber) { data = data[0]; } return data; } - /** * Get converted data from given data dict with specified field and precision type. * @param {Object} srcDataDict * @param {String} source * @param {String} precisionType - * @return {Array} + * @return {(Array|Number)} */ function getPrecisionDataFromDataDict(srcDataDict, source, precisionType) { const feedData = srcDataDict[source]; @@ -65,59 +70,114 @@ function getPrecisionDataFromDataDict(srcDataDict, source, precisionType) { } /** - * Get a random number between the specified values - * @param {Number} min - * @param {Number} max - * @param {String} type default 'float64' - * @param {String} sign default 'positive' + * Get a random number by specified dataRange and dataType. + * @param {{min: Number, max: Number, sign: String}} dataRange + * @param {String} dataType * @return {Number} */ -function getRandom(min, max, type = 'float64', sign = 'positive') { +function getRandom(dataRange, dataType) { + function getFloatRandomInclusive() { + // The Math. random() method returns a random floating point number between 0 (inclusive) + // and 1 (exclusive). + let value = Math.random() * 2; + if (value > 1) { + value = 1; + } + return value; + } + + function validateMinMaxByType(min, max, type) { + if (type === 'int8' && (min < -128 || max > 127)) { + throw new Error(`The range of int8 type should be [-128, 127].`); + } else if (type === 'uint8' && (min < 0 || max > 255)) { + throw new Error(`The range of uint8 type should be [0, 255].`); + } else if (type === 'int32' && (min < -Math.pow(2, 31) || max > Math.pow(2, 31) - 1)) { + throw new Error( + `The range of int32 type should be [${-Math.pow(2, 31)}, ${Math.pow(2, 31) - 1}].`); + } else if (type === 'uint32' && (min < 0 || max > Math.pow(2, 32) - 1)) { + throw new Error(`The range of uint32 type should be [0, ${Math.pow(2, 32) - 1}].`); + } else if (type === 'float16') { + const fp16Max = (2- Math.pow(2, -10)) * Math.pow(2, 15); + if (min < -fp16Max || max > fp16Max) { + throw new Error(`The range of float16 type should be [${-fp16Max}, ${fp16Max}].`); + } + } else if (type === 'int64') { + const int64Max = 2n ** 64n - 1n; + if (min < -int64Max || max > int64Max) { + throw new Error(`The range of int64 type should be [${-int64Max}, ${int64Max}].`); + } + } else if (type === 'uint64') { + // In JavaScript, you can represent a BigUint64 using the BigInt data type. + const int64Max = 2n ** 64n - 1n; + if (min < 0n || max > int64Max) { + throw new Error(`The range of uint64 type should be [0n, ${int64Max}].`); + } + } else if (type === 'float32') { + const fp32Max = (2- Math.pow(2, -23)) * Math.pow(2, 127); + if (min < -fp32Max || max > fp32Max) { + throw new Error(`The range of float32 type should be [${-fp32Max}, ${fp32Max}].`); + } + } + } + + let min = dataRange.min; + let max = dataRange.max; + if (min > max) { + throw new Error(`The min should be lesser than max.`); + } + + validateMinMaxByType(min, max, dataType); + + const sign = dataRange.sign || 'mixed'; if (sign === 'positive') { + if (max <= 0) { + throw new Error(`The max should be greater than 0 when sign is set as 'positive'.`); + } if (min < 0) { min = 0; } } else if (sign === 'negative') { + if (min >= 0) { + throw new Error(`The min should be lesser than 0 when sign is set as 'negative'.`); + } if (max > 0) { max = 0; } + } else { + // No change on min and max for mixed sign } - if (type === 'float64' || type === 'float32' || type === 'float16') { - return Math.random() * (max - min) + min; - } else if (type === 'int32') { - min = Math.ceil(min) + 1; - max = Math.floor(max) - 1; - // The maximum is exclusive and the minimum is inclusive - return Math.floor(Math.random() * (max - min) + min); - } else if (type === 'int64'||type === 'uint32') { - return Math.floor(Math.random() * (max - min + 1) + min); - } else if (type === 'uint8') { - let randomUint8Value; - if (Math.random() < 0.2) { - randomUint8Value = 0; - } else { - randomUint8Value = Math.floor(Math.random() * 255); - } - return randomUint8Value; + const factor = getFloatRandomInclusive(); + let data; + if (dataType === 'float32' || dataType === 'float16') { + data = factor * (max - min) + min; + } else if (!['int64', 'uint64'].includes(dataType)) { + // interger + const minCeiled = Math.ceil(min); + const maxFloored = Math.floor(max); + data = Math.floor(factor * (maxFloored - minCeiled) + minCeiled); + } else { + const convertedMin = Math.ceil(parseInt(min)); + const convertedMax = Math.floor(parseInt(max)); + data = BigInt(Math.floor(factor * (convertedMax - convertedMin) + convertedMin)); } + + return data; } /** - * Get random numbers between the specified values - * @param {Number} min - * @param {Number} max + * Get random numbers of TypedArray. * @param {Number} size - * @param {String} [type='float64'] - * @param {String} [sign='mixed'] - * @return {Array} + * @param {{min: Number, max: Number, sign: String}} dataRange + * @param {String} dataType + * @return {(Array|Number)} */ -function getRandomNumbers(min, max, size, type = 'float64', sign='mixed') { +function getRandomNumbers(size, dataRange, dataType) { const data = new Array(size); for (let i = 0; i < size; i++) { - data[i] = getRandom(min, max, type, sign); + data[i] = getRandom(dataRange, dataType); } - return getPrecisionData(data, type); + return getPrecisionData(data, dataType); } /** @@ -125,15 +185,14 @@ function getRandomNumbers(min, max, size, type = 'float64', sign='mixed') { * max parameters . * @param {Object} inputsDataInfo information object for input data * @param {String} dataFile saved data file path - * @param {Number} min - * @param {Number} max + * @param {{min: Number, max: Number}} dataRange * @return {Object} */ -function prepareInputsData(inputsDataInfo, dataFile, min, max) { +function prepareInputsData(inputsDataInfo, dataFile, dataRange) { const dstDataDict = {inputsData: {}}; let srcDataDict = {}; if (fs.existsSync(dataFile)) { - srcDataDict = utils.readJsonFile(dataFile); + srcDataDict = readJsonFile(dataFile); } for (const source in inputsDataInfo) { // reserve last input data when generating new required input data @@ -153,18 +212,14 @@ function prepareInputsData(inputsDataInfo, dataFile, min, max) { } else if (targetDataInfo.processCategory === 'negative') { outputTensor = neg(inputTensor); } - console.log(`source ${source}`); dstDataDict['inputsData'][source] = outputTensor.data; } else { const total = sizeOfShape(targetDataInfo.shape); - const sign = targetDataInfo.sign; - const type = targetDataInfo.type; - if (targetDataInfo.dataRange) { - min = targetDataInfo.dataRange[0]; - max = targetDataInfo.dataRange[1]; + if (targetDataInfo.dataRange !== undefined) { + // Specified data range + dataRange = targetDataInfo.dataRange; } - const generatedNumbers = - utils.getRandomNumbers(min, max, total, type, sign); + const generatedNumbers = getRandomNumbers(total, dataRange, targetDataInfo.dataType); dstDataDict['inputsData'][source] = generatedNumbers; } } @@ -187,7 +242,7 @@ function readJsonFile(filePath) { } const content = fs.readFileSync(inputFile).toString(); const jsonDict = JSON.parse( - content.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, + content.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, // remove comments (m, g) => g ? '' : m)); return jsonDict; } @@ -207,13 +262,13 @@ function writeJsonFile(jsonDict, saveFile) { // If found, it replaces it by a trio if ( value instanceof Int8Array || value instanceof Uint8Array || - value instanceof Uint16Array || value instanceof Int32Array || value instanceof Uint32Array || - value instanceof Float32Array || + value instanceof BigInt64Array || + value instanceof BigUint64Array || value instanceof Float16Array || - value instanceof Float64Array ) { - if (value.length ===1) { // value instanceof Uint8Array && + value instanceof Float32Array) { + if (value.length === 1) { const result = []; result[0] = value[0]; return result;