clamp.https.any.js (63507B)
1 // META: title=test WebNN API clamp 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-clamp 12 // Clamp the input tensor element-wise within a range specified by the minimum 13 // and maximum values. 14 // 15 // dictionary MLClampOptions { 16 // MLNumber minValue; 17 // MLNumber maxValue; 18 // }; 19 // 20 // MLOperand clamp(MLOperand input, optional MLClampOptions options = {}); 21 22 const clampTests = [ 23 { 24 'name': 'clamp float32 0D tensor default options', 25 'graph': { 26 'inputs': { 27 'clampInput': { 28 'data': [-9.817828178405762], 29 'descriptor': {shape: [], dataType: 'float32'} 30 } 31 }, 32 'operators': [{ 33 'name': 'clamp', 34 'arguments': [{'input': 'clampInput'}], 35 'outputs': 'clampOutput' 36 }], 37 'expectedOutputs': { 38 'clampOutput': { 39 'data': [-9.817828178405762], 40 'descriptor': {shape: [], dataType: 'float32'} 41 } 42 } 43 } 44 }, 45 { 46 'name': 'clamp float32 1D constant tensor default options', 47 'graph': { 48 'inputs': { 49 'clampInput': { 50 'data': [ 51 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 52 -6.575078010559082, -7.755683898925781, 9.524681091308594, 53 3.7292487621307373, 6.481687068939209, -1.537420630455017, 54 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 55 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 56 -8.199960708618164, -7.786487102508545, 9.280223846435547, 57 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 58 5.549378395080566, 7.409400463104248, -2.123614549636841 59 ], 60 'descriptor': {shape: [24], dataType: 'float32'}, 61 'constant': true 62 } 63 }, 64 'operators': [{ 65 'name': 'clamp', 66 'arguments': [{'input': 'clampInput'}], 67 'outputs': 'clampOutput' 68 }], 69 'expectedOutputs': { 70 'clampOutput': { 71 'data': [ 72 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 73 -6.575078010559082, -7.755683898925781, 9.524681091308594, 74 3.7292487621307373, 6.481687068939209, -1.537420630455017, 75 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 76 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 77 -8.199960708618164, -7.786487102508545, 9.280223846435547, 78 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 79 5.549378395080566, 7.409400463104248, -2.123614549636841 80 ], 81 'descriptor': {shape: [24], dataType: 'float32'} 82 } 83 } 84 } 85 }, 86 { 87 'name': 'clamp float32 1D tensor default options', 88 'graph': { 89 'inputs': { 90 'clampInput': { 91 'data': [ 92 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 93 -6.575078010559082, -7.755683898925781, 9.524681091308594, 94 3.7292487621307373, 6.481687068939209, -1.537420630455017, 95 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 96 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 97 -8.199960708618164, -7.786487102508545, 9.280223846435547, 98 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 99 5.549378395080566, 7.409400463104248, -2.123614549636841 100 ], 101 'descriptor': {shape: [24], dataType: 'float32'} 102 } 103 }, 104 'operators': [{ 105 'name': 'clamp', 106 'arguments': [{'input': 'clampInput'}], 107 'outputs': 'clampOutput' 108 }], 109 'expectedOutputs': { 110 'clampOutput': { 111 'data': [ 112 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 113 -6.575078010559082, -7.755683898925781, 9.524681091308594, 114 3.7292487621307373, 6.481687068939209, -1.537420630455017, 115 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 116 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 117 -8.199960708618164, -7.786487102508545, 9.280223846435547, 118 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 119 5.549378395080566, 7.409400463104248, -2.123614549636841 120 ], 121 'descriptor': {shape: [24], dataType: 'float32'} 122 } 123 } 124 } 125 }, 126 { 127 'name': 'clamp int8 1D tensor', 128 'graph': { 129 'inputs': { 130 'clampInput': { 131 'data': [-128, 127, -4, -2, 1, 0, 2, 4], 132 'descriptor': {shape: [8], dataType: 'int8'} 133 } 134 }, 135 'operators': [{ 136 'name': 'clamp', 137 'arguments': [ 138 {'input': 'clampInput'}, 139 {'options': {'minValue': -2, 'maxValue': 125}} 140 ], 141 'outputs': 'clampOutput' 142 }], 143 'expectedOutputs': { 144 'clampOutput': { 145 'data': [-2, 125, -2, -2, 1, 0, 2, 4], 146 'descriptor': {shape: [8], dataType: 'int8'} 147 } 148 } 149 } 150 }, 151 { 152 'name': 'clamp uint8 1D tensor', 153 'graph': { 154 'inputs': { 155 'clampInput': { 156 'data': [255, 127, 5, 0], 157 'descriptor': {shape: [4], dataType: 'uint8'} 158 } 159 }, 160 'operators': [{ 161 'name': 'clamp', 162 'arguments': [ 163 {'input': 'clampInput'}, {'options': {'minValue': 5, 'maxValue': 200}} 164 ], 165 'outputs': 'clampOutput' 166 }], 167 'expectedOutputs': { 168 'clampOutput': { 169 'data': [200, 127, 5, 5], 170 'descriptor': {shape: [4], dataType: 'uint8'} 171 } 172 } 173 } 174 }, 175 { 176 'name': 'clamp int32 1D tensor', 177 'graph': { 178 'inputs': { 179 'clampInput': { 180 'data': [-2147483648, 2147483647, -4, -2, 1, 0, 2, 4], 181 'descriptor': {shape: [8], dataType: 'int32'} 182 } 183 }, 184 'operators': [{ 185 'name': 'clamp', 186 'arguments': [ 187 {'input': 'clampInput'}, 188 {'options': {'minValue': -2, 'maxValue': 2147483645}} 189 ], 190 'outputs': 'clampOutput' 191 }], 192 'expectedOutputs': { 193 'clampOutput': { 194 'data': [-2, 2147483645, -2, -2, 1, 0, 2, 4], 195 'descriptor': {shape: [8], dataType: 'int32'} 196 } 197 } 198 } 199 }, 200 { 201 'name': 'clamp uint32 1D tensor', 202 'graph': { 203 'inputs': { 204 'clampInput': { 205 'data': [4294967295, 127, 5, 0], 206 'descriptor': {shape: [4], dataType: 'uint32'} 207 } 208 }, 209 'operators': [{ 210 'name': 'clamp', 211 'arguments': [ 212 {'input': 'clampInput'}, 213 {'options': {'minValue': 5, 'maxValue': 4294967290}} 214 ], 215 'outputs': 'clampOutput' 216 }], 217 'expectedOutputs': { 218 'clampOutput': { 219 'data': [4294967290, 127, 5, 5], 220 'descriptor': {shape: [4], dataType: 'uint32'} 221 } 222 } 223 } 224 }, 225 { 226 'name': 'clamp int64 1D tensor with bigint max', 227 'graph': { 228 'inputs': { 229 'clampInput': { 230 'data': [-41, 9007199254740995n, -4, -2, 1, 0, 2, 4], 231 'descriptor': {shape: [8], dataType: 'int64'} 232 } 233 }, 234 'operators': [{ 235 'name': 'clamp', 236 'arguments': [ 237 {'input': 'clampInput'}, 238 {'options': {'minValue': -2, 'maxValue': 9007199254740992n}} 239 ], 240 'outputs': 'clampOutput' 241 }], 242 'expectedOutputs': { 243 'clampOutput': { 244 'data': [-2, 9007199254740992n, -2, -2, 1, 0, 2, 4], 245 'descriptor': {shape: [8], dataType: 'int64'} 246 } 247 } 248 } 249 }, 250 { 251 'name': 'clamp uint64 1D tensor with Number min and max', 252 'graph': { 253 'inputs': { 254 'clampInput': { 255 'data': [5294967295, 127, 5, 0], 256 'descriptor': {shape: [4], dataType: 'uint64'} 257 } 258 }, 259 'operators': [{ 260 'name': 'clamp', 261 'arguments': [ 262 {'input': 'clampInput'}, 263 {'options': {'minValue': 5, 'maxValue': 5294967290}} 264 ], 265 'outputs': 'clampOutput' 266 }], 267 'expectedOutputs': { 268 'clampOutput': { 269 'data': [5294967290, 127, 5, 5], 270 'descriptor': {shape: [4], dataType: 'uint64'} 271 } 272 } 273 } 274 }, 275 { 276 'name': 'clamp uint64 1D tensor with bigint max', 277 'graph': { 278 'inputs': { 279 'clampInput': { 280 'data': [9007199254740995n, 127, 5, 0], 281 'descriptor': {shape: [4], dataType: 'uint64'} 282 } 283 }, 284 'operators': [{ 285 'name': 'clamp', 286 'arguments': [ 287 {'input': 'clampInput'}, 288 {'options': {'minValue': 5, 'maxValue': 9007199254740992n}} 289 ], 290 'outputs': 'clampOutput' 291 }], 292 'expectedOutputs': { 293 'clampOutput': { 294 'data': [9007199254740992n, 127, 5, 5], 295 'descriptor': {shape: [4], dataType: 'uint64'} 296 } 297 } 298 } 299 }, 300 { 301 'name': 'clamp float32 2D tensor default options', 302 'graph': { 303 'inputs': { 304 'clampInput': { 305 'data': [ 306 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 307 -6.575078010559082, -7.755683898925781, 9.524681091308594, 308 3.7292487621307373, 6.481687068939209, -1.537420630455017, 309 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 310 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 311 -8.199960708618164, -7.786487102508545, 9.280223846435547, 312 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 313 5.549378395080566, 7.409400463104248, -2.123614549636841 314 ], 315 'descriptor': {shape: [4, 6], dataType: 'float32'} 316 } 317 }, 318 'operators': [{ 319 'name': 'clamp', 320 'arguments': [{'input': 'clampInput'}], 321 'outputs': 'clampOutput' 322 }], 323 'expectedOutputs': { 324 'clampOutput': { 325 'data': [ 326 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 327 -6.575078010559082, -7.755683898925781, 9.524681091308594, 328 3.7292487621307373, 6.481687068939209, -1.537420630455017, 329 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 330 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 331 -8.199960708618164, -7.786487102508545, 9.280223846435547, 332 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 333 5.549378395080566, 7.409400463104248, -2.123614549636841 334 ], 335 'descriptor': {shape: [4, 6], dataType: 'float32'} 336 } 337 } 338 } 339 }, 340 { 341 'name': 'clamp float32 3D tensor default options', 342 'graph': { 343 'inputs': { 344 'clampInput': { 345 'data': [ 346 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 347 -6.575078010559082, -7.755683898925781, 9.524681091308594, 348 3.7292487621307373, 6.481687068939209, -1.537420630455017, 349 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 350 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 351 -8.199960708618164, -7.786487102508545, 9.280223846435547, 352 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 353 5.549378395080566, 7.409400463104248, -2.123614549636841 354 ], 355 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 356 } 357 }, 358 'operators': [{ 359 'name': 'clamp', 360 'arguments': [{'input': 'clampInput'}], 361 'outputs': 'clampOutput' 362 }], 363 'expectedOutputs': { 364 'clampOutput': { 365 'data': [ 366 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 367 -6.575078010559082, -7.755683898925781, 9.524681091308594, 368 3.7292487621307373, 6.481687068939209, -1.537420630455017, 369 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 370 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 371 -8.199960708618164, -7.786487102508545, 9.280223846435547, 372 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 373 5.549378395080566, 7.409400463104248, -2.123614549636841 374 ], 375 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 376 } 377 } 378 } 379 }, 380 { 381 'name': 'clamp float32 4D tensor default options', 382 'graph': { 383 'inputs': { 384 'clampInput': { 385 'data': [ 386 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 387 -6.575078010559082, -7.755683898925781, 9.524681091308594, 388 3.7292487621307373, 6.481687068939209, -1.537420630455017, 389 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 390 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 391 -8.199960708618164, -7.786487102508545, 9.280223846435547, 392 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 393 5.549378395080566, 7.409400463104248, -2.123614549636841 394 ], 395 'descriptor': {shape: [3, 2, 2, 2], dataType: 'float32'} 396 } 397 }, 398 'operators': [{ 399 'name': 'clamp', 400 'arguments': [{'input': 'clampInput'}], 401 'outputs': 'clampOutput' 402 }], 403 'expectedOutputs': { 404 'clampOutput': { 405 'data': [ 406 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 407 -6.575078010559082, -7.755683898925781, 9.524681091308594, 408 3.7292487621307373, 6.481687068939209, -1.537420630455017, 409 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 410 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 411 -8.199960708618164, -7.786487102508545, 9.280223846435547, 412 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 413 5.549378395080566, 7.409400463104248, -2.123614549636841 414 ], 415 'descriptor': {shape: [3, 2, 2, 2], dataType: 'float32'} 416 } 417 } 418 } 419 }, 420 { 421 'name': 'clamp float32 5D tensor default options', 422 'graph': { 423 'inputs': { 424 'clampInput': { 425 'data': [ 426 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 427 -6.575078010559082, -7.755683898925781, 9.524681091308594, 428 3.7292487621307373, 6.481687068939209, -1.537420630455017, 429 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 430 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 431 -8.199960708618164, -7.786487102508545, 9.280223846435547, 432 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 433 5.549378395080566, 7.409400463104248, -2.123614549636841 434 ], 435 'descriptor': {shape: [4, 1, 1, 2, 3], dataType: 'float32'} 436 } 437 }, 438 'operators': [{ 439 'name': 'clamp', 440 'arguments': [{'input': 'clampInput'}], 441 'outputs': 'clampOutput' 442 }], 443 'expectedOutputs': { 444 'clampOutput': { 445 'data': [ 446 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 447 -6.575078010559082, -7.755683898925781, 9.524681091308594, 448 3.7292487621307373, 6.481687068939209, -1.537420630455017, 449 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 450 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 451 -8.199960708618164, -7.786487102508545, 9.280223846435547, 452 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 453 5.549378395080566, 7.409400463104248, -2.123614549636841 454 ], 455 'descriptor': {shape: [4, 1, 1, 2, 3], dataType: 'float32'} 456 } 457 } 458 } 459 }, 460 { 461 'name': 462 'clamp float32 4D tensor default options.maxValue and specified negative options.minValue', 463 'graph': { 464 'inputs': { 465 'clampInput': { 466 'data': [ 467 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 468 -6.575078010559082, -7.755683898925781, 9.524681091308594, 469 3.7292487621307373, 6.481687068939209, -1.537420630455017, 470 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 471 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 472 -8.199960708618164, -7.786487102508545, 9.280223846435547, 473 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 474 5.549378395080566, 7.409400463104248, -2.123614549636841 475 ], 476 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 477 } 478 }, 479 'operators': [{ 480 'name': 'clamp', 481 'arguments': [{'input': 'clampInput'}, {'options': {'minValue': -1}}], 482 'outputs': 'clampOutput' 483 }], 484 'expectedOutputs': { 485 'clampOutput': { 486 'data': [ 487 -1, 488 -1, 489 -1, 490 -1, 491 -1, 492 9.524681091308594, 493 3.7292487621307373, 494 6.481687068939209, 495 -1, 496 -1, 497 7.880751132965088, 498 -1, 499 6.3438639640808105, 500 5.525737762451172, 501 0.8433118462562561, 502 -1, 503 -1, 504 9.280223846435547, 505 -1, 506 9.549695014953613, 507 5.788925647735596, 508 5.549378395080566, 509 7.409400463104248, 510 -1 511 ], 512 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float32'} 513 } 514 } 515 } 516 }, 517 { 518 'name': 519 'clamp float32 3D tensor default options.maxValue and specified options.minValue=0.0', 520 'graph': { 521 'inputs': { 522 'clampInput': { 523 'data': [ 524 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 525 -6.575078010559082, -7.755683898925781, 9.524681091308594, 526 3.7292487621307373, 6.481687068939209, -1.537420630455017, 527 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 528 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 529 -8.199960708618164, -7.786487102508545, 9.280223846435547, 530 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 531 5.549378395080566, 7.409400463104248, -2.123614549636841 532 ], 533 'descriptor': {shape: [6, 2, 2], dataType: 'float32'} 534 } 535 }, 536 'operators': [{ 537 'name': 'clamp', 538 'arguments': [{'input': 'clampInput'}, {'options': {'minValue': 0}}], 539 'outputs': 'clampOutput' 540 }], 541 'expectedOutputs': { 542 'clampOutput': { 543 'data': [ 544 0, 545 0, 546 0, 547 0, 548 0, 549 9.524681091308594, 550 3.7292487621307373, 551 6.481687068939209, 552 0, 553 0, 554 7.880751132965088, 555 0, 556 6.3438639640808105, 557 5.525737762451172, 558 0.8433118462562561, 559 0, 560 0, 561 9.280223846435547, 562 0, 563 9.549695014953613, 564 5.788925647735596, 565 5.549378395080566, 566 7.409400463104248, 567 0 568 ], 569 'descriptor': {shape: [6, 2, 2], dataType: 'float32'} 570 } 571 } 572 } 573 }, 574 { 575 'name': 576 'clamp float32 2D tensor default options.maxValue and specified positive options.minValue', 577 'graph': { 578 'inputs': { 579 'clampInput': { 580 'data': [ 581 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 582 -6.575078010559082, -7.755683898925781, 9.524681091308594, 583 3.7292487621307373, 6.481687068939209, -1.537420630455017, 584 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 585 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 586 -8.199960708618164, -7.786487102508545, 9.280223846435547, 587 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 588 5.549378395080566, 7.409400463104248, -2.123614549636841 589 ], 590 'descriptor': {shape: [3, 8], dataType: 'float32'} 591 } 592 }, 593 'operators': [{ 594 'name': 'clamp', 595 'arguments': [{'input': 'clampInput'}, {'options': {'minValue': 1}}], 596 'outputs': 'clampOutput' 597 }], 598 'expectedOutputs': { 599 'clampOutput': { 600 'data': [ 601 1, 602 1, 603 1, 604 1, 605 1, 606 9.524681091308594, 607 3.7292487621307373, 608 6.481687068939209, 609 1, 610 1, 611 7.880751132965088, 612 1, 613 6.3438639640808105, 614 5.525737762451172, 615 1, 616 1, 617 1, 618 9.280223846435547, 619 1, 620 9.549695014953613, 621 5.788925647735596, 622 5.549378395080566, 623 7.409400463104248, 624 1 625 ], 626 'descriptor': {shape: [3, 8], dataType: 'float32'} 627 } 628 } 629 } 630 }, 631 { 632 'name': 633 'clamp float32 5D tensor default options.minValue and specified negative options.maxValue', 634 'graph': { 635 'inputs': { 636 'clampInput': { 637 'data': [ 638 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 639 -6.575078010559082, -7.755683898925781, 9.524681091308594, 640 3.7292487621307373, 6.481687068939209, -1.537420630455017, 641 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 642 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 643 -8.199960708618164, -7.786487102508545, 9.280223846435547, 644 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 645 5.549378395080566, 7.409400463104248, -2.123614549636841 646 ], 647 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float32'} 648 } 649 }, 650 'operators': [{ 651 'name': 'clamp', 652 'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': -2}}], 653 'outputs': 'clampOutput' 654 }], 655 'expectedOutputs': { 656 'clampOutput': { 657 'data': [ 658 -9.817828178405762, 659 -6.024064064025879, 660 -4.0725626945495605, 661 -6.575078010559082, 662 -7.755683898925781, 663 -2, 664 -2, 665 -2, 666 -2, 667 -7.34310245513916, 668 -2, 669 -2.0564088821411133, 670 -2, 671 -2, 672 -2, 673 -8.199960708618164, 674 -7.786487102508545, 675 -2, 676 -2.3130595684051514, 677 -2, 678 -2, 679 -2, 680 -2, 681 -2.123614549636841 682 ], 683 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float32'} 684 } 685 } 686 } 687 }, 688 { 689 'name': 690 'clamp float32 1D tensor default options.minValue and specified options.maxValue=0.0', 691 'graph': { 692 'inputs': { 693 'clampInput': { 694 'data': [ 695 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 696 -6.575078010559082, -7.755683898925781, 9.524681091308594, 697 3.7292487621307373, 6.481687068939209, -1.537420630455017, 698 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 699 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 700 -8.199960708618164, -7.786487102508545, 9.280223846435547, 701 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 702 5.549378395080566, 7.409400463104248, -2.123614549636841 703 ], 704 'descriptor': {shape: [24], dataType: 'float32'} 705 } 706 }, 707 'operators': [{ 708 'name': 'clamp', 709 'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': 0}}], 710 'outputs': 'clampOutput' 711 }], 712 'expectedOutputs': { 713 'clampOutput': { 714 'data': [ 715 -9.817828178405762, 716 -6.024064064025879, 717 -4.0725626945495605, 718 -6.575078010559082, 719 -7.755683898925781, 720 0, 721 0, 722 0, 723 -1.537420630455017, 724 -7.34310245513916, 725 0, 726 -2.0564088821411133, 727 0, 728 0, 729 0, 730 -8.199960708618164, 731 -7.786487102508545, 732 0, 733 -2.3130595684051514, 734 0, 735 0, 736 0, 737 0, 738 -2.123614549636841 739 ], 740 'descriptor': {shape: [24], dataType: 'float32'} 741 } 742 } 743 } 744 }, 745 { 746 'name': 747 'clamp float32 3D tensor default options.minValue and specified positive options.maxValue', 748 'graph': { 749 'inputs': { 750 'clampInput': { 751 'data': [ 752 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 753 -6.575078010559082, -7.755683898925781, 9.524681091308594, 754 3.7292487621307373, 6.481687068939209, -1.537420630455017, 755 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 756 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 757 -8.199960708618164, -7.786487102508545, 9.280223846435547, 758 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 759 5.549378395080566, 7.409400463104248, -2.123614549636841 760 ], 761 'descriptor': {shape: [3, 4, 2], dataType: 'float32'} 762 } 763 }, 764 'operators': [{ 765 'name': 'clamp', 766 'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': 3}}], 767 'outputs': 'clampOutput' 768 }], 769 'expectedOutputs': { 770 'clampOutput': { 771 'data': [ 772 -9.817828178405762, 773 -6.024064064025879, 774 -4.0725626945495605, 775 -6.575078010559082, 776 -7.755683898925781, 777 3, 778 3, 779 3, 780 -1.537420630455017, 781 -7.34310245513916, 782 3, 783 -2.0564088821411133, 784 3, 785 3, 786 0.8433118462562561, 787 -8.199960708618164, 788 -7.786487102508545, 789 3, 790 -2.3130595684051514, 791 3, 792 3, 793 3, 794 3, 795 -2.123614549636841 796 ], 797 'descriptor': {shape: [3, 4, 2], dataType: 'float32'} 798 } 799 } 800 } 801 }, 802 { 803 'name': 804 'clamp float32 5D tensor specified both negative options.minValue and options.maxValue', 805 'graph': { 806 'inputs': { 807 'clampInput': { 808 'data': [ 809 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 810 -6.575078010559082, -7.755683898925781, 9.524681091308594, 811 3.7292487621307373, 6.481687068939209, -1.537420630455017, 812 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 813 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 814 -8.199960708618164, -7.786487102508545, 9.280223846435547, 815 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 816 5.549378395080566, 7.409400463104248, -2.123614549636841 817 ], 818 'descriptor': {shape: [3, 2, 1, 1, 4], dataType: 'float32'} 819 } 820 }, 821 'operators': [{ 822 'name': 'clamp', 823 'arguments': [ 824 {'input': 'clampInput'}, {'options': {'minValue': -8, 'maxValue': -1}} 825 ], 826 'outputs': 'clampOutput' 827 }], 828 'expectedOutputs': { 829 'clampOutput': { 830 'data': [ 831 -8, 832 -6.024064064025879, 833 -4.0725626945495605, 834 -6.575078010559082, 835 -7.755683898925781, 836 -1, 837 -1, 838 -1, 839 -1.537420630455017, 840 -7.34310245513916, 841 -1, 842 -2.0564088821411133, 843 -1, 844 -1, 845 -1, 846 -8, 847 -7.786487102508545, 848 -1, 849 -2.3130595684051514, 850 -1, 851 -1, 852 -1, 853 -1, 854 -2.123614549636841 855 ], 856 'descriptor': {shape: [3, 2, 1, 1, 4], dataType: 'float32'} 857 } 858 } 859 } 860 }, 861 { 862 'name': 863 'clamp float32 4D tensor specified negative options.minValue and options.maxValue=0.0', 864 'graph': { 865 'inputs': { 866 'clampInput': { 867 'data': [ 868 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 869 -6.575078010559082, -7.755683898925781, 9.524681091308594, 870 3.7292487621307373, 6.481687068939209, -1.537420630455017, 871 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 872 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 873 -8.199960708618164, -7.786487102508545, 9.280223846435547, 874 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 875 5.549378395080566, 7.409400463104248, -2.123614549636841 876 ], 877 'descriptor': {shape: [1, 4, 3, 2], dataType: 'float32'} 878 } 879 }, 880 'operators': [{ 881 'name': 'clamp', 882 'arguments': [ 883 {'input': 'clampInput'}, {'options': {'minValue': -6, 'maxValue': 0}} 884 ], 885 'outputs': 'clampOutput' 886 }], 887 'expectedOutputs': { 888 'clampOutput': { 889 'data': [ 890 -6, 891 -6, 892 -4.0725626945495605, 893 -6, 894 -6, 895 0, 896 0, 897 0, 898 -1.537420630455017, 899 -6, 900 0, 901 -2.0564088821411133, 902 0, 903 0, 904 0, 905 -6, 906 -6, 907 0, 908 -2.3130595684051514, 909 0, 910 0, 911 0, 912 0, 913 -2.123614549636841 914 ], 915 'descriptor': {shape: [1, 4, 3, 2], dataType: 'float32'} 916 } 917 } 918 } 919 }, 920 { 921 'name': 922 'clamp float32 3D tensor specified negative options.minValue and positive options.maxValue', 923 'graph': { 924 'inputs': { 925 'clampInput': { 926 'data': [ 927 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 928 -6.575078010559082, -7.755683898925781, 9.524681091308594, 929 3.7292487621307373, 6.481687068939209, -1.537420630455017, 930 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 931 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 932 -8.199960708618164, -7.786487102508545, 9.280223846435547, 933 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 934 5.549378395080566, 7.409400463104248, -2.123614549636841 935 ], 936 'descriptor': {shape: [2, 6, 2], dataType: 'float32'} 937 } 938 }, 939 'operators': [{ 940 'name': 'clamp', 941 'arguments': [ 942 {'input': 'clampInput'}, {'options': {'minValue': -3, 'maxValue': 4}} 943 ], 944 'outputs': 'clampOutput' 945 }], 946 'expectedOutputs': { 947 'clampOutput': { 948 'data': [ 949 -3, 950 -3, 951 -3, 952 -3, 953 -3, 954 4, 955 3.7292487621307373, 956 4, 957 -1.537420630455017, 958 -3, 959 4, 960 -2.0564088821411133, 961 4, 962 4, 963 0.8433118462562561, 964 -3, 965 -3, 966 4, 967 -2.3130595684051514, 968 4, 969 4, 970 4, 971 4, 972 -2.123614549636841 973 ], 974 'descriptor': {shape: [2, 6, 2], dataType: 'float32'} 975 } 976 } 977 } 978 }, 979 { 980 'name': 981 'clamp float32 2D tensor specified options.minValue=0.0 and positive options.maxValue', 982 'graph': { 983 'inputs': { 984 'clampInput': { 985 'data': [ 986 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 987 -6.575078010559082, -7.755683898925781, 9.524681091308594, 988 3.7292487621307373, 6.481687068939209, -1.537420630455017, 989 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 990 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 991 -8.199960708618164, -7.786487102508545, 9.280223846435547, 992 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 993 5.549378395080566, 7.409400463104248, -2.123614549636841 994 ], 995 'descriptor': {shape: [6, 4], dataType: 'float32'} 996 } 997 }, 998 'operators': [{ 999 'name': 'clamp', 1000 'arguments': [ 1001 {'input': 'clampInput'}, {'options': {'minValue': 0, 'maxValue': 6}} 1002 ], 1003 'outputs': 'clampOutput' 1004 }], 1005 'expectedOutputs': { 1006 'clampOutput': { 1007 'data': [ 1008 0, 1009 0, 1010 0, 1011 0, 1012 0, 1013 6, 1014 3.7292487621307373, 1015 6, 1016 0, 1017 0, 1018 6, 1019 0, 1020 6, 1021 5.525737762451172, 1022 0.8433118462562561, 1023 0, 1024 0, 1025 6, 1026 0, 1027 6, 1028 5.788925647735596, 1029 5.549378395080566, 1030 6, 1031 0 1032 ], 1033 'descriptor': {shape: [6, 4], dataType: 'float32'} 1034 } 1035 } 1036 } 1037 }, 1038 { 1039 'name': 1040 'clamp float32 1D tensor specified both positive options.minValue and options.maxValue', 1041 'graph': { 1042 'inputs': { 1043 'clampInput': { 1044 'data': [ 1045 -9.817828178405762, -6.024064064025879, -4.0725626945495605, 1046 -6.575078010559082, -7.755683898925781, 9.524681091308594, 1047 3.7292487621307373, 6.481687068939209, -1.537420630455017, 1048 -7.34310245513916, 7.880751132965088, -2.0564088821411133, 1049 6.3438639640808105, 5.525737762451172, 0.8433118462562561, 1050 -8.199960708618164, -7.786487102508545, 9.280223846435547, 1051 -2.3130595684051514, 9.549695014953613, 5.788925647735596, 1052 5.549378395080566, 7.409400463104248, -2.123614549636841 1053 ], 1054 'descriptor': {shape: [24], dataType: 'float32'} 1055 } 1056 }, 1057 'operators': [{ 1058 'name': 'clamp', 1059 'arguments': [ 1060 {'input': 'clampInput'}, {'options': {'minValue': 2, 'maxValue': 7}} 1061 ], 1062 'outputs': 'clampOutput' 1063 }], 1064 'expectedOutputs': { 1065 'clampOutput': { 1066 'data': [ 1067 2, 1068 2, 1069 2, 1070 2, 1071 2, 1072 7, 1073 3.7292487621307373, 1074 6.481687068939209, 1075 2, 1076 2, 1077 7, 1078 2, 1079 6.3438639640808105, 1080 5.525737762451172, 1081 2, 1082 2, 1083 2, 1084 7, 1085 2, 1086 7, 1087 5.788925647735596, 1088 5.549378395080566, 1089 7, 1090 2 1091 ], 1092 'descriptor': {shape: [24], dataType: 'float32'} 1093 } 1094 } 1095 } 1096 }, 1097 1098 // float16 tests 1099 { 1100 'name': 'clamp float16 0D tensor default options', 1101 'graph': { 1102 'inputs': { 1103 'clampInput': { 1104 'data': [-9.8203125], 1105 'descriptor': {shape: [], dataType: 'float16'} 1106 } 1107 }, 1108 'operators': [{ 1109 'name': 'clamp', 1110 'arguments': [{'input': 'clampInput'}], 1111 'outputs': 'clampOutput' 1112 }], 1113 'expectedOutputs': { 1114 'clampOutput': { 1115 'data': [-9.8203125], 1116 'descriptor': {shape: [], dataType: 'float16'} 1117 } 1118 } 1119 } 1120 }, 1121 { 1122 'name': 'clamp float16 1D tensor', 1123 'graph': { 1124 'inputs': { 1125 'clampInput': { 1126 'data': [-64000, 64000, -2, 1, 0], 1127 'descriptor': {shape: [5], dataType: 'float16'} 1128 } 1129 }, 1130 'operators': [{ 1131 'name': 'clamp', 1132 'arguments': [{'input': 'clampInput'}, {'options': {'minValue': -2}}], 1133 'outputs': 'clampOutput' 1134 }], 1135 'expectedOutputs': { 1136 'clampOutput': { 1137 'data': [-2, 64000, -2, 1, 0], 1138 'descriptor': {shape: [5], dataType: 'float16'} 1139 } 1140 } 1141 } 1142 }, 1143 { 1144 'name': 'clamp float16 1D constant tensor default options', 1145 'graph': { 1146 'inputs': { 1147 'clampInput': { 1148 'data': [ 1149 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1150 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1151 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1152 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1153 5.7890625, 5.55078125, 7.41015625, -2.123046875 1154 ], 1155 'descriptor': {shape: [24], dataType: 'float16'}, 1156 'constant': true 1157 } 1158 }, 1159 'operators': [{ 1160 'name': 'clamp', 1161 'arguments': [{'input': 'clampInput'}], 1162 'outputs': 'clampOutput' 1163 }], 1164 'expectedOutputs': { 1165 'clampOutput': { 1166 'data': [ 1167 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1168 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1169 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1170 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1171 5.7890625, 5.55078125, 7.41015625, -2.123046875 1172 ], 1173 'descriptor': {shape: [24], dataType: 'float16'} 1174 } 1175 } 1176 } 1177 }, 1178 { 1179 'name': 'clamp float16 1D tensor default options', 1180 'graph': { 1181 'inputs': { 1182 'clampInput': { 1183 'data': [ 1184 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1185 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1186 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1187 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1188 5.7890625, 5.55078125, 7.41015625, -2.123046875 1189 ], 1190 'descriptor': {shape: [24], dataType: 'float16'} 1191 } 1192 }, 1193 'operators': [{ 1194 'name': 'clamp', 1195 'arguments': [{'input': 'clampInput'}], 1196 'outputs': 'clampOutput' 1197 }], 1198 'expectedOutputs': { 1199 'clampOutput': { 1200 'data': [ 1201 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1202 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1203 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1204 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1205 5.7890625, 5.55078125, 7.41015625, -2.123046875 1206 ], 1207 'descriptor': {shape: [24], dataType: 'float16'} 1208 } 1209 } 1210 } 1211 }, 1212 { 1213 'name': 'clamp float16 2D tensor default options', 1214 'graph': { 1215 'inputs': { 1216 'clampInput': { 1217 'data': [ 1218 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1219 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1220 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1221 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1222 5.7890625, 5.55078125, 7.41015625, -2.123046875 1223 ], 1224 'descriptor': {shape: [4, 6], dataType: 'float16'} 1225 } 1226 }, 1227 'operators': [{ 1228 'name': 'clamp', 1229 'arguments': [{'input': 'clampInput'}], 1230 'outputs': 'clampOutput' 1231 }], 1232 'expectedOutputs': { 1233 'clampOutput': { 1234 'data': [ 1235 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1236 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1237 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1238 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1239 5.7890625, 5.55078125, 7.41015625, -2.123046875 1240 ], 1241 'descriptor': {shape: [4, 6], dataType: 'float16'} 1242 } 1243 } 1244 } 1245 }, 1246 { 1247 'name': 'clamp float16 3D tensor default options', 1248 'graph': { 1249 'inputs': { 1250 'clampInput': { 1251 'data': [ 1252 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1253 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1254 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1255 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1256 5.7890625, 5.55078125, 7.41015625, -2.123046875 1257 ], 1258 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 1259 } 1260 }, 1261 'operators': [{ 1262 'name': 'clamp', 1263 'arguments': [{'input': 'clampInput'}], 1264 'outputs': 'clampOutput' 1265 }], 1266 'expectedOutputs': { 1267 'clampOutput': { 1268 'data': [ 1269 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1270 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1271 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1272 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1273 5.7890625, 5.55078125, 7.41015625, -2.123046875 1274 ], 1275 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 1276 } 1277 } 1278 } 1279 }, 1280 { 1281 'name': 'clamp float16 4D tensor default options', 1282 'graph': { 1283 'inputs': { 1284 'clampInput': { 1285 'data': [ 1286 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1287 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1288 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1289 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1290 5.7890625, 5.55078125, 7.41015625, -2.123046875 1291 ], 1292 'descriptor': {shape: [3, 2, 2, 2], dataType: 'float16'} 1293 } 1294 }, 1295 'operators': [{ 1296 'name': 'clamp', 1297 'arguments': [{'input': 'clampInput'}], 1298 'outputs': 'clampOutput' 1299 }], 1300 'expectedOutputs': { 1301 'clampOutput': { 1302 'data': [ 1303 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1304 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1305 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1306 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1307 5.7890625, 5.55078125, 7.41015625, -2.123046875 1308 ], 1309 'descriptor': {shape: [3, 2, 2, 2], dataType: 'float16'} 1310 } 1311 } 1312 } 1313 }, 1314 { 1315 'name': 'clamp float16 5D tensor default options', 1316 'graph': { 1317 'inputs': { 1318 'clampInput': { 1319 'data': [ 1320 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1321 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1322 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1323 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1324 5.7890625, 5.55078125, 7.41015625, -2.123046875 1325 ], 1326 'descriptor': {shape: [4, 1, 1, 2, 3], dataType: 'float16'} 1327 } 1328 }, 1329 'operators': [{ 1330 'name': 'clamp', 1331 'arguments': [{'input': 'clampInput'}], 1332 'outputs': 'clampOutput' 1333 }], 1334 'expectedOutputs': { 1335 'clampOutput': { 1336 'data': [ 1337 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1338 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1339 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1340 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1341 5.7890625, 5.55078125, 7.41015625, -2.123046875 1342 ], 1343 'descriptor': {shape: [4, 1, 1, 2, 3], dataType: 'float16'} 1344 } 1345 } 1346 } 1347 }, 1348 { 1349 'name': 1350 'clamp float16 4D tensor default options.maxValue and specified negative options.minValue', 1351 'graph': { 1352 'inputs': { 1353 'clampInput': { 1354 'data': [ 1355 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1356 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1357 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1358 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1359 5.7890625, 5.55078125, 7.41015625, -2.123046875 1360 ], 1361 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 1362 } 1363 }, 1364 'operators': [{ 1365 'name': 'clamp', 1366 'arguments': [{'input': 'clampInput'}, {'options': {'minValue': -1}}], 1367 'outputs': 'clampOutput' 1368 }], 1369 'expectedOutputs': { 1370 'clampOutput': { 1371 'data': [ 1372 -1, -1, -1, -1, -1, 1373 9.5234375, 3.728515625, 6.48046875, -1, -1, 1374 7.87890625, -1, 6.34375, 5.52734375, 0.84326171875, 1375 -1, -1, 9.28125, -1, 9.546875, 1376 5.7890625, 5.55078125, 7.41015625, -1 1377 ], 1378 'descriptor': {shape: [2, 1, 4, 3], dataType: 'float16'} 1379 } 1380 } 1381 } 1382 }, 1383 { 1384 'name': 1385 'clamp float16 3D tensor default options.maxValue and specified options.minValue=0.0', 1386 'graph': { 1387 'inputs': { 1388 'clampInput': { 1389 'data': [ 1390 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1391 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1392 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1393 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1394 5.7890625, 5.55078125, 7.41015625, -2.123046875 1395 ], 1396 'descriptor': {shape: [6, 2, 2], dataType: 'float16'} 1397 } 1398 }, 1399 'operators': [{ 1400 'name': 'clamp', 1401 'arguments': [{'input': 'clampInput'}, {'options': {'minValue': 0}}], 1402 'outputs': 'clampOutput' 1403 }], 1404 'expectedOutputs': { 1405 'clampOutput': { 1406 'data': [ 1407 0, 0, 0, 0, 0, 1408 9.5234375, 3.728515625, 6.48046875, 0, 0, 1409 7.87890625, 0, 6.34375, 5.52734375, 0.84326171875, 1410 0, 0, 9.28125, 0, 9.546875, 1411 5.7890625, 5.55078125, 7.41015625, 0 1412 ], 1413 'descriptor': {shape: [6, 2, 2], dataType: 'float16'} 1414 } 1415 } 1416 } 1417 }, 1418 { 1419 'name': 1420 'clamp float16 2D tensor default options.maxValue and specified positive options.minValue', 1421 'graph': { 1422 'inputs': { 1423 'clampInput': { 1424 'data': [ 1425 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1426 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1427 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1428 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1429 5.7890625, 5.55078125, 7.41015625, -2.123046875 1430 ], 1431 'descriptor': {shape: [3, 8], dataType: 'float16'} 1432 } 1433 }, 1434 'operators': [{ 1435 'name': 'clamp', 1436 'arguments': [{'input': 'clampInput'}, {'options': {'minValue': 1}}], 1437 'outputs': 'clampOutput' 1438 }], 1439 'expectedOutputs': { 1440 'clampOutput': { 1441 'data': [ 1442 1, 1, 1, 1, 1, 9.5234375, 3.728515625, 1443 6.48046875, 1, 1, 7.87890625, 1, 6.34375, 5.52734375, 1444 1, 1, 1, 9.28125, 1, 9.546875, 5.7890625, 1445 5.55078125, 7.41015625, 1 1446 ], 1447 'descriptor': {shape: [3, 8], dataType: 'float16'} 1448 } 1449 } 1450 } 1451 }, 1452 { 1453 'name': 1454 'clamp float16 5D tensor default options.minValue and specified negative options.maxValue', 1455 'graph': { 1456 'inputs': { 1457 'clampInput': { 1458 'data': [ 1459 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1460 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1461 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1462 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1463 5.7890625, 5.55078125, 7.41015625, -2.123046875 1464 ], 1465 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float16'} 1466 } 1467 }, 1468 'operators': [{ 1469 'name': 'clamp', 1470 'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': -2}}], 1471 'outputs': 'clampOutput' 1472 }], 1473 'expectedOutputs': { 1474 'clampOutput': { 1475 'data': [ 1476 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1477 -2, -2, -2, -2, -7.34375, 1478 -2, -2.056640625, -2, -2, -2, 1479 -8.203125, -7.78515625, -2, -2.3125, -2, 1480 -2, -2, -2, -2.123046875 1481 ], 1482 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float16'} 1483 } 1484 } 1485 } 1486 }, 1487 { 1488 'name': 1489 'clamp float16 1D tensor default options.minValue and specified options.maxValue=0.0', 1490 'graph': { 1491 'inputs': { 1492 'clampInput': { 1493 'data': [ 1494 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1495 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1496 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1497 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1498 5.7890625, 5.55078125, 7.41015625, -2.123046875 1499 ], 1500 'descriptor': {shape: [24], dataType: 'float16'} 1501 } 1502 }, 1503 'operators': [{ 1504 'name': 'clamp', 1505 'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': 0}}], 1506 'outputs': 'clampOutput' 1507 }], 1508 'expectedOutputs': { 1509 'clampOutput': { 1510 'data': [ 1511 -9.8203125, -6.0234375, -4.07421875, 1512 -6.57421875, -7.75390625, 0, 1513 0, 0, -1.537109375, 1514 -7.34375, 0, -2.056640625, 1515 0, 0, 0, 1516 -8.203125, -7.78515625, 0, 1517 -2.3125, 0, 0, 1518 0, 0, -2.123046875 1519 ], 1520 'descriptor': {shape: [24], dataType: 'float16'} 1521 } 1522 } 1523 } 1524 }, 1525 { 1526 'name': 1527 'clamp float16 3D tensor default options.minValue and specified positive options.maxValue', 1528 'graph': { 1529 'inputs': { 1530 'clampInput': { 1531 'data': [ 1532 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1533 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1534 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1535 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1536 5.7890625, 5.55078125, 7.41015625, -2.123046875 1537 ], 1538 'descriptor': {shape: [3, 4, 2], dataType: 'float16'} 1539 } 1540 }, 1541 'operators': [{ 1542 'name': 'clamp', 1543 'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': 3}}], 1544 'outputs': 'clampOutput' 1545 }], 1546 'expectedOutputs': { 1547 'clampOutput': { 1548 'data': [ 1549 -9.8203125, -6.0234375, -4.07421875, 1550 -6.57421875, -7.75390625, 3, 1551 3, 3, -1.537109375, 1552 -7.34375, 3, -2.056640625, 1553 3, 3, 0.84326171875, 1554 -8.203125, -7.78515625, 3, 1555 -2.3125, 3, 3, 1556 3, 3, -2.123046875 1557 ], 1558 'descriptor': {shape: [3, 4, 2], dataType: 'float16'} 1559 } 1560 } 1561 } 1562 }, 1563 { 1564 'name': 1565 'clamp float16 5D tensor specified both negative options.minValue and options.maxValue', 1566 'graph': { 1567 'inputs': { 1568 'clampInput': { 1569 'data': [ 1570 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1571 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1572 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1573 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1574 5.7890625, 5.55078125, 7.41015625, -2.123046875 1575 ], 1576 'descriptor': {shape: [3, 2, 1, 1, 4], dataType: 'float16'} 1577 } 1578 }, 1579 'operators': [{ 1580 'name': 'clamp', 1581 'arguments': [ 1582 {'input': 'clampInput'}, {'options': {'minValue': -8, 'maxValue': -1}} 1583 ], 1584 'outputs': 'clampOutput' 1585 }], 1586 'expectedOutputs': { 1587 'clampOutput': { 1588 'data': [ 1589 -8, -6.0234375, -4.07421875, -6.57421875, -7.75390625, -1, -1, 1590 -1, -1.537109375, -7.34375, -1, -2.056640625, -1, -1, 1591 -1, -8, -7.78515625, -1, -2.3125, -1, -1, 1592 -1, -1, -2.123046875 1593 ], 1594 'descriptor': {shape: [3, 2, 1, 1, 4], dataType: 'float16'} 1595 } 1596 } 1597 } 1598 }, 1599 { 1600 'name': 1601 'clamp float16 4D tensor specified negative options.minValue and options.maxValue=0.0', 1602 'graph': { 1603 'inputs': { 1604 'clampInput': { 1605 'data': [ 1606 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1607 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1608 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1609 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1610 5.7890625, 5.55078125, 7.41015625, -2.123046875 1611 ], 1612 'descriptor': {shape: [1, 4, 3, 2], dataType: 'float16'} 1613 } 1614 }, 1615 'operators': [{ 1616 'name': 'clamp', 1617 'arguments': [ 1618 {'input': 'clampInput'}, {'options': {'minValue': -6, 'maxValue': 0}} 1619 ], 1620 'outputs': 'clampOutput' 1621 }], 1622 'expectedOutputs': { 1623 'clampOutput': { 1624 'data': [ 1625 -6, -6, -4.07421875, 1626 -6, -6, 0, 1627 0, 0, -1.537109375, 1628 -6, 0, -2.056640625, 1629 0, 0, 0, 1630 -6, -6, 0, 1631 -2.3125, 0, 0, 1632 0, 0, -2.123046875 1633 ], 1634 'descriptor': {shape: [1, 4, 3, 2], dataType: 'float16'} 1635 } 1636 } 1637 } 1638 }, 1639 { 1640 'name': 1641 'clamp float16 3D tensor specified negative options.minValue and positive options.maxValue', 1642 'graph': { 1643 'inputs': { 1644 'clampInput': { 1645 'data': [ 1646 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1647 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1648 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1649 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1650 5.7890625, 5.55078125, 7.41015625, -2.123046875 1651 ], 1652 'descriptor': {shape: [2, 6, 2], dataType: 'float16'} 1653 } 1654 }, 1655 'operators': [{ 1656 'name': 'clamp', 1657 'arguments': [ 1658 {'input': 'clampInput'}, {'options': {'minValue': -3, 'maxValue': 4}} 1659 ], 1660 'outputs': 'clampOutput' 1661 }], 1662 'expectedOutputs': { 1663 'clampOutput': { 1664 'data': [ 1665 -3, -3, -3, 1666 -3, -3, 4, 1667 3.728515625, 4, -1.537109375, 1668 -3, 4, -2.056640625, 1669 4, 4, 0.84326171875, 1670 -3, -3, 4, 1671 -2.3125, 4, 4, 1672 4, 4, -2.123046875 1673 ], 1674 'descriptor': {shape: [2, 6, 2], dataType: 'float16'} 1675 } 1676 } 1677 } 1678 }, 1679 { 1680 'name': 1681 'clamp float16 2D tensor specified options.minValue=0.0 and positive options.maxValue', 1682 'graph': { 1683 'inputs': { 1684 'clampInput': { 1685 'data': [ 1686 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1687 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1688 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1689 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1690 5.7890625, 5.55078125, 7.41015625, -2.123046875 1691 ], 1692 'descriptor': {shape: [6, 4], dataType: 'float16'} 1693 } 1694 }, 1695 'operators': [{ 1696 'name': 'clamp', 1697 'arguments': [ 1698 {'input': 'clampInput'}, {'options': {'minValue': 0, 'maxValue': 6}} 1699 ], 1700 'outputs': 'clampOutput' 1701 }], 1702 'expectedOutputs': { 1703 'clampOutput': { 1704 'data': [ 1705 0, 0, 0, 0, 0, 1706 6, 3.728515625, 6, 0, 0, 1707 6, 0, 6, 5.52734375, 0.84326171875, 1708 0, 0, 6, 0, 6, 1709 5.7890625, 5.55078125, 6, 0 1710 ], 1711 'descriptor': {shape: [6, 4], dataType: 'float16'} 1712 } 1713 } 1714 } 1715 }, 1716 { 1717 'name': 1718 'clamp float16 1D tensor specified both positive options.minValue and options.maxValue', 1719 'graph': { 1720 'inputs': { 1721 'clampInput': { 1722 'data': [ 1723 -9.8203125, -6.0234375, -4.07421875, -6.57421875, -7.75390625, 1724 9.5234375, 3.728515625, 6.48046875, -1.537109375, -7.34375, 1725 7.87890625, -2.056640625, 6.34375, 5.52734375, 0.84326171875, 1726 -8.203125, -7.78515625, 9.28125, -2.3125, 9.546875, 1727 5.7890625, 5.55078125, 7.41015625, -2.123046875 1728 ], 1729 'descriptor': {shape: [24], dataType: 'float16'} 1730 } 1731 }, 1732 'operators': [{ 1733 'name': 'clamp', 1734 'arguments': [ 1735 {'input': 'clampInput'}, {'options': {'minValue': 2, 'maxValue': 7}} 1736 ], 1737 'outputs': 'clampOutput' 1738 }], 1739 'expectedOutputs': { 1740 'clampOutput': { 1741 'data': [ 1742 2, 2, 2, 2, 2, 7, 3.728515625, 6.48046875, 1743 2, 2, 7, 2, 6.34375, 5.52734375, 2, 2, 1744 2, 7, 2, 7, 5.7890625, 5.55078125, 7, 2 1745 ], 1746 'descriptor': {shape: [24], dataType: 'float16'} 1747 } 1748 } 1749 } 1750 }, 1751 { 1752 'name': 'minValue as -Infinity', 1753 'graph': { 1754 'inputs': { 1755 'clampInput': { 1756 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1757 'descriptor': {shape: [7], dataType: 'float32'}, 1758 'constant': true 1759 } 1760 }, 1761 'operators': [{ 1762 'name': 'clamp', 1763 'arguments': 1764 [{'input': 'clampInput'}, {'options': {'minValue': -Infinity}}], 1765 'outputs': 'clampOutput' 1766 }], 1767 'expectedOutputs': { 1768 'clampOutput': { 1769 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1770 'descriptor': {shape: [7], dataType: 'float32'} 1771 } 1772 } 1773 } 1774 }, 1775 { 1776 'name': 'minValue as Infinity', 1777 'graph': { 1778 'inputs': { 1779 'clampInput': { 1780 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1781 'descriptor': {shape: [7], dataType: 'float32'}, 1782 'constant': true 1783 } 1784 }, 1785 'operators': [{ 1786 'name': 'clamp', 1787 'arguments': 1788 [{'input': 'clampInput'}, {'options': {'minValue': Infinity}}], 1789 'outputs': 'clampOutput' 1790 }], 1791 'expectedOutputs': { 1792 'clampOutput': { 1793 'data': [ 1794 Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity 1795 ], 1796 'descriptor': {shape: [7], dataType: 'float32'} 1797 } 1798 } 1799 } 1800 }, 1801 { 1802 'name': 'maxValue as -Infinity', 1803 'graph': { 1804 'inputs': { 1805 'clampInput': { 1806 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1807 'descriptor': {shape: [7], dataType: 'float32'}, 1808 'constant': true 1809 } 1810 }, 1811 'operators': [{ 1812 'name': 'clamp', 1813 'arguments': 1814 [{'input': 'clampInput'}, {'options': {'maxValue': -Infinity}}], 1815 'outputs': 'clampOutput' 1816 }], 1817 'expectedOutputs': { 1818 'clampOutput': { 1819 'data': [ 1820 -Infinity, -Infinity, -Infinity, -Infinity, -Infinity, -Infinity, 1821 -Infinity 1822 ], 1823 'descriptor': {shape: [7], dataType: 'float32'} 1824 } 1825 } 1826 } 1827 }, 1828 { 1829 'name': 'maxValue as Infinity', 1830 'graph': { 1831 'inputs': { 1832 'clampInput': { 1833 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1834 'descriptor': {shape: [7], dataType: 'float32'}, 1835 'constant': true 1836 } 1837 }, 1838 'operators': [{ 1839 'name': 'clamp', 1840 'arguments': 1841 [{'input': 'clampInput'}, {'options': {'maxValue': Infinity}}], 1842 'outputs': 'clampOutput' 1843 }], 1844 'expectedOutputs': { 1845 'clampOutput': { 1846 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1847 'descriptor': {shape: [7], dataType: 'float32'} 1848 } 1849 } 1850 } 1851 }, 1852 { 1853 'name': 'minValue == maxValue', 1854 'graph': { 1855 'inputs': { 1856 'clampInput': { 1857 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1858 'descriptor': {shape: [7], dataType: 'float32'}, 1859 'constant': true 1860 } 1861 }, 1862 'operators': [{ 1863 'name': 'clamp', 1864 'arguments': [ 1865 {'input': 'clampInput'}, 1866 {'options': {'minValue': 0.5, 'maxValue': 0.5}} 1867 ], 1868 'outputs': 'clampOutput' 1869 }], 1870 'expectedOutputs': { 1871 'clampOutput': { 1872 'data': [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5], 1873 'descriptor': {shape: [7], dataType: 'float32'} 1874 } 1875 } 1876 } 1877 }, 1878 { 1879 'name': 'minValue as NaN', 1880 'graph': { 1881 'inputs': { 1882 'clampInput': { 1883 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1884 'descriptor': {shape: [7], dataType: 'float32'}, 1885 'constant': true 1886 } 1887 }, 1888 'operators': [{ 1889 'name': 'clamp', 1890 'arguments': 1891 [{'input': 'clampInput'}, {'options': {'minValue': NaN}}], 1892 'outputs': 'clampOutput' 1893 }], 1894 'expectedOutputs': { 1895 'clampOutput': { 1896 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1897 'descriptor': {shape: [7], dataType: 'float32'} 1898 } 1899 } 1900 } 1901 }, 1902 { 1903 'name': 'maxValue as NaN', 1904 'graph': { 1905 'inputs': { 1906 'clampInput': { 1907 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1908 'descriptor': {shape: [7], dataType: 'float32'}, 1909 'constant': true 1910 } 1911 }, 1912 'operators': [{ 1913 'name': 'clamp', 1914 'arguments': 1915 [{'input': 'clampInput'}, {'options': {'maxValue': NaN}}], 1916 'outputs': 'clampOutput' 1917 }], 1918 'expectedOutputs': { 1919 'clampOutput': { 1920 'data': [-Infinity, Infinity, -3e35, 2147483647, -2, 1, 0], 1921 'descriptor': {shape: [7], dataType: 'float32'} 1922 } 1923 } 1924 } 1925 }, 1926 ]; 1927 1928 webnn_conformance_test(clampTests, buildAndExecuteGraph, getPrecisionTolerance);