reduce_l2.https.any.js (40765B)
1 // META: title=test WebNN API reduction operations 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/#dom-mlgraphbuilder-reducel2 12 // Reduce the input tensor along all dimensions, or along the axes specified in 13 // the axes array parameter. 14 // 15 // dictionary MLReduceOptions { 16 // sequence<[EnforceRange] unsigned long> axes; 17 // boolean keepDimensions = false; 18 // }; 19 // 20 // MLOperand reduceL2(MLOperand input, optional MLReduceOptions options = {}); 21 22 const reduceL2Tests = [ 23 // reduceL2 tests 24 { 25 'name': 'reduceL2 float32 0D constant tensor default options', 26 'graph': { 27 'inputs': { 28 'reduceL2Input': { 29 'data': [4.860228061676025], 30 'descriptor': {shape: [], dataType: 'float32'}, 31 'constant': true 32 } 33 }, 34 'operators': [{ 35 'name': 'reduceL2', 36 'arguments': [{'input': 'reduceL2Input'}], 37 'outputs': 'reduceL2Output' 38 }], 39 'expectedOutputs': { 40 'reduceL2Output': { 41 'data': 4.860228061676025, 42 'descriptor': {shape: [], dataType: 'float32'} 43 } 44 } 45 } 46 }, 47 { 48 'name': 'reduceL2 float32 0D tensor default options', 49 'graph': { 50 'inputs': { 51 'reduceL2Input': { 52 'data': [4.860228061676025], 53 'descriptor': {shape: [], dataType: 'float32'}, 54 'constant': false 55 } 56 }, 57 'operators': [{ 58 'name': 'reduceL2', 59 'arguments': [{'input': 'reduceL2Input'}], 60 'outputs': 'reduceL2Output' 61 }], 62 'expectedOutputs': { 63 'reduceL2Output': { 64 'data': 4.860228061676025, 65 'descriptor': {shape: [], dataType: 'float32'} 66 } 67 } 68 } 69 }, 70 { 71 'name': 'reduceL2 float32 0D constant tensor empty axes', 72 'graph': { 73 'inputs': { 74 'reduceL2Input': { 75 'data': [4.860228061676025], 76 'descriptor': {shape: [], dataType: 'float32'}, 77 'constant': true 78 } 79 }, 80 'operators': [{ 81 'name': 'reduceL2', 82 'arguments': [{'input': 'reduceL2Input'}, {'options': {'axes': []}}], 83 'outputs': 'reduceL2Output' 84 }], 85 'expectedOutputs': { 86 'reduceL2Output': { 87 'data': 4.860228061676025, 88 'descriptor': {shape: [], dataType: 'float32'} 89 } 90 } 91 } 92 }, 93 { 94 'name': 'reduceL2 float32 0D tensor empty axes', 95 'graph': { 96 'inputs': { 97 'reduceL2Input': { 98 'data': [4.860228061676025], 99 'descriptor': {shape: [], dataType: 'float32'}, 100 'constant': false 101 } 102 }, 103 'operators': [{ 104 'name': 'reduceL2', 105 'arguments': [{'input': 'reduceL2Input'}, {'options': {'axes': []}}], 106 'outputs': 'reduceL2Output' 107 }], 108 'expectedOutputs': { 109 'reduceL2Output': { 110 'data': 4.860228061676025, 111 'descriptor': {shape: [], dataType: 'float32'} 112 } 113 } 114 } 115 }, 116 { 117 'name': 'reduceL2 float32 1D constant tensor empty axes', 118 'graph': { 119 'inputs': { 120 'reduceL2Input': { 121 'data': [-4.860228061676025, 4.860228061676024], 122 'descriptor': {shape: [2], dataType: 'float32'}, 123 'constant': true 124 } 125 }, 126 'operators': [{ 127 'name': 'reduceL2', 128 'arguments': [{'input': 'reduceL2Input'}, {'options': {'axes': []}}], 129 'outputs': 'reduceL2Output' 130 }], 131 'expectedOutputs': { 132 'reduceL2Output': { 133 'data': [4.860228061676025, 4.860228061676024], 134 'descriptor': {shape: [2], dataType: 'float32'} 135 } 136 } 137 } 138 }, 139 { 140 'name': 'reduceL2 float32 1D constant tensor all positive default options', 141 'graph': { 142 'inputs': { 143 'reduceL2Input': { 144 'data': [ 145 4.860228061676025, 88.23184204101562, 54.489688873291016, 146 64.75027465820312, 6.855991363525391, 91.39871215820312, 147 41.88857650756836, 73.65444946289062, 35.31573486328125, 148 48.345428466796875, 82.39190673828125, 77.86200714111328, 149 93.31141662597656, 62.48688507080078, 60.29290008544922, 150 13.230599403381348, 20.535987854003906, 53.45161819458008, 151 11.320085525512695, 64.75763702392578, 43.6589469909668, 152 0.8374307155609131, 0.6848266124725342, 33.504703521728516 153 ], 154 'descriptor': {shape: [24], dataType: 'float32'}, 155 'constant': true 156 } 157 }, 158 'operators': [{ 159 'name': 'reduceL2', 160 'arguments': [{'input': 'reduceL2Input'}], 161 'outputs': 'reduceL2Output' 162 }], 163 'expectedOutputs': { 164 'reduceL2Output': { 165 'data': 272.0996398925781, 166 'descriptor': {shape: [], dataType: 'float32'} 167 } 168 } 169 } 170 }, 171 { 172 'name': 'reduceL2 float32 1D tensor all positive default options', 173 'graph': { 174 'inputs': { 175 'reduceL2Input': { 176 'data': [ 177 4.860228061676025, 88.23184204101562, 54.489688873291016, 178 64.75027465820312, 6.855991363525391, 91.39871215820312, 179 41.88857650756836, 73.65444946289062, 35.31573486328125, 180 48.345428466796875, 82.39190673828125, 77.86200714111328, 181 93.31141662597656, 62.48688507080078, 60.29290008544922, 182 13.230599403381348, 20.535987854003906, 53.45161819458008, 183 11.320085525512695, 64.75763702392578, 43.6589469909668, 184 0.8374307155609131, 0.6848266124725342, 33.504703521728516 185 ], 186 'descriptor': {shape: [24], dataType: 'float32'} 187 } 188 }, 189 'operators': [{ 190 'name': 'reduceL2', 191 'arguments': [{'input': 'reduceL2Input'}], 192 'outputs': 'reduceL2Output' 193 }], 194 'expectedOutputs': { 195 'reduceL2Output': { 196 'data': 272.0996398925781, 197 'descriptor': {shape: [], dataType: 'float32'} 198 } 199 } 200 } 201 }, 202 { 203 'name': 'reduceL2 float32 1D tensor all negative default options', 204 'graph': { 205 'inputs': { 206 'reduceL2Input': { 207 'data': [ 208 -66.80043029785156, -53.00004959106445, -59.58587646484375, 209 -46.14392852783203, -49.60614013671875, -12.832738876342773, 210 -88.05061340332031, -75.56246185302734, -50.76777648925781, 211 -36.96630096435547, -26.344043731689453, -58.90546417236328, 212 -94.28752899169922, -22.7802791595459, -84.3487777709961, 213 -60.47734451293945, -41.455806732177734, -92.84781646728516, 214 -85.05448913574219, -30.235260009765625, -47.33808135986328, 215 -25.268428802490234, -78.11959075927734, -28.330944061279297 216 ], 217 'descriptor': {shape: [24], dataType: 'float32'} 218 } 219 }, 220 'operators': [{ 221 'name': 'reduceL2', 222 'arguments': [{'input': 'reduceL2Input'}], 223 'outputs': 'reduceL2Output' 224 }], 225 'expectedOutputs': { 226 'reduceL2Output': { 227 'data': 292.57574462890625, 228 'descriptor': {shape: [], dataType: 'float32'} 229 } 230 } 231 } 232 }, 233 { 234 'name': 'reduceL2 float32 1D tensor all positive integers default options', 235 'graph': { 236 'inputs': { 237 'reduceL2Input': { 238 'data': [ 239 4, 29, 8, 56, 42, 78, 89, 64, 56, 81, 85, 18, 240 6, 39, 35, 63, 87, 50, 81, 89, 5, 8, 37, 37 241 ], 242 'descriptor': {shape: [24], dataType: 'float32'} 243 } 244 }, 245 'operators': [{ 246 'name': 'reduceL2', 247 'arguments': [{'input': 'reduceL2Input'}], 248 'outputs': 'reduceL2Output' 249 }], 250 'expectedOutputs': { 251 'reduceL2Output': { 252 'data': 274.4029846191406, 253 'descriptor': {shape: [], dataType: 'float32'} 254 } 255 } 256 } 257 }, 258 { 259 'name': 'reduceL2 float32 1D tensor all negative integers default options', 260 'graph': { 261 'inputs': { 262 'reduceL2Input': { 263 'data': [ 264 -70, -78, -65, -77, -25, -47, -63, -67, -66, -15, -28, -75, 265 -88, -54, -13, -27, -5, -18, -68, -71, -50, -56, -99, -99 266 ], 267 'descriptor': {shape: [24], dataType: 'float32'} 268 } 269 }, 270 'operators': [{ 271 'name': 'reduceL2', 272 'arguments': [{'input': 'reduceL2Input'}], 273 'outputs': 'reduceL2Output' 274 }], 275 'expectedOutputs': { 276 'reduceL2Output': { 277 'data': 300.3830871582031, 278 'descriptor': {shape: [], dataType: 'float32'} 279 } 280 } 281 } 282 }, 283 { 284 'name': 'reduceL2 float32 2D tensor default options', 285 'graph': { 286 'inputs': { 287 'reduceL2Input': { 288 'data': [ 289 4.860228061676025, 88.23184204101562, 54.489688873291016, 290 64.75027465820312, 6.855991363525391, 91.39871215820312, 291 41.88857650756836, 73.65444946289062, 35.31573486328125, 292 48.345428466796875, 82.39190673828125, 77.86200714111328, 293 93.31141662597656, 62.48688507080078, 60.29290008544922, 294 13.230599403381348, 20.535987854003906, 53.45161819458008, 295 11.320085525512695, 64.75763702392578, 43.6589469909668, 296 0.8374307155609131, 0.6848266124725342, 33.504703521728516 297 ], 298 'descriptor': {shape: [4, 6], dataType: 'float32'} 299 } 300 }, 301 'operators': [{ 302 'name': 'reduceL2', 303 'arguments': [{'input': 'reduceL2Input'}], 304 'outputs': 'reduceL2Output' 305 }], 306 'expectedOutputs': { 307 'reduceL2Output': { 308 'data': 272.0996398925781, 309 'descriptor': {shape: [], dataType: 'float32'} 310 } 311 } 312 } 313 }, 314 { 315 'name': 'reduceL2 float32 3D tensor default options', 316 'graph': { 317 'inputs': { 318 'reduceL2Input': { 319 'data': [ 320 4.860228061676025, 88.23184204101562, 54.489688873291016, 321 64.75027465820312, 6.855991363525391, 91.39871215820312, 322 41.88857650756836, 73.65444946289062, 35.31573486328125, 323 48.345428466796875, 82.39190673828125, 77.86200714111328, 324 93.31141662597656, 62.48688507080078, 60.29290008544922, 325 13.230599403381348, 20.535987854003906, 53.45161819458008, 326 11.320085525512695, 64.75763702392578, 43.6589469909668, 327 0.8374307155609131, 0.6848266124725342, 33.504703521728516 328 ], 329 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 330 } 331 }, 332 'operators': [{ 333 'name': 'reduceL2', 334 'arguments': [{'input': 'reduceL2Input'}], 335 'outputs': 'reduceL2Output' 336 }], 337 'expectedOutputs': { 338 'reduceL2Output': { 339 'data': 272.0996398925781, 340 'descriptor': {shape: [], dataType: 'float32'} 341 } 342 } 343 } 344 }, 345 { 346 'name': 'reduceL2 float32 4D tensor default options', 347 'graph': { 348 'inputs': { 349 'reduceL2Input': { 350 'data': [ 351 4.860228061676025, 88.23184204101562, 54.489688873291016, 352 64.75027465820312, 6.855991363525391, 91.39871215820312, 353 41.88857650756836, 73.65444946289062, 35.31573486328125, 354 48.345428466796875, 82.39190673828125, 77.86200714111328, 355 93.31141662597656, 62.48688507080078, 60.29290008544922, 356 13.230599403381348, 20.535987854003906, 53.45161819458008, 357 11.320085525512695, 64.75763702392578, 43.6589469909668, 358 0.8374307155609131, 0.6848266124725342, 33.504703521728516 359 ], 360 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 361 } 362 }, 363 'operators': [{ 364 'name': 'reduceL2', 365 'arguments': [{'input': 'reduceL2Input'}], 366 'outputs': 'reduceL2Output' 367 }], 368 'expectedOutputs': { 369 'reduceL2Output': { 370 'data': 272.0996398925781, 371 'descriptor': {shape: [], dataType: 'float32'} 372 } 373 } 374 } 375 }, 376 { 377 'name': 'reduceL2 float32 5D tensor default options', 378 'graph': { 379 'inputs': { 380 'reduceL2Input': { 381 'data': [ 382 4.860228061676025, 88.23184204101562, 54.489688873291016, 383 64.75027465820312, 6.855991363525391, 91.39871215820312, 384 41.88857650756836, 73.65444946289062, 35.31573486328125, 385 48.345428466796875, 82.39190673828125, 77.86200714111328, 386 93.31141662597656, 62.48688507080078, 60.29290008544922, 387 13.230599403381348, 20.535987854003906, 53.45161819458008, 388 11.320085525512695, 64.75763702392578, 43.6589469909668, 389 0.8374307155609131, 0.6848266124725342, 33.504703521728516 390 ], 391 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 392 } 393 }, 394 'operators': [{ 395 'name': 'reduceL2', 396 'arguments': [{'input': 'reduceL2Input'}], 397 'outputs': 'reduceL2Output' 398 }], 399 'expectedOutputs': { 400 'reduceL2Output': { 401 'data': 272.0996398925781, 402 'descriptor': {shape: [], dataType: 'float32'} 403 } 404 } 405 } 406 }, 407 { 408 'name': 'reduceL2 float32 3D tensor options.axes', 409 'graph': { 410 'inputs': { 411 'reduceL2Input': { 412 'data': [ 413 4.860228061676025, 88.23184204101562, 54.489688873291016, 414 64.75027465820312, 6.855991363525391, 91.39871215820312, 415 41.88857650756836, 73.65444946289062, 35.31573486328125, 416 48.345428466796875, 82.39190673828125, 77.86200714111328, 417 93.31141662597656, 62.48688507080078, 60.29290008544922, 418 13.230599403381348, 20.535987854003906, 53.45161819458008, 419 11.320085525512695, 64.75763702392578, 43.6589469909668, 420 0.8374307155609131, 0.6848266124725342, 33.504703521728516 421 ], 422 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 423 } 424 }, 425 'operators': [{ 426 'name': 'reduceL2', 427 'arguments': [{'input': 'reduceL2Input'}, {'options': {'axes': [2]}}], 428 'outputs': 'reduceL2Output' 429 }], 430 'expectedOutputs': { 431 'reduceL2Output': { 432 'data': [ 433 122.352783203125, 124.8213119506836, 128.20062255859375, 434 128.14801025390625, 87.18083953857422, 55.043975830078125 435 ], 436 'descriptor': {shape: [2, 3], dataType: 'float32'} 437 } 438 } 439 } 440 }, 441 { 442 'name': 'reduceL2 float32 4D tensor options.axes', 443 'graph': { 444 'inputs': { 445 'reduceL2Input': { 446 'data': [ 447 4.860228061676025, 88.23184204101562, 54.489688873291016, 448 64.75027465820312, 6.855991363525391, 91.39871215820312, 449 41.88857650756836, 73.65444946289062, 35.31573486328125, 450 48.345428466796875, 82.39190673828125, 77.86200714111328, 451 93.31141662597656, 62.48688507080078, 60.29290008544922, 452 13.230599403381348, 20.535987854003906, 53.45161819458008, 453 11.320085525512695, 64.75763702392578, 43.6589469909668, 454 0.8374307155609131, 0.6848266124725342, 33.504703521728516 455 ], 456 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 457 } 458 }, 459 'operators': [{ 460 'name': 'reduceL2', 461 'arguments': 462 [{'input': 'reduceL2Input'}, {'options': {'axes': [0, 2]}}], 463 'outputs': 'reduceL2Output' 464 }], 465 'expectedOutputs': { 466 'reduceL2Output': { 467 'data': [ 468 114.44775390625, 110.26422882080078, 133.47344970703125, 469 64.96752166748047, 128.0914764404297, 101.677734375 470 ], 471 'descriptor': {shape: [2, 3], dataType: 'float32'} 472 } 473 } 474 } 475 }, 476 { 477 'name': 'reduceL2 float32 3D tensor options.keepDimensions=false', 478 'graph': { 479 'inputs': { 480 'reduceL2Input': { 481 'data': [ 482 4.860228061676025, 88.23184204101562, 54.489688873291016, 483 64.75027465820312, 6.855991363525391, 91.39871215820312, 484 41.88857650756836, 73.65444946289062, 35.31573486328125, 485 48.345428466796875, 82.39190673828125, 77.86200714111328, 486 93.31141662597656, 62.48688507080078, 60.29290008544922, 487 13.230599403381348, 20.535987854003906, 53.45161819458008, 488 11.320085525512695, 64.75763702392578, 43.6589469909668, 489 0.8374307155609131, 0.6848266124725342, 33.504703521728516 490 ], 491 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 492 } 493 }, 494 'operators': [{ 495 'name': 'reduceL2', 496 'arguments': [ 497 {'input': 'reduceL2Input'}, {'options': {'keepDimensions': false}} 498 ], 499 'outputs': 'reduceL2Output' 500 }], 501 'expectedOutputs': { 502 'reduceL2Output': { 503 'data': 272.0996398925781, 504 'descriptor': {shape: [], dataType: 'float32'} 505 } 506 } 507 } 508 }, 509 { 510 'name': 'reduceL2 float32 3D tensor options.keepDimensions=true', 511 'graph': { 512 'inputs': { 513 'reduceL2Input': { 514 'data': [ 515 4.860228061676025, 88.23184204101562, 54.489688873291016, 516 64.75027465820312, 6.855991363525391, 91.39871215820312, 517 41.88857650756836, 73.65444946289062, 35.31573486328125, 518 48.345428466796875, 82.39190673828125, 77.86200714111328, 519 93.31141662597656, 62.48688507080078, 60.29290008544922, 520 13.230599403381348, 20.535987854003906, 53.45161819458008, 521 11.320085525512695, 64.75763702392578, 43.6589469909668, 522 0.8374307155609131, 0.6848266124725342, 33.504703521728516 523 ], 524 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 525 } 526 }, 527 'operators': [{ 528 'name': 'reduceL2', 529 'arguments': 530 [{'input': 'reduceL2Input'}, {'options': {'keepDimensions': true}}], 531 'outputs': 'reduceL2Output' 532 }], 533 'expectedOutputs': { 534 'reduceL2Output': { 535 'data': [272.0996398925781], 536 'descriptor': {shape: [1, 1, 1], dataType: 'float32'} 537 } 538 } 539 } 540 }, 541 { 542 'name': 'reduceL2 float32 4D tensor options.keepDimensions=false', 543 'graph': { 544 'inputs': { 545 'reduceL2Input': { 546 'data': [ 547 4.860228061676025, 88.23184204101562, 54.489688873291016, 548 64.75027465820312, 6.855991363525391, 91.39871215820312, 549 41.88857650756836, 73.65444946289062, 35.31573486328125, 550 48.345428466796875, 82.39190673828125, 77.86200714111328, 551 93.31141662597656, 62.48688507080078, 60.29290008544922, 552 13.230599403381348, 20.535987854003906, 53.45161819458008, 553 11.320085525512695, 64.75763702392578, 43.6589469909668, 554 0.8374307155609131, 0.6848266124725342, 33.504703521728516 555 ], 556 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 557 } 558 }, 559 'operators': [{ 560 'name': 'reduceL2', 561 'arguments': [ 562 {'input': 'reduceL2Input'}, {'options': {'keepDimensions': false}} 563 ], 564 'outputs': 'reduceL2Output' 565 }], 566 'expectedOutputs': { 567 'reduceL2Output': { 568 'data': 272.0996398925781, 569 'descriptor': {shape: [], dataType: 'float32'} 570 } 571 } 572 } 573 }, 574 { 575 'name': 'reduceL2 float32 4D tensor options.keepDimensions=true', 576 'graph': { 577 'inputs': { 578 'reduceL2Input': { 579 'data': [ 580 4.860228061676025, 88.23184204101562, 54.489688873291016, 581 64.75027465820312, 6.855991363525391, 91.39871215820312, 582 41.88857650756836, 73.65444946289062, 35.31573486328125, 583 48.345428466796875, 82.39190673828125, 77.86200714111328, 584 93.31141662597656, 62.48688507080078, 60.29290008544922, 585 13.230599403381348, 20.535987854003906, 53.45161819458008, 586 11.320085525512695, 64.75763702392578, 43.6589469909668, 587 0.8374307155609131, 0.6848266124725342, 33.504703521728516 588 ], 589 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 590 } 591 }, 592 'operators': [{ 593 'name': 'reduceL2', 594 'arguments': 595 [{'input': 'reduceL2Input'}, {'options': {'keepDimensions': true}}], 596 'outputs': 'reduceL2Output' 597 }], 598 'expectedOutputs': { 599 'reduceL2Output': { 600 'data': [272.0996398925781], 601 'descriptor': {shape: [1, 1, 1, 1], dataType: 'float32'} 602 } 603 } 604 } 605 }, 606 { 607 'name': 608 'reduceL2 float32 4D tensor options.axes with options.keepDimensions=false', 609 'graph': { 610 'inputs': { 611 'reduceL2Input': { 612 'data': [ 613 4.860228061676025, 88.23184204101562, 54.489688873291016, 614 64.75027465820312, 6.855991363525391, 91.39871215820312, 615 41.88857650756836, 73.65444946289062, 35.31573486328125, 616 48.345428466796875, 82.39190673828125, 77.86200714111328, 617 93.31141662597656, 62.48688507080078, 60.29290008544922, 618 13.230599403381348, 20.535987854003906, 53.45161819458008, 619 11.320085525512695, 64.75763702392578, 43.6589469909668, 620 0.8374307155609131, 0.6848266124725342, 33.504703521728516 621 ], 622 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 623 } 624 }, 625 'operators': [{ 626 'name': 'reduceL2', 627 'arguments': [ 628 {'input': 'reduceL2Input'}, 629 {'options': {'axes': [1, 3], 'keepDimensions': false}} 630 ], 631 'outputs': 'reduceL2Output' 632 }], 633 'expectedOutputs': { 634 'reduceL2Output': { 635 'data': [ 636 138.580078125, 166.67791748046875, 149.91552734375, 67.6578598022461 637 ], 638 'descriptor': {shape: [2, 2], dataType: 'float32'} 639 } 640 } 641 } 642 }, 643 { 644 'name': 645 'reduceL2 float32 4D tensor options.axes with options.keepDimensions=true', 646 'graph': { 647 'inputs': { 648 'reduceL2Input': { 649 'data': [ 650 4.860228061676025, 88.23184204101562, 54.489688873291016, 651 64.75027465820312, 6.855991363525391, 91.39871215820312, 652 41.88857650756836, 73.65444946289062, 35.31573486328125, 653 48.345428466796875, 82.39190673828125, 77.86200714111328, 654 93.31141662597656, 62.48688507080078, 60.29290008544922, 655 13.230599403381348, 20.535987854003906, 53.45161819458008, 656 11.320085525512695, 64.75763702392578, 43.6589469909668, 657 0.8374307155609131, 0.6848266124725342, 33.504703521728516 658 ], 659 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 660 } 661 }, 662 'operators': [{ 663 'name': 'reduceL2', 664 'arguments': [ 665 {'input': 'reduceL2Input'}, 666 {'options': {'axes': [1, 3], 'keepDimensions': true}} 667 ], 668 'outputs': 'reduceL2Output' 669 }], 670 'expectedOutputs': { 671 'reduceL2Output': { 672 'data': [ 673 138.580078125, 166.67791748046875, 149.91552734375, 67.6578598022461 674 ], 675 'descriptor': {shape: [2, 1, 2, 1], dataType: 'float32'} 676 } 677 } 678 } 679 }, 680 681 // float16 tests 682 { 683 'name': 'reduceL2 float16 0D constant tensor default options', 684 'graph': { 685 'inputs': { 686 'reduceL2Input': { 687 'data': [4.859375], 688 'descriptor': {shape: [], dataType: 'float16'}, 689 'constant': true 690 } 691 }, 692 'operators': [{ 693 'name': 'reduceL2', 694 'arguments': [{'input': 'reduceL2Input'}], 695 'outputs': 'reduceL2Output' 696 }], 697 'expectedOutputs': { 698 'reduceL2Output': 699 {'data': [4.859375], 'descriptor': {shape: [], dataType: 'float16'}} 700 } 701 } 702 }, 703 { 704 'name': 'reduceL2 float16 0D tensor default options', 705 'graph': { 706 'inputs': { 707 'reduceL2Input': { 708 'data': [4.859375], 709 'descriptor': {shape: [], dataType: 'float16'}, 710 'constant': false 711 } 712 }, 713 'operators': [{ 714 'name': 'reduceL2', 715 'arguments': [{'input': 'reduceL2Input'}], 716 'outputs': 'reduceL2Output' 717 }], 718 'expectedOutputs': { 719 'reduceL2Output': 720 {'data': [4.859375], 'descriptor': {shape: [], dataType: 'float16'}} 721 } 722 } 723 }, 724 { 725 'name': 'reduceL2 float16 0D constant tensor empty axes', 726 'graph': { 727 'inputs': { 728 'reduceL2Input': { 729 'data': [4.859375], 730 'descriptor': {shape: [], dataType: 'float16'}, 731 'constant': true 732 } 733 }, 734 'operators': [{ 735 'name': 'reduceL2', 736 'arguments': [{'input': 'reduceL2Input'}, {'options': {'axes': []}}], 737 'outputs': 'reduceL2Output' 738 }], 739 'expectedOutputs': { 740 'reduceL2Output': 741 {'data': [4.859375], 'descriptor': {shape: [], dataType: 'float16'}} 742 } 743 } 744 }, 745 { 746 'name': 'reduceL2 float16 0D tensor empty axes', 747 'graph': { 748 'inputs': { 749 'reduceL2Input': { 750 'data': [4.859375], 751 'descriptor': {shape: [], dataType: 'float16'}, 752 'constant': false 753 } 754 }, 755 'operators': [{ 756 'name': 'reduceL2', 757 'arguments': [{'input': 'reduceL2Input'}, {'options': {'axes': []}}], 758 'outputs': 'reduceL2Output' 759 }], 760 'expectedOutputs': { 761 'reduceL2Output': 762 {'data': [4.859375], 'descriptor': {shape: [], dataType: 'float16'}} 763 } 764 } 765 }, 766 { 767 'name': 'reduceL2 float16 1D constant tensor all positive default options', 768 'graph': { 769 'inputs': { 770 'reduceL2Input': { 771 'data': [ 772 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 773 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 774 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 775 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 776 ], 777 'descriptor': {shape: [24], dataType: 'float16'}, 778 'constant': true 779 } 780 }, 781 'operators': [{ 782 'name': 'reduceL2', 783 'arguments': [{'input': 'reduceL2Input'}], 784 'outputs': 'reduceL2Output' 785 }], 786 'expectedOutputs': { 787 'reduceL2Output': 788 {'data': [272], 'descriptor': {shape: [], dataType: 'float16'}} 789 } 790 } 791 }, 792 { 793 'name': 'reduceL2 float16 1D tensor all positive default options', 794 'graph': { 795 'inputs': { 796 'reduceL2Input': { 797 'data': [ 798 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 799 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 800 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 801 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 802 ], 803 'descriptor': {shape: [24], dataType: 'float16'} 804 } 805 }, 806 'operators': [{ 807 'name': 'reduceL2', 808 'arguments': [{'input': 'reduceL2Input'}], 809 'outputs': 'reduceL2Output' 810 }], 811 'expectedOutputs': { 812 'reduceL2Output': 813 {'data': [272], 'descriptor': {shape: [], dataType: 'float16'}} 814 } 815 } 816 }, 817 { 818 'name': 'reduceL2 float16 1D tensor all negative default options', 819 'graph': { 820 'inputs': { 821 'reduceL2Input': { 822 'data': [ 823 -66.8125, -53, -59.59375, -46.15625, -49.59375, -12.8359375, 824 -88.0625, -75.5625, -50.78125, -36.96875, -26.34375, -58.90625, 825 -94.3125, -22.78125, -84.375, -60.46875, -41.46875, -92.875, 826 -85.0625, -30.234375, -47.34375, -25.265625, -78.125, -28.328125 827 ], 828 'descriptor': {shape: [24], dataType: 'float16'} 829 } 830 }, 831 'operators': [{ 832 'name': 'reduceL2', 833 'arguments': [{'input': 'reduceL2Input'}], 834 'outputs': 'reduceL2Output' 835 }], 836 'expectedOutputs': { 837 'reduceL2Output': 838 {'data': [292.5], 'descriptor': {shape: [], dataType: 'float16'}} 839 } 840 } 841 }, 842 { 843 'name': 'reduceL2 float16 1D tensor all positive integers default options', 844 'graph': { 845 'inputs': { 846 'reduceL2Input': { 847 'data': [ 848 4, 29, 8, 56, 42, 78, 89, 64, 56, 81, 85, 18, 849 6, 39, 35, 63, 87, 50, 81, 89, 5, 8, 37, 37 850 ], 851 'descriptor': {shape: [24], dataType: 'float16'} 852 } 853 }, 854 'operators': [{ 855 'name': 'reduceL2', 856 'arguments': [{'input': 'reduceL2Input'}], 857 'outputs': 'reduceL2Output' 858 }], 859 'expectedOutputs': { 860 'reduceL2Output': 861 {'data': [274.5], 'descriptor': {shape: [], dataType: 'float16'}} 862 } 863 } 864 }, 865 { 866 'name': 'reduceL2 float16 1D tensor all negative integers default options', 867 'graph': { 868 'inputs': { 869 'reduceL2Input': { 870 'data': [ 871 -70, -78, -65, -77, -25, -47, -63, -67, -66, -15, -28, -75, 872 -88, -54, -13, -27, -5, -18, -68, -71, -50, -56, -99, -99 873 ], 874 'descriptor': {shape: [24], dataType: 'float16'} 875 } 876 }, 877 'operators': [{ 878 'name': 'reduceL2', 879 'arguments': [{'input': 'reduceL2Input'}], 880 'outputs': 'reduceL2Output' 881 }], 882 'expectedOutputs': { 883 'reduceL2Output': 884 {'data': [300.5], 'descriptor': {shape: [], dataType: 'float16'}} 885 } 886 } 887 }, 888 { 889 'name': 'reduceL2 float16 2D tensor default options', 890 'graph': { 891 'inputs': { 892 'reduceL2Input': { 893 'data': [ 894 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 895 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 896 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 897 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 898 ], 899 'descriptor': {shape: [4, 6], dataType: 'float16'} 900 } 901 }, 902 'operators': [{ 903 'name': 'reduceL2', 904 'arguments': [{'input': 'reduceL2Input'}], 905 'outputs': 'reduceL2Output' 906 }], 907 'expectedOutputs': { 908 'reduceL2Output': 909 {'data': [272], 'descriptor': {shape: [], dataType: 'float16'}} 910 } 911 } 912 }, 913 { 914 'name': 'reduceL2 float16 3D tensor default options', 915 'graph': { 916 'inputs': { 917 'reduceL2Input': { 918 'data': [ 919 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 920 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 921 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 922 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 923 ], 924 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 925 } 926 }, 927 'operators': [{ 928 'name': 'reduceL2', 929 'arguments': [{'input': 'reduceL2Input'}], 930 'outputs': 'reduceL2Output' 931 }], 932 'expectedOutputs': { 933 'reduceL2Output': 934 {'data': [272], 'descriptor': {shape: [], dataType: 'float16'}} 935 } 936 } 937 }, 938 { 939 'name': 'reduceL2 float16 4D tensor default options', 940 'graph': { 941 'inputs': { 942 'reduceL2Input': { 943 'data': [ 944 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 945 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 946 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 947 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 948 ], 949 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 950 } 951 }, 952 'operators': [{ 953 'name': 'reduceL2', 954 'arguments': [{'input': 'reduceL2Input'}], 955 'outputs': 'reduceL2Output' 956 }], 957 'expectedOutputs': { 958 'reduceL2Output': 959 {'data': [272], 'descriptor': {shape: [], dataType: 'float16'}} 960 } 961 } 962 }, 963 { 964 'name': 'reduceL2 float16 5D tensor default options', 965 'graph': { 966 'inputs': { 967 'reduceL2Input': { 968 'data': [ 969 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 970 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 971 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 972 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 973 ], 974 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 975 } 976 }, 977 'operators': [{ 978 'name': 'reduceL2', 979 'arguments': [{'input': 'reduceL2Input'}], 980 'outputs': 'reduceL2Output' 981 }], 982 'expectedOutputs': { 983 'reduceL2Output': 984 {'data': [272], 'descriptor': {shape: [], dataType: 'float16'}} 985 } 986 } 987 }, 988 { 989 'name': 'reduceL2 float16 3D tensor options.axes', 990 'graph': { 991 'inputs': { 992 'reduceL2Input': { 993 'data': [ 994 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 995 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 996 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 997 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 998 ], 999 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 1000 } 1001 }, 1002 'operators': [{ 1003 'name': 'reduceL2', 1004 'arguments': [{'input': 'reduceL2Input'}, {'options': {'axes': [2]}}], 1005 'outputs': 'reduceL2Output' 1006 }], 1007 'expectedOutputs': { 1008 'reduceL2Output': { 1009 'data': [122.375, 124.8125, 128.25, 128.125, 87.1875, 55.03125], 1010 'descriptor': {shape: [2, 3], dataType: 'float16'} 1011 } 1012 } 1013 } 1014 }, 1015 { 1016 'name': 'reduceL2 float16 4D tensor options.axes', 1017 'graph': { 1018 'inputs': { 1019 'reduceL2Input': { 1020 'data': [ 1021 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 1022 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 1023 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 1024 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 1025 ], 1026 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 1027 } 1028 }, 1029 'operators': [{ 1030 'name': 'reduceL2', 1031 'arguments': 1032 [{'input': 'reduceL2Input'}, {'options': {'axes': [0, 2]}}], 1033 'outputs': 'reduceL2Output' 1034 }], 1035 'expectedOutputs': { 1036 'reduceL2Output': { 1037 'data': [114.4375, 110.3125, 133.5, 64.9375, 128, 101.6875], 1038 'descriptor': {shape: [2, 3], dataType: 'float16'} 1039 } 1040 } 1041 } 1042 }, 1043 { 1044 'name': 'reduceL2 float16 3D tensor options.keepDimensions=false', 1045 'graph': { 1046 'inputs': { 1047 'reduceL2Input': { 1048 'data': [ 1049 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 1050 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 1051 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 1052 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 1053 ], 1054 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 1055 } 1056 }, 1057 'operators': [{ 1058 'name': 'reduceL2', 1059 'arguments': [ 1060 {'input': 'reduceL2Input'}, {'options': {'keepDimensions': false}} 1061 ], 1062 'outputs': 'reduceL2Output' 1063 }], 1064 'expectedOutputs': { 1065 'reduceL2Output': 1066 {'data': [272], 'descriptor': {shape: [], dataType: 'float16'}} 1067 } 1068 } 1069 }, 1070 { 1071 'name': 'reduceL2 float16 3D tensor options.keepDimensions=true', 1072 'graph': { 1073 'inputs': { 1074 'reduceL2Input': { 1075 'data': [ 1076 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 1077 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 1078 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 1079 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 1080 ], 1081 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 1082 } 1083 }, 1084 'operators': [{ 1085 'name': 'reduceL2', 1086 'arguments': 1087 [{'input': 'reduceL2Input'}, {'options': {'keepDimensions': true}}], 1088 'outputs': 'reduceL2Output' 1089 }], 1090 'expectedOutputs': { 1091 'reduceL2Output': { 1092 'data': [272], 1093 'descriptor': {shape: [1, 1, 1], dataType: 'float16'} 1094 } 1095 } 1096 } 1097 }, 1098 { 1099 'name': 'reduceL2 float16 4D tensor options.keepDimensions=false', 1100 'graph': { 1101 'inputs': { 1102 'reduceL2Input': { 1103 'data': [ 1104 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 1105 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 1106 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 1107 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 1108 ], 1109 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 1110 } 1111 }, 1112 'operators': [{ 1113 'name': 'reduceL2', 1114 'arguments': [ 1115 {'input': 'reduceL2Input'}, {'options': {'keepDimensions': false}} 1116 ], 1117 'outputs': 'reduceL2Output' 1118 }], 1119 'expectedOutputs': { 1120 'reduceL2Output': 1121 {'data': [272], 'descriptor': {shape: [], dataType: 'float16'}} 1122 } 1123 } 1124 }, 1125 { 1126 'name': 'reduceL2 float16 4D tensor options.keepDimensions=true', 1127 'graph': { 1128 'inputs': { 1129 'reduceL2Input': { 1130 'data': [ 1131 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 1132 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 1133 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 1134 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 1135 ], 1136 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 1137 } 1138 }, 1139 'operators': [{ 1140 'name': 'reduceL2', 1141 'arguments': 1142 [{'input': 'reduceL2Input'}, {'options': {'keepDimensions': true}}], 1143 'outputs': 'reduceL2Output' 1144 }], 1145 'expectedOutputs': { 1146 'reduceL2Output': { 1147 'data': [272], 1148 'descriptor': {shape: [1, 1, 1, 1], dataType: 'float16'} 1149 } 1150 } 1151 } 1152 }, 1153 { 1154 'name': 1155 'reduceL2 float16 4D tensor options.axes with options.keepDimensions=false', 1156 'graph': { 1157 'inputs': { 1158 'reduceL2Input': { 1159 'data': [ 1160 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 1161 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 1162 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 1163 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 1164 ], 1165 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 1166 } 1167 }, 1168 'operators': [{ 1169 'name': 'reduceL2', 1170 'arguments': [ 1171 {'input': 'reduceL2Input'}, 1172 {'options': {'axes': [1, 3], 'keepDimensions': false}} 1173 ], 1174 'outputs': 'reduceL2Output' 1175 }], 1176 'expectedOutputs': { 1177 'reduceL2Output': { 1178 'data': [138.625, 166.625, 149.875, 67.625], 1179 'descriptor': {shape: [2, 2], dataType: 'float16'} 1180 } 1181 } 1182 } 1183 }, 1184 { 1185 'name': 1186 'reduceL2 float16 4D tensor options.axes with options.keepDimensions=true', 1187 'graph': { 1188 'inputs': { 1189 'reduceL2Input': { 1190 'data': [ 1191 4.859375, 88.25, 54.5, 64.75, 6.85546875, 91.375, 1192 41.875, 73.625, 35.3125, 48.34375, 82.375, 77.875, 1193 93.3125, 62.5, 60.28125, 13.234375, 20.53125, 53.4375, 1194 11.3203125, 64.75, 43.65625, 0.83740234375, 0.68505859375, 33.5 1195 ], 1196 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 1197 } 1198 }, 1199 'operators': [{ 1200 'name': 'reduceL2', 1201 'arguments': [ 1202 {'input': 'reduceL2Input'}, 1203 {'options': {'axes': [1, 3], 'keepDimensions': true}} 1204 ], 1205 'outputs': 'reduceL2Output' 1206 }], 1207 'expectedOutputs': { 1208 'reduceL2Output': { 1209 'data': [138.625, 166.625, 149.875, 67.625], 1210 'descriptor': {shape: [2, 1, 2, 1], dataType: 'float16'} 1211 } 1212 } 1213 } 1214 } 1215 ]; 1216 1217 webnn_conformance_test( 1218 reduceL2Tests, buildAndExecuteGraph, getPrecisionTolerance);