sub.https.any.js (42536B)
1 // META: title=test WebNN API element-wise sub 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 // https://www.w3.org/TR/webnn/#api-mlgraphbuilder-binary 12 // Compute the element-wise binary subtraction of the two input tensors. 13 // MLOperand sub(MLOperand a, MLOperand b); 14 15 const subTests = [ 16 { 17 'name': 'sub float32 1D constant tensors', 18 'graph': { 19 'inputs': { 20 'inputA': { 21 'data': [ 22 73.59273529052734, 14.4846830368042, -69.40201568603516, 23 -52.045284271240234, -75.7813720703125, -2.2740514278411865, 24 -83.29907989501953, 15.57776927947998, -62.7008056640625, 25 32.954002380371094, 82.55709075927734, -74.90638732910156, 26 78.22299194335938, 48.39240264892578, -19.153541564941406, 27 -85.93221282958984, 89.12355041503906, 22.874629974365234, 28 80.56973266601562, 97.62598419189453, 52.74850845336914, 29 89.1660385131836, -20.50341796875, 99.48707580566406 30 ], 31 'descriptor': {shape: [24], dataType: 'float32'}, 32 'constant': true 33 }, 34 'inputB': { 35 'data': [ 36 -49.12813186645508, 40.189292907714844, 7.224666595458984, 37 89.26004791259766, -81.43340301513672, 59.61166000366211, 38 11.234410285949707, 48.884056091308594, 85.26825714111328, 39 27.695297241210938, 30.98945426940918, -38.12903594970703, 40 -83.14810180664062, -86.16175079345703, 16.75888442993164, 41 46.12889862060547, -28.432477951049805, 28.229337692260742, 42 35.2364616394043, -77.05516815185547, -57.8714714050293, 43 -58.15085983276367, 27.488866806030273, 31.99802017211914 44 ], 45 'descriptor': {shape: [24], dataType: 'float32'}, 46 'constant': true 47 } 48 }, 49 'operators': [{ 50 'name': 'sub', 51 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 52 'outputs': 'output' 53 }], 54 'expectedOutputs': { 55 'output': { 56 'data': [ 57 122.72087097167969, -25.704608917236328, -76.62667846679688, 58 -141.30532836914062, 5.652030944824219, -61.885711669921875, 59 -94.53349304199219, -33.3062858581543, -147.96905517578125, 60 5.258705139160156, 51.56763458251953, -36.77735137939453, 61 161.37109375, 134.5541534423828, -35.91242599487305, 62 -132.0611114501953, 117.5560302734375, -5.354707717895508, 63 45.33327102661133, 174.68115234375, 110.61997985839844, 64 147.31689453125, -47.992286682128906, 67.48905944824219 65 ], 66 'descriptor': {shape: [24], dataType: 'float32'} 67 } 68 } 69 } 70 }, 71 { 72 'name': 'sub float32 1D tensors', 73 'graph': { 74 'inputs': { 75 'inputA': { 76 'data': [ 77 73.59273529052734, 14.4846830368042, -69.40201568603516, 78 -52.045284271240234, -75.7813720703125, -2.2740514278411865, 79 -83.29907989501953, 15.57776927947998, -62.7008056640625, 80 32.954002380371094, 82.55709075927734, -74.90638732910156, 81 78.22299194335938, 48.39240264892578, -19.153541564941406, 82 -85.93221282958984, 89.12355041503906, 22.874629974365234, 83 80.56973266601562, 97.62598419189453, 52.74850845336914, 84 89.1660385131836, -20.50341796875, 99.48707580566406 85 ], 86 'descriptor': {shape: [24], dataType: 'float32'} 87 }, 88 'inputB': { 89 'data': [ 90 -49.12813186645508, 40.189292907714844, 7.224666595458984, 91 89.26004791259766, -81.43340301513672, 59.61166000366211, 92 11.234410285949707, 48.884056091308594, 85.26825714111328, 93 27.695297241210938, 30.98945426940918, -38.12903594970703, 94 -83.14810180664062, -86.16175079345703, 16.75888442993164, 95 46.12889862060547, -28.432477951049805, 28.229337692260742, 96 35.2364616394043, -77.05516815185547, -57.8714714050293, 97 -58.15085983276367, 27.488866806030273, 31.99802017211914 98 ], 99 'descriptor': {shape: [24], dataType: 'float32'} 100 } 101 }, 102 'operators': [{ 103 'name': 'sub', 104 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 105 'outputs': 'output' 106 }], 107 'expectedOutputs': { 108 'output': { 109 'data': [ 110 122.72087097167969, -25.704608917236328, -76.62667846679688, 111 -141.30532836914062, 5.652030944824219, -61.885711669921875, 112 -94.53349304199219, -33.3062858581543, -147.96905517578125, 113 5.258705139160156, 51.56763458251953, -36.77735137939453, 114 161.37109375, 134.5541534423828, -35.91242599487305, 115 -132.0611114501953, 117.5560302734375, -5.354707717895508, 116 45.33327102661133, 174.68115234375, 110.61997985839844, 117 147.31689453125, -47.992286682128906, 67.48905944824219 118 ], 119 'descriptor': {shape: [24], dataType: 'float32'} 120 } 121 } 122 } 123 }, 124 { 125 'name': 'sub float32 2D tensors', 126 'graph': { 127 'inputs': { 128 'inputA': { 129 'data': [ 130 73.59273529052734, 14.4846830368042, -69.40201568603516, 131 -52.045284271240234, -75.7813720703125, -2.2740514278411865, 132 -83.29907989501953, 15.57776927947998, -62.7008056640625, 133 32.954002380371094, 82.55709075927734, -74.90638732910156, 134 78.22299194335938, 48.39240264892578, -19.153541564941406, 135 -85.93221282958984, 89.12355041503906, 22.874629974365234, 136 80.56973266601562, 97.62598419189453, 52.74850845336914, 137 89.1660385131836, -20.50341796875, 99.48707580566406 138 ], 139 'descriptor': {shape: [4, 6], dataType: 'float32'} 140 }, 141 'inputB': { 142 'data': [ 143 -49.12813186645508, 40.189292907714844, 7.224666595458984, 144 89.26004791259766, -81.43340301513672, 59.61166000366211, 145 11.234410285949707, 48.884056091308594, 85.26825714111328, 146 27.695297241210938, 30.98945426940918, -38.12903594970703, 147 -83.14810180664062, -86.16175079345703, 16.75888442993164, 148 46.12889862060547, -28.432477951049805, 28.229337692260742, 149 35.2364616394043, -77.05516815185547, -57.8714714050293, 150 -58.15085983276367, 27.488866806030273, 31.99802017211914 151 ], 152 'descriptor': {shape: [4, 6], dataType: 'float32'} 153 } 154 }, 155 'operators': [{ 156 'name': 'sub', 157 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 158 'outputs': 'output' 159 }], 160 'expectedOutputs': { 161 'output': { 162 'data': [ 163 122.72087097167969, -25.704608917236328, -76.62667846679688, 164 -141.30532836914062, 5.652030944824219, -61.885711669921875, 165 -94.53349304199219, -33.3062858581543, -147.96905517578125, 166 5.258705139160156, 51.56763458251953, -36.77735137939453, 167 161.37109375, 134.5541534423828, -35.91242599487305, 168 -132.0611114501953, 117.5560302734375, -5.354707717895508, 169 45.33327102661133, 174.68115234375, 110.61997985839844, 170 147.31689453125, -47.992286682128906, 67.48905944824219 171 ], 172 'descriptor': {shape: [4, 6], dataType: 'float32'} 173 } 174 } 175 } 176 }, 177 { 178 'name': 'sub float32 3D tensors', 179 'graph': { 180 'inputs': { 181 'inputA': { 182 'data': [ 183 73.59273529052734, 14.4846830368042, -69.40201568603516, 184 -52.045284271240234, -75.7813720703125, -2.2740514278411865, 185 -83.29907989501953, 15.57776927947998, -62.7008056640625, 186 32.954002380371094, 82.55709075927734, -74.90638732910156, 187 78.22299194335938, 48.39240264892578, -19.153541564941406, 188 -85.93221282958984, 89.12355041503906, 22.874629974365234, 189 80.56973266601562, 97.62598419189453, 52.74850845336914, 190 89.1660385131836, -20.50341796875, 99.48707580566406 191 ], 192 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 193 }, 194 'inputB': { 195 'data': [ 196 -49.12813186645508, 40.189292907714844, 7.224666595458984, 197 89.26004791259766, -81.43340301513672, 59.61166000366211, 198 11.234410285949707, 48.884056091308594, 85.26825714111328, 199 27.695297241210938, 30.98945426940918, -38.12903594970703, 200 -83.14810180664062, -86.16175079345703, 16.75888442993164, 201 46.12889862060547, -28.432477951049805, 28.229337692260742, 202 35.2364616394043, -77.05516815185547, -57.8714714050293, 203 -58.15085983276367, 27.488866806030273, 31.99802017211914 204 ], 205 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 206 } 207 }, 208 'operators': [{ 209 'name': 'sub', 210 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 211 'outputs': 'output' 212 }], 213 'expectedOutputs': { 214 'output': { 215 'data': [ 216 122.72087097167969, -25.704608917236328, -76.62667846679688, 217 -141.30532836914062, 5.652030944824219, -61.885711669921875, 218 -94.53349304199219, -33.3062858581543, -147.96905517578125, 219 5.258705139160156, 51.56763458251953, -36.77735137939453, 220 161.37109375, 134.5541534423828, -35.91242599487305, 221 -132.0611114501953, 117.5560302734375, -5.354707717895508, 222 45.33327102661133, 174.68115234375, 110.61997985839844, 223 147.31689453125, -47.992286682128906, 67.48905944824219 224 ], 225 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 226 } 227 } 228 } 229 }, 230 { 231 'name': 'sub float32 4D tensors', 232 'graph': { 233 'inputs': { 234 'inputA': { 235 'data': [ 236 73.59273529052734, 14.4846830368042, -69.40201568603516, 237 -52.045284271240234, -75.7813720703125, -2.2740514278411865, 238 -83.29907989501953, 15.57776927947998, -62.7008056640625, 239 32.954002380371094, 82.55709075927734, -74.90638732910156, 240 78.22299194335938, 48.39240264892578, -19.153541564941406, 241 -85.93221282958984, 89.12355041503906, 22.874629974365234, 242 80.56973266601562, 97.62598419189453, 52.74850845336914, 243 89.1660385131836, -20.50341796875, 99.48707580566406 244 ], 245 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 246 }, 247 'inputB': { 248 'data': [ 249 -49.12813186645508, 40.189292907714844, 7.224666595458984, 250 89.26004791259766, -81.43340301513672, 59.61166000366211, 251 11.234410285949707, 48.884056091308594, 85.26825714111328, 252 27.695297241210938, 30.98945426940918, -38.12903594970703, 253 -83.14810180664062, -86.16175079345703, 16.75888442993164, 254 46.12889862060547, -28.432477951049805, 28.229337692260742, 255 35.2364616394043, -77.05516815185547, -57.8714714050293, 256 -58.15085983276367, 27.488866806030273, 31.99802017211914 257 ], 258 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 259 } 260 }, 261 'operators': [{ 262 'name': 'sub', 263 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 264 'outputs': 'output' 265 }], 266 'expectedOutputs': { 267 'output': { 268 'data': [ 269 122.72087097167969, -25.704608917236328, -76.62667846679688, 270 -141.30532836914062, 5.652030944824219, -61.885711669921875, 271 -94.53349304199219, -33.3062858581543, -147.96905517578125, 272 5.258705139160156, 51.56763458251953, -36.77735137939453, 273 161.37109375, 134.5541534423828, -35.91242599487305, 274 -132.0611114501953, 117.5560302734375, -5.354707717895508, 275 45.33327102661133, 174.68115234375, 110.61997985839844, 276 147.31689453125, -47.992286682128906, 67.48905944824219 277 ], 278 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 279 } 280 } 281 } 282 }, 283 { 284 'name': 'sub float32 5D tensors', 285 'graph': { 286 'inputs': { 287 'inputA': { 288 'data': [ 289 73.59273529052734, 14.4846830368042, -69.40201568603516, 290 -52.045284271240234, -75.7813720703125, -2.2740514278411865, 291 -83.29907989501953, 15.57776927947998, -62.7008056640625, 292 32.954002380371094, 82.55709075927734, -74.90638732910156, 293 78.22299194335938, 48.39240264892578, -19.153541564941406, 294 -85.93221282958984, 89.12355041503906, 22.874629974365234, 295 80.56973266601562, 97.62598419189453, 52.74850845336914, 296 89.1660385131836, -20.50341796875, 99.48707580566406 297 ], 298 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float32'} 299 }, 300 'inputB': { 301 'data': [ 302 -49.12813186645508, 40.189292907714844, 7.224666595458984, 303 89.26004791259766, -81.43340301513672, 59.61166000366211, 304 11.234410285949707, 48.884056091308594, 85.26825714111328, 305 27.695297241210938, 30.98945426940918, -38.12903594970703, 306 -83.14810180664062, -86.16175079345703, 16.75888442993164, 307 46.12889862060547, -28.432477951049805, 28.229337692260742, 308 35.2364616394043, -77.05516815185547, -57.8714714050293, 309 -58.15085983276367, 27.488866806030273, 31.99802017211914 310 ], 311 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float32'} 312 } 313 }, 314 'operators': [{ 315 'name': 'sub', 316 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 317 'outputs': 'output' 318 }], 319 'expectedOutputs': { 320 'output': { 321 'data': [ 322 122.72087097167969, -25.704608917236328, -76.62667846679688, 323 -141.30532836914062, 5.652030944824219, -61.885711669921875, 324 -94.53349304199219, -33.3062858581543, -147.96905517578125, 325 5.258705139160156, 51.56763458251953, -36.77735137939453, 326 161.37109375, 134.5541534423828, -35.91242599487305, 327 -132.0611114501953, 117.5560302734375, -5.354707717895508, 328 45.33327102661133, 174.68115234375, 110.61997985839844, 329 147.31689453125, -47.992286682128906, 67.48905944824219 330 ], 331 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float32'} 332 } 333 } 334 } 335 }, 336 { 337 'name': 'sub float32 broadcast 1D to 4D', 338 'graph': { 339 'inputs': { 340 'inputA': { 341 'data': [-97.04911804199219], 342 'descriptor': {shape: [1], dataType: 'float32'} 343 }, 344 'inputB': { 345 'data': [ 346 73.59273529052734, 14.4846830368042, -69.40201568603516, 347 -52.045284271240234, -75.7813720703125, -2.2740514278411865, 348 -83.29907989501953, 15.57776927947998, -62.7008056640625, 349 32.954002380371094, 82.55709075927734, -74.90638732910156, 350 78.22299194335938, 48.39240264892578, -19.153541564941406, 351 -85.93221282958984, 89.12355041503906, 22.874629974365234, 352 80.56973266601562, 97.62598419189453, 52.74850845336914, 353 89.1660385131836, -20.50341796875, 99.48707580566406 354 ], 355 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 356 } 357 }, 358 'operators': [{ 359 'name': 'sub', 360 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 361 'outputs': 'output' 362 }], 363 'expectedOutputs': { 364 'output': { 365 'data': [ 366 -170.641845703125, -111.53379821777344, -27.64710235595703, 367 -45.00383377075195, -21.267745971679688, -94.77507019042969, 368 -13.750038146972656, -112.62688446044922, -34.34831237792969, 369 -130.00311279296875, -179.606201171875, -22.142730712890625, 370 -175.27210998535156, -145.4415283203125, -77.89557647705078, 371 -11.116905212402344, -186.17266845703125, -119.92375183105469, 372 -177.6188507080078, -194.67510986328125, -149.79762268066406, 373 -186.21514892578125, -76.54570007324219, -196.53619384765625 374 ], 375 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 376 } 377 } 378 } 379 }, 380 { 381 'name': 'sub float32 broadcast 2D to 4D', 382 'graph': { 383 'inputs': { 384 'inputA': { 385 'data': [ 386 73.59273529052734, 14.4846830368042, -69.40201568603516, 387 -52.045284271240234, -75.7813720703125, -2.2740514278411865, 388 -83.29907989501953, 15.57776927947998, -62.7008056640625, 389 32.954002380371094, 82.55709075927734, -74.90638732910156, 390 78.22299194335938, 48.39240264892578, -19.153541564941406, 391 -85.93221282958984, 89.12355041503906, 22.874629974365234, 392 80.56973266601562, 97.62598419189453, 52.74850845336914, 393 89.1660385131836, -20.50341796875, 99.48707580566406 394 ], 395 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 396 }, 397 'inputB': { 398 'data': [ 399 10.762838363647461, -90.23992156982422, 12.787367820739746, 400 -62.44633865356445, 32.18257522583008, 20.359493255615234 401 ], 402 'descriptor': {shape: [2, 3], dataType: 'float32'} 403 } 404 }, 405 'operators': [{ 406 'name': 'sub', 407 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 408 'outputs': 'output' 409 }], 410 'expectedOutputs': { 411 'output': { 412 'data': [ 413 62.82989501953125, 104.72460174560547, -82.18938446044922, 414 10.401054382324219, -107.96394348144531, -22.633544921875, 415 -94.06192016601562, 105.81768798828125, -75.48817443847656, 416 95.40034484863281, 50.374515533447266, -95.26588439941406, 417 67.46015167236328, 138.63232421875, -31.94091033935547, 418 -23.48587417602539, 56.940975189208984, 2.51513671875, 419 69.80689239501953, 187.86590576171875, 39.96113967895508, 420 151.6123809814453, -52.68599319458008, 79.12757873535156 421 ], 422 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 423 } 424 } 425 } 426 }, 427 { 428 'name': 'sub float32 broadcast 3D to 4D', 429 'graph': { 430 'inputs': { 431 'inputA': { 432 'data': [ 433 73.59273529052734, 14.4846830368042, -69.40201568603516, 434 -52.045284271240234, -75.7813720703125, -2.2740514278411865, 435 -83.29907989501953, 15.57776927947998, -62.7008056640625, 436 32.954002380371094, 82.55709075927734, -74.90638732910156, 437 78.22299194335938, 48.39240264892578, -19.153541564941406, 438 -85.93221282958984, 89.12355041503906, 22.874629974365234, 439 80.56973266601562, 97.62598419189453, 52.74850845336914, 440 89.1660385131836, -20.50341796875, 99.48707580566406 441 ], 442 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 443 }, 444 'inputB': { 445 'data': [ 446 -8.39311408996582, 75.54753112792969, -32.325870513916016, 447 8.088332176208496 448 ], 449 'descriptor': {shape: [2, 2, 1], dataType: 'float32'} 450 } 451 }, 452 'operators': [{ 453 'name': 'sub', 454 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 455 'outputs': 'output' 456 }], 457 'expectedOutputs': { 458 'output': { 459 'data': [ 460 81.98584747314453, 22.877796173095703, -61.00890350341797, 461 -127.59281921386719, -151.3289031982422, -77.82157897949219, 462 -50.973209381103516, 47.90364074707031, -30.374935150146484, 463 24.86566925048828, 74.46875762939453, -82.99472045898438, 464 86.61610412597656, 56.78551483154297, -10.760427474975586, 465 -161.479736328125, 13.576019287109375, -52.67290115356445, 466 112.89559936523438, 129.9518585205078, 85.07437896728516, 467 81.07770538330078, -28.591751098632812, 91.39874267578125 468 ], 469 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 470 } 471 } 472 } 473 }, 474 { 475 'name': 'sub float32 broadcast 4D to 4D', 476 'graph': { 477 'inputs': { 478 'inputA': { 479 'data': [-97.04911804199219], 480 'descriptor': {shape: [1, 1, 1, 1], dataType: 'float32'} 481 }, 482 'inputB': { 483 'data': [ 484 73.59273529052734, 14.4846830368042, -69.40201568603516, 485 -52.045284271240234, -75.7813720703125, -2.2740514278411865, 486 -83.29907989501953, 15.57776927947998, -62.7008056640625, 487 32.954002380371094, 82.55709075927734, -74.90638732910156, 488 78.22299194335938, 48.39240264892578, -19.153541564941406, 489 -85.93221282958984, 89.12355041503906, 22.874629974365234, 490 80.56973266601562, 97.62598419189453, 52.74850845336914, 491 89.1660385131836, -20.50341796875, 99.48707580566406 492 ], 493 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 494 } 495 }, 496 'operators': [{ 497 'name': 'sub', 498 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 499 'outputs': 'output' 500 }], 501 'expectedOutputs': { 502 'output': { 503 'data': [ 504 -170.641845703125, -111.53379821777344, -27.64710235595703, 505 -45.00383377075195, -21.267745971679688, -94.77507019042969, 506 -13.750038146972656, -112.62688446044922, -34.34831237792969, 507 -130.00311279296875, -179.606201171875, -22.142730712890625, 508 -175.27210998535156, -145.4415283203125, -77.89557647705078, 509 -11.116905212402344, -186.17266845703125, -119.92375183105469, 510 -177.6188507080078, -194.67510986328125, -149.79762268066406, 511 -186.21514892578125, -76.54570007324219, -196.53619384765625 512 ], 513 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 514 } 515 } 516 } 517 }, 518 519 // float16 tests 520 { 521 'name': 'sub float16 1D constant tensors', 522 'graph': { 523 'inputs': { 524 'inputA': { 525 'data': [ 526 73.5625, 14.484375, -69.375, -52.03125, -75.8125, -2.2734375, 527 -83.3125, 15.578125, -62.6875, 32.96875, 82.5625, -74.9375, 528 78.25, 48.40625, -19.15625, -85.9375, 89.125, 22.875, 529 80.5625, 97.625, 52.75, 89.1875, -20.5, 99.5 530 ], 531 'descriptor': {shape: [24], dataType: 'float16'}, 532 'constant': true 533 }, 534 'inputB': { 535 'data': [ 536 -49.125, 40.1875, 7.2265625, 89.25, -81.4375, 59.625, 537 11.234375, 48.875, 85.25, 27.6875, 30.984375, -38.125, 538 -83.125, -86.1875, 16.765625, 46.125, -28.4375, 28.234375, 539 35.25, -77.0625, -57.875, -58.15625, 27.484375, 32 540 ], 541 'descriptor': {shape: [24], dataType: 'float16'}, 542 'constant': true 543 } 544 }, 545 'operators': [{ 546 'name': 'sub', 547 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 548 'outputs': 'output' 549 }], 550 'expectedOutputs': { 551 'output': { 552 'data': [ 553 122.6875, -25.703125, -76.625, -141.25, 5.625, -61.90625, 554 -94.5625, -33.3125, -148, 5.28125, 51.5625, -36.8125, 555 161.375, 134.625, -35.9375, -132, 117.5625, -5.359375, 556 45.3125, 174.75, 110.625, 147.375, -48, 67.5 557 ], 558 'descriptor': {shape: [24], dataType: 'float16'} 559 } 560 } 561 } 562 }, 563 { 564 'name': 'sub float16 1D tensors', 565 'graph': { 566 'inputs': { 567 'inputA': { 568 'data': [ 569 73.5625, 14.484375, -69.375, -52.03125, -75.8125, -2.2734375, 570 -83.3125, 15.578125, -62.6875, 32.96875, 82.5625, -74.9375, 571 78.25, 48.40625, -19.15625, -85.9375, 89.125, 22.875, 572 80.5625, 97.625, 52.75, 89.1875, -20.5, 99.5 573 ], 574 'descriptor': {shape: [24], dataType: 'float16'} 575 }, 576 'inputB': { 577 'data': [ 578 -49.125, 40.1875, 7.2265625, 89.25, -81.4375, 59.625, 579 11.234375, 48.875, 85.25, 27.6875, 30.984375, -38.125, 580 -83.125, -86.1875, 16.765625, 46.125, -28.4375, 28.234375, 581 35.25, -77.0625, -57.875, -58.15625, 27.484375, 32 582 ], 583 'descriptor': {shape: [24], dataType: 'float16'} 584 } 585 }, 586 'operators': [{ 587 'name': 'sub', 588 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 589 'outputs': 'output' 590 }], 591 'expectedOutputs': { 592 'output': { 593 'data': [ 594 122.6875, -25.703125, -76.625, -141.25, 5.625, -61.90625, 595 -94.5625, -33.3125, -148, 5.28125, 51.5625, -36.8125, 596 161.375, 134.625, -35.9375, -132, 117.5625, -5.359375, 597 45.3125, 174.75, 110.625, 147.375, -48, 67.5 598 ], 599 'descriptor': {shape: [24], dataType: 'float16'} 600 } 601 } 602 } 603 }, 604 { 605 'name': 'sub float16 2D tensors', 606 'graph': { 607 'inputs': { 608 'inputA': { 609 'data': [ 610 73.5625, 14.484375, -69.375, -52.03125, -75.8125, -2.2734375, 611 -83.3125, 15.578125, -62.6875, 32.96875, 82.5625, -74.9375, 612 78.25, 48.40625, -19.15625, -85.9375, 89.125, 22.875, 613 80.5625, 97.625, 52.75, 89.1875, -20.5, 99.5 614 ], 615 'descriptor': {shape: [4, 6], dataType: 'float16'} 616 }, 617 'inputB': { 618 'data': [ 619 -49.125, 40.1875, 7.2265625, 89.25, -81.4375, 59.625, 620 11.234375, 48.875, 85.25, 27.6875, 30.984375, -38.125, 621 -83.125, -86.1875, 16.765625, 46.125, -28.4375, 28.234375, 622 35.25, -77.0625, -57.875, -58.15625, 27.484375, 32 623 ], 624 'descriptor': {shape: [4, 6], dataType: 'float16'} 625 } 626 }, 627 'operators': [{ 628 'name': 'sub', 629 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 630 'outputs': 'output' 631 }], 632 'expectedOutputs': { 633 'output': { 634 'data': [ 635 122.6875, -25.703125, -76.625, -141.25, 5.625, -61.90625, 636 -94.5625, -33.3125, -148, 5.28125, 51.5625, -36.8125, 637 161.375, 134.625, -35.9375, -132, 117.5625, -5.359375, 638 45.3125, 174.75, 110.625, 147.375, -48, 67.5 639 ], 640 'descriptor': {shape: [4, 6], dataType: 'float16'} 641 } 642 } 643 } 644 }, 645 { 646 'name': 'sub float16 3D tensors', 647 'graph': { 648 'inputs': { 649 'inputA': { 650 'data': [ 651 73.5625, 14.484375, -69.375, -52.03125, -75.8125, -2.2734375, 652 -83.3125, 15.578125, -62.6875, 32.96875, 82.5625, -74.9375, 653 78.25, 48.40625, -19.15625, -85.9375, 89.125, 22.875, 654 80.5625, 97.625, 52.75, 89.1875, -20.5, 99.5 655 ], 656 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 657 }, 658 'inputB': { 659 'data': [ 660 -49.125, 40.1875, 7.2265625, 89.25, -81.4375, 59.625, 661 11.234375, 48.875, 85.25, 27.6875, 30.984375, -38.125, 662 -83.125, -86.1875, 16.765625, 46.125, -28.4375, 28.234375, 663 35.25, -77.0625, -57.875, -58.15625, 27.484375, 32 664 ], 665 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 666 } 667 }, 668 'operators': [{ 669 'name': 'sub', 670 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 671 'outputs': 'output' 672 }], 673 'expectedOutputs': { 674 'output': { 675 'data': [ 676 122.6875, -25.703125, -76.625, -141.25, 5.625, -61.90625, 677 -94.5625, -33.3125, -148, 5.28125, 51.5625, -36.8125, 678 161.375, 134.625, -35.9375, -132, 117.5625, -5.359375, 679 45.3125, 174.75, 110.625, 147.375, -48, 67.5 680 ], 681 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 682 } 683 } 684 } 685 }, 686 { 687 'name': 'sub float16 4D tensors', 688 'graph': { 689 'inputs': { 690 'inputA': { 691 'data': [ 692 73.5625, 14.484375, -69.375, -52.03125, -75.8125, -2.2734375, 693 -83.3125, 15.578125, -62.6875, 32.96875, 82.5625, -74.9375, 694 78.25, 48.40625, -19.15625, -85.9375, 89.125, 22.875, 695 80.5625, 97.625, 52.75, 89.1875, -20.5, 99.5 696 ], 697 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 698 }, 699 'inputB': { 700 'data': [ 701 -49.125, 40.1875, 7.2265625, 89.25, -81.4375, 59.625, 702 11.234375, 48.875, 85.25, 27.6875, 30.984375, -38.125, 703 -83.125, -86.1875, 16.765625, 46.125, -28.4375, 28.234375, 704 35.25, -77.0625, -57.875, -58.15625, 27.484375, 32 705 ], 706 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 707 } 708 }, 709 'operators': [{ 710 'name': 'sub', 711 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 712 'outputs': 'output' 713 }], 714 'expectedOutputs': { 715 'output': { 716 'data': [ 717 122.6875, -25.703125, -76.625, -141.25, 5.625, -61.90625, 718 -94.5625, -33.3125, -148, 5.28125, 51.5625, -36.8125, 719 161.375, 134.625, -35.9375, -132, 117.5625, -5.359375, 720 45.3125, 174.75, 110.625, 147.375, -48, 67.5 721 ], 722 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 723 } 724 } 725 } 726 }, 727 { 728 'name': 'sub float16 5D tensors', 729 'graph': { 730 'inputs': { 731 'inputA': { 732 'data': [ 733 73.5625, 14.484375, -69.375, -52.03125, -75.8125, -2.2734375, 734 -83.3125, 15.578125, -62.6875, 32.96875, 82.5625, -74.9375, 735 78.25, 48.40625, -19.15625, -85.9375, 89.125, 22.875, 736 80.5625, 97.625, 52.75, 89.1875, -20.5, 99.5 737 ], 738 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float16'} 739 }, 740 'inputB': { 741 'data': [ 742 -49.125, 40.1875, 7.2265625, 89.25, -81.4375, 59.625, 743 11.234375, 48.875, 85.25, 27.6875, 30.984375, -38.125, 744 -83.125, -86.1875, 16.765625, 46.125, -28.4375, 28.234375, 745 35.25, -77.0625, -57.875, -58.15625, 27.484375, 32 746 ], 747 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float16'} 748 } 749 }, 750 'operators': [{ 751 'name': 'sub', 752 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 753 'outputs': 'output' 754 }], 755 'expectedOutputs': { 756 'output': { 757 'data': [ 758 122.6875, -25.703125, -76.625, -141.25, 5.625, -61.90625, 759 -94.5625, -33.3125, -148, 5.28125, 51.5625, -36.8125, 760 161.375, 134.625, -35.9375, -132, 117.5625, -5.359375, 761 45.3125, 174.75, 110.625, 147.375, -48, 67.5 762 ], 763 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float16'} 764 } 765 } 766 } 767 }, 768 { 769 'name': 'sub float16 broadcast 1D to 4D', 770 'graph': { 771 'inputs': { 772 'inputA': { 773 'data': [-97.0625], 774 'descriptor': {shape: [1], dataType: 'float16'} 775 }, 776 'inputB': { 777 'data': [ 778 73.5625, 14.484375, -69.375, -52.03125, -75.8125, -2.2734375, 779 -83.3125, 15.578125, -62.6875, 32.96875, 82.5625, -74.9375, 780 78.25, 48.40625, -19.15625, -85.9375, 89.125, 22.875, 781 80.5625, 97.625, 52.75, 89.1875, -20.5, 99.5 782 ], 783 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 784 } 785 }, 786 'operators': [{ 787 'name': 'sub', 788 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 789 'outputs': 'output' 790 }], 791 'expectedOutputs': { 792 'output': { 793 'data': [ 794 -170.625, -111.5625, -27.6875, -45.03125, -21.25, -94.8125, 795 -13.75, -112.625, -34.375, -130, -179.625, -22.125, 796 -175.25, -145.5, -77.875, -11.125, -186.25, -119.9375, 797 -177.625, -194.75, -149.75, -186.25, -76.5625, -196.5 798 ], 799 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 800 } 801 } 802 } 803 }, 804 { 805 'name': 'sub float16 broadcast 2D to 4D', 806 'graph': { 807 'inputs': { 808 'inputA': { 809 'data': [ 810 73.5625, 14.484375, -69.375, -52.03125, -75.8125, -2.2734375, 811 -83.3125, 15.578125, -62.6875, 32.96875, 82.5625, -74.9375, 812 78.25, 48.40625, -19.15625, -85.9375, 89.125, 22.875, 813 80.5625, 97.625, 52.75, 89.1875, -20.5, 99.5 814 ], 815 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 816 }, 817 'inputB': { 818 'data': [10.765625, -90.25, 12.7890625, -62.4375, 32.1875, 20.359375], 819 'descriptor': {shape: [2, 3], dataType: 'float16'} 820 } 821 }, 822 'operators': [{ 823 'name': 'sub', 824 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 825 'outputs': 'output' 826 }], 827 'expectedOutputs': { 828 'output': { 829 'data': [ 830 62.8125, 104.75, -82.1875, 10.40625, -108, -22.625, 831 -94.0625, 105.8125, -75.5, 95.375, 50.375, -95.3125, 832 67.5, 138.625, -31.9375, -23.5, 56.9375, 2.515625, 833 69.8125, 187.875, 39.96875, 151.625, -52.6875, 79.125 834 ], 835 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 836 } 837 } 838 } 839 }, 840 { 841 'name': 'sub float16 broadcast 3D to 4D', 842 'graph': { 843 'inputs': { 844 'inputA': { 845 'data': [ 846 73.5625, 14.484375, -69.375, -52.03125, -75.8125, -2.2734375, 847 -83.3125, 15.578125, -62.6875, 32.96875, 82.5625, -74.9375, 848 78.25, 48.40625, -19.15625, -85.9375, 89.125, 22.875, 849 80.5625, 97.625, 52.75, 89.1875, -20.5, 99.5 850 ], 851 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 852 }, 853 'inputB': { 854 'data': [-8.390625, 75.5625, -32.3125, 8.0859375], 855 'descriptor': {shape: [2, 2, 1], dataType: 'float16'} 856 } 857 }, 858 'operators': [{ 859 'name': 'sub', 860 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 861 'outputs': 'output' 862 }], 863 'expectedOutputs': { 864 'output': { 865 'data': [ 866 81.9375, 22.875, -61, -127.625, -151.375, -77.8125, 867 -51, 47.875, -30.375, 24.875, 74.5, -83, 868 86.625, 56.8125, -10.765625, -161.5, 13.5625, -52.6875, 869 112.875, 130, 85.0625, 81.125, -28.59375, 91.4375 870 ], 871 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 872 } 873 } 874 } 875 }, 876 { 877 'name': 'sub float16 broadcast 4D to 4D', 878 'graph': { 879 'inputs': { 880 'inputA': { 881 'data': [-97.0625], 882 'descriptor': {shape: [1, 1, 1, 1], dataType: 'float16'} 883 }, 884 'inputB': { 885 'data': [ 886 73.5625, 14.484375, -69.375, -52.03125, -75.8125, -2.2734375, 887 -83.3125, 15.578125, -62.6875, 32.96875, 82.5625, -74.9375, 888 78.25, 48.40625, -19.15625, -85.9375, 89.125, 22.875, 889 80.5625, 97.625, 52.75, 89.1875, -20.5, 99.5 890 ], 891 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 892 } 893 }, 894 'operators': [{ 895 'name': 'sub', 896 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 897 'outputs': 'output' 898 }], 899 'expectedOutputs': { 900 'output': { 901 'data': [ 902 -170.625, -111.5625, -27.6875, -45.03125, -21.25, -94.8125, 903 -13.75, -112.625, -34.375, -130, -179.625, -22.125, 904 -175.25, -145.5, -77.875, -11.125, -186.25, -119.9375, 905 -177.625, -194.75, -149.75, -186.25, -76.5625, -196.5 906 ], 907 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 908 } 909 } 910 } 911 }, 912 913 // int8 tests 914 { 915 'name': 'sub int8 4D tensors', 916 'graph': { 917 'inputs': { 918 'inputA': { 919 'data': [ 920 73, 14, -69, -52, -75, -2, -83, 15, -62, 32, 82, -74, 921 78, 48, -19, -85, 89, 22, 80, 97, 52, 89, -20, 99 922 ], 923 'descriptor': {shape: [2, 2, 2, 3], dataType: 'int8'} 924 }, 925 'inputB': { 926 'data': [ 927 -49, 40, 7, 76, -81, 59, 11, 48, 65, 27, 30, -38, 928 -49, -78, 16, 35, -28, 28, 35, -3, -57, -21, 27, 32 929 ], 930 'descriptor': {shape: [2, 2, 2, 3], dataType: 'int8'} 931 } 932 }, 933 'operators': [{ 934 'name': 'sub', 935 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 936 'outputs': 'output' 937 }], 938 'expectedOutputs': { 939 'output': { 940 // the range of int8 result: [-128, 127] 941 'data': [ 942 122, -26, -76, -128, 6, -61, -94, -33, -127, 5, 52, -36, 943 127, 126, -35, -120, 117, -6, 45, 100, 109, 110, -47, 67 944 ], 945 'descriptor': {shape: [2, 2, 2, 3], dataType: 'int8'} 946 } 947 } 948 } 949 }, 950 951 // uint8 tests 952 { 953 'name': 'sub uint8 4D tensors', 954 'graph': { 955 'inputs': { 956 'inputA': { 957 'data': [1, 10, 100, 255], 958 'descriptor': {shape: [1, 2, 2, 1], dataType: 'uint8'} 959 }, 960 'inputB': { 961 // b should be lesser than or equal to a, otherwise the result would 962 // overflow when testing uint8 data type 963 'data': [1, 8, 88, 254], 964 'descriptor': {shape: [1, 2, 2, 1], dataType: 'uint8'} 965 } 966 }, 967 'operators': [{ 968 'name': 'sub', 969 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 970 'outputs': 'output' 971 }], 972 'expectedOutputs': { 973 'output': { 974 'data': [0, 2, 12, 1], 975 'descriptor': {shape: [1, 2, 2, 1], dataType: 'uint8'} 976 } 977 } 978 } 979 }, 980 981 // int32 tests 982 { 983 'name': 'sub int32 4D tensors', 984 'graph': { 985 'inputs': { 986 'inputA': { 987 'data': [ 988 73, 14, -69, -52, -75, -2, -83, 15, -62, 32, 82, -74, 989 78, 48, -19, -85, 89, 22, 80, 97, 52, 89, -20, 99 990 ], 991 'descriptor': {shape: [2, 2, 2, 3], dataType: 'int32'} 992 }, 993 'inputB': { 994 'data': [ 995 -49, 40, 7, 89, -81, 59, 11, 48, 85, 27, 30, -38, 996 -83, -86, 16, 46, -28, 28, 35, -77, -57, -58, 27, 32 997 ], 998 'descriptor': {shape: [2, 2, 2, 3], dataType: 'int32'} 999 } 1000 }, 1001 'operators': [{ 1002 'name': 'sub', 1003 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 1004 'outputs': 'output' 1005 }], 1006 'expectedOutputs': { 1007 'output': { 1008 'data': [ 1009 122, -26, -76, -141, 6, -61, -94, -33, -147, 5, 52, -36, 1010 161, 134, -35, -131, 117, -6, 45, 174, 109, 147, -47, 67 1011 ], 1012 'descriptor': {shape: [2, 2, 2, 3], dataType: 'int32'} 1013 } 1014 } 1015 } 1016 }, 1017 1018 // uint32 tests 1019 { 1020 'name': 'sub uint32 4D tensors', 1021 'graph': { 1022 'inputs': { 1023 'inputA': { 1024 'data': [1, 10, 100, 1024], 1025 'descriptor': {shape: [1, 2, 2, 1], dataType: 'uint32'} 1026 }, 1027 'inputB': { 1028 // b should be lesser than or equal to a, otherwise the result would 1029 // overflow when testing uint32 data type 1030 'data': [1, 8, 88, 1000], 1031 'descriptor': {shape: [1, 2, 2, 1], dataType: 'uint32'} 1032 } 1033 }, 1034 'operators': [{ 1035 'name': 'sub', 1036 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 1037 'outputs': 'output' 1038 }], 1039 'expectedOutputs': { 1040 'output': { 1041 'data': [0, 2, 12, 24], 1042 'descriptor': {shape: [1, 2, 2, 1], dataType: 'uint32'} 1043 } 1044 } 1045 } 1046 }, 1047 1048 // int64 tests 1049 { 1050 'name': 'sub int64 4D tensors', 1051 'graph': { 1052 'inputs': { 1053 'inputA': { 1054 'data': [ 1055 73, 14, -69, -52, -75, -2, -83, 15, -62, 32, 82, -74, 1056 78, 48, -19, -85, 89, 22, 80, 97, 52, 89, -20, 99 1057 ], 1058 'descriptor': {shape: [2, 2, 2, 3], dataType: 'int64'} 1059 }, 1060 'inputB': { 1061 'data': [ 1062 -49, 40, 7, 89, -81, 59, 11, 48, 85, 27, 30, -38, 1063 -83, -86, 16, 46, -28, 28, 35, -77, -57, -58, 27, 32 1064 ], 1065 'descriptor': {shape: [2, 2, 2, 3], dataType: 'int64'} 1066 } 1067 }, 1068 'operators': [{ 1069 'name': 'sub', 1070 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 1071 'outputs': 'output' 1072 }], 1073 'expectedOutputs': { 1074 'output': { 1075 'data': [ 1076 122, -26, -76, -141, 6, -61, -94, -33, -147, 5, 52, -36, 1077 161, 134, -35, -131, 117, -6, 45, 174, 109, 147, -47, 67 1078 ], 1079 'descriptor': {shape: [2, 2, 2, 3], dataType: 'int64'} 1080 } 1081 } 1082 } 1083 }, 1084 1085 // uint64 tests 1086 { 1087 'name': 'sub uint64 4D tensors', 1088 'graph': { 1089 'inputs': { 1090 'inputA': { 1091 'data': [1, 10, 100, 1024], 1092 'descriptor': {shape: [1, 2, 2, 1], dataType: 'uint64'} 1093 }, 1094 'inputB': { 1095 // b should be lesser than or equal to a, otherwise the result would 1096 // overflow when testing uint64 data type 1097 'data': [1, 8, 88, 1000], 1098 'descriptor': {shape: [1, 2, 2, 1], dataType: 'uint64'} 1099 } 1100 }, 1101 'operators': [{ 1102 'name': 'sub', 1103 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 1104 'outputs': 'output' 1105 }], 1106 'expectedOutputs': { 1107 'output': { 1108 'data': [0, 2, 12, 24], 1109 'descriptor': {shape: [1, 2, 2, 1], dataType: 'uint64'} 1110 } 1111 } 1112 } 1113 } 1114 ]; 1115 1116 webnn_conformance_test(subTests, buildAndExecuteGraph, getPrecisionTolerance);