scatterElements.https.any.js (8201B)
1 // META: title=test WebNN API scatterElements operation 2 // META: global=window 3 // META: variant=?cpu 4 // META: variant=?gpu 5 // META: variant=?npu 6 // META: script=../resources/utils.js 7 // META: timeout=long 8 9 'use strict'; 10 11 const scatterElementsTests = [ 12 { 13 'name': 'scatterElements float32 tensors along axis 0', 14 'graph': { 15 'inputs': { 16 'input': { 17 'data': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 18 'descriptor': {shape: [3, 3], dataType: 'float32'} 19 }, 20 'indices': { 21 'data': [1, 0, 2, 0, 2, 1], 22 'descriptor': {shape: [2, 3], dataType: 'int32'} 23 }, 24 'updates': { 25 'data': [1.0, 1.1, 1.2, 2.0, 2.1, 2.2], 26 'descriptor': {shape: [2, 3], dataType: 'float32'} 27 } 28 }, 29 'operators': [{ 30 'name': 'scatterElements', 31 'arguments': [ 32 {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}, 33 {'options': {'axis': 0}} 34 ], 35 'outputs': 'output' 36 }], 37 'expectedOutputs': { 38 'output': { 39 'data': [2.0, 1.1, 0.0, 1.0, 0.0, 2.2, 0.0, 2.1, 1.2], 40 'descriptor': {shape: [3, 3], dataType: 'float32'} 41 } 42 } 43 } 44 }, 45 { 46 'name': 'scatterElements float32 tensors along axis 0 and constant indices', 47 'graph': { 48 'inputs': { 49 'input': { 50 'data': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 51 'descriptor': {shape: [3, 3], dataType: 'float32'} 52 }, 53 'indices': { 54 'data': [1, 0, 2, 0, 2, 1], 55 'descriptor': {shape: [2, 3], dataType: 'int32'}, 56 'constant': true 57 }, 58 'updates': { 59 'data': [1.0, 1.1, 1.2, 2.0, 2.1, 2.2], 60 'descriptor': {shape: [2, 3], dataType: 'float32'} 61 } 62 }, 63 'operators': [{ 64 'name': 'scatterElements', 65 'arguments': [ 66 {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}, 67 {'options': {'axis': 0}} 68 ], 69 'outputs': 'output' 70 }], 71 'expectedOutputs': { 72 'output': { 73 'data': [2.0, 1.1, 0.0, 1.0, 0.0, 2.2, 0.0, 2.1, 1.2], 74 'descriptor': {shape: [3, 3], dataType: 'float32'} 75 } 76 } 77 } 78 }, 79 { 80 'name': 'scatterElements float32 tensors along axis 1', 81 'graph': { 82 'inputs': { 83 'input': { 84 'data': [1.0, 2.0, 3.0, 4.0, 5.0], 85 'descriptor': {shape: [1, 5], dataType: 'float32'} 86 }, 87 'indices': 88 {'data': [1, 3], 'descriptor': {shape: [1, 2], dataType: 'int32'}}, 89 'updates': { 90 'data': [1.1, 2.1], 91 'descriptor': {shape: [1, 2], dataType: 'float32'} 92 } 93 }, 94 'operators': [{ 95 'name': 'scatterElements', 96 'arguments': [ 97 {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}, 98 {'options': {'axis': 1}} 99 ], 100 'outputs': 'output' 101 }], 102 'expectedOutputs': { 103 'output': { 104 'data': [1.0, 1.1, 3.0, 2.1, 5.0], 105 'descriptor': {shape: [1, 5], dataType: 'float32'} 106 } 107 } 108 } 109 }, 110 { 111 'name': 'scatterElements float32 tensors along axis 1 and constant indices', 112 'graph': { 113 'inputs': { 114 'input': { 115 'data': [1.0, 2.0, 3.0, 4.0, 5.0], 116 'descriptor': {shape: [1, 5], dataType: 'float32'} 117 }, 118 'indices': { 119 'data': [1, 3], 120 'descriptor': {shape: [1, 2], dataType: 'int32'}, 121 'constant': true 122 }, 123 'updates': { 124 'data': [1.1, 2.1], 125 'descriptor': {shape: [1, 2], dataType: 'float32'} 126 } 127 }, 128 'operators': [{ 129 'name': 'scatterElements', 130 'arguments': [ 131 {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}, 132 {'options': {'axis': 1}} 133 ], 134 'outputs': 'output' 135 }], 136 'expectedOutputs': { 137 'output': { 138 'data': [1.0, 1.1, 3.0, 2.1, 5.0], 139 'descriptor': {shape: [1, 5], dataType: 'float32'} 140 } 141 } 142 } 143 }, 144 145 // float16 tests 146 { 147 'name': 'scatterElements float16 tensors along axis 0', 148 'graph': { 149 'inputs': { 150 'input': { 151 'data': [0, 0, 0, 0, 0, 0, 0, 0, 0], 152 'descriptor': {shape: [3, 3], dataType: 'float16'} 153 }, 154 'indices': { 155 'data': [1, 0, 2, 0, 2, 1], 156 'descriptor': {shape: [2, 3], dataType: 'int32'} 157 }, 158 'updates': { 159 'data': [1, 1.099609375, 1.2001953125, 2, 2.099609375, 2.19921875], 160 'descriptor': {shape: [2, 3], dataType: 'float16'} 161 } 162 }, 163 'operators': [{ 164 'name': 'scatterElements', 165 'arguments': [ 166 {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}, 167 {'options': {'axis': 0}} 168 ], 169 'outputs': 'output' 170 }], 171 'expectedOutputs': { 172 'output': { 173 'data': [ 174 2, 1.099609375, 0, 1, 0, 2.19921875, 0, 2.099609375, 1.2001953125 175 ], 176 'descriptor': {shape: [3, 3], dataType: 'float16'} 177 } 178 } 179 } 180 }, 181 { 182 'name': 'scatterElements float16 tensors along axis 0 and constant indices', 183 'graph': { 184 'inputs': { 185 'input': { 186 'data': [0, 0, 0, 0, 0, 0, 0, 0, 0], 187 'descriptor': {shape: [3, 3], dataType: 'float16'} 188 }, 189 'indices': { 190 'data': [1, 0, 2, 0, 2, 1], 191 'descriptor': {shape: [2, 3], dataType: 'int32'}, 192 'constant': true 193 }, 194 'updates': { 195 'data': [1, 1.099609375, 1.2001953125, 2, 2.099609375, 2.19921875], 196 'descriptor': {shape: [2, 3], dataType: 'float16'} 197 } 198 }, 199 'operators': [{ 200 'name': 'scatterElements', 201 'arguments': [ 202 {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}, 203 {'options': {'axis': 0}} 204 ], 205 'outputs': 'output' 206 }], 207 'expectedOutputs': { 208 'output': { 209 'data': [ 210 2, 1.099609375, 0, 1, 0, 2.19921875, 0, 2.099609375, 1.2001953125 211 ], 212 'descriptor': {shape: [3, 3], dataType: 'float16'} 213 } 214 } 215 } 216 }, 217 { 218 'name': 'scatterElements float16 tensors along axis 1', 219 'graph': { 220 'inputs': { 221 'input': { 222 'data': [1, 2, 3, 4, 5], 223 'descriptor': {shape: [1, 5], dataType: 'float16'} 224 }, 225 'indices': 226 {'data': [1, 3], 'descriptor': {shape: [1, 2], dataType: 'int32'}}, 227 'updates': { 228 'data': [1.099609375, 2.099609375], 229 'descriptor': {shape: [1, 2], dataType: 'float16'} 230 } 231 }, 232 'operators': [{ 233 'name': 'scatterElements', 234 'arguments': [ 235 {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}, 236 {'options': {'axis': 1}} 237 ], 238 'outputs': 'output' 239 }], 240 'expectedOutputs': { 241 'output': { 242 'data': [1, 1.099609375, 3, 2.099609375, 5], 243 'descriptor': {shape: [1, 5], dataType: 'float16'} 244 } 245 } 246 } 247 }, 248 { 249 'name': 'scatterElements float16 tensors along axis 1 and constant indices', 250 'graph': { 251 'inputs': { 252 'input': { 253 'data': [1, 2, 3, 4, 5], 254 'descriptor': {shape: [1, 5], dataType: 'float16'} 255 }, 256 'indices': { 257 'data': [1, 3], 258 'descriptor': {shape: [1, 2], dataType: 'int32'}, 259 'constant': true 260 }, 261 'updates': { 262 'data': [1.099609375, 2.099609375], 263 'descriptor': {shape: [1, 2], dataType: 'float16'} 264 } 265 }, 266 'operators': [{ 267 'name': 'scatterElements', 268 'arguments': [ 269 {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}, 270 {'options': {'axis': 1}} 271 ], 272 'outputs': 'output' 273 }], 274 'expectedOutputs': { 275 'output': { 276 'data': [1, 1.099609375, 3, 2.099609375, 5], 277 'descriptor': {shape: [1, 5], dataType: 'float16'} 278 } 279 } 280 } 281 } 282 ]; 283 284 webnn_conformance_test( 285 scatterElementsTests, buildAndExecuteGraph, getZeroULPTolerance);