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