tan.https.any.js (20684B)
1 // META: title=test WebNN API element-wise tan 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-unary 12 // Compute the tangent of the input tensor, element-wise. 13 // 14 // MLOperand tan(MLOperand input); 15 16 17 const getTanPrecisionTolerance = (graphResources) => { 18 const toleranceValueDict = {float32: 1 / 1024, float16: 1 / 512}; 19 const expectedDataType = 20 getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs); 21 return {metricType: 'ATOL', value: toleranceValueDict[expectedDataType]}; 22 }; 23 24 const tanTests = [ 25 { 26 'name': 'tan float32 0D scalar', 27 'graph': { 28 'inputs': { 29 'tanInput': { 30 'data': [52.69781494140625], 31 'descriptor': {shape: [], dataType: 'float32'} 32 } 33 }, 34 'operators': [{ 35 'name': 'tan', 36 'arguments': [{'input': 'tanInput'}], 37 'outputs': 'tanOutput' 38 }], 39 'expectedOutputs': { 40 'tanOutput': { 41 'data': [-0.8582430481910706], 42 'descriptor': {shape: [], dataType: 'float32'} 43 } 44 } 45 } 46 }, 47 { 48 'name': 'tan float32 1D constant tensor', 49 'graph': { 50 'inputs': { 51 'tanInput': { 52 'data': [ 53 52.69781494140625, 70.06912994384766, 90.49689483642578, 54 24.65666961669922, 11.66512680053711, -50.95264434814453, 55 40.320064544677734, -9.641122817993164, -31.567750930786133, 56 45.59520721435547, -55.93085861206055, -44.602970123291016, 57 80.4539794921875, -2.314880847930908, -25.474767684936523, 58 62.589454650878906, -70.94403076171875, 62.84861755371094, 59 84.79766845703125, -95.58502960205078, 15.552484512329102, 60 -55.25654220581055, -26.884889602661133, 0.159261092543602 61 ], 62 'descriptor': {shape: [24], dataType: 'float32'}, 63 'constant': true 64 } 65 }, 66 'operators': [{ 67 'name': 'tan', 68 'arguments': [{'input': 'tanInput'}], 69 'outputs': 'tanOutput' 70 }], 71 'expectedOutputs': { 72 'tanOutput': { 73 'data': [ 74 -0.8582430481910706, 1.410544753074646, -0.6978657245635986, 75 -0.5156278610229492, -1.2633823156356812, -0.8205758929252625, 76 -0.5734118819236755, -0.21978461742401123, -0.1530018001794815, 77 -23.731182098388672, 0.7106066942214966, -0.7149254679679871, 78 -2.7969717979431152, 1.086239218711853, -0.3560185432434082, 79 -0.24726025760173798, 3.7865755558013916, 0.016766052693128586, 80 -0.025338610634207726, -4.203672409057617, -0.1567438244819641, 81 3.495089292526245, 5.453553199768066, 0.16062140464782715 82 ], 83 'descriptor': {shape: [24], dataType: 'float32'} 84 } 85 } 86 } 87 }, 88 { 89 'name': 'tan float32 1D tensor', 90 'graph': { 91 'inputs': { 92 'tanInput': { 93 'data': [ 94 52.69781494140625, 70.06912994384766, 90.49689483642578, 95 24.65666961669922, 11.66512680053711, -50.95264434814453, 96 40.320064544677734, -9.641122817993164, -31.567750930786133, 97 45.59520721435547, -55.93085861206055, -44.602970123291016, 98 80.4539794921875, -2.314880847930908, -25.474767684936523, 99 62.589454650878906, -70.94403076171875, 62.84861755371094, 100 84.79766845703125, -95.58502960205078, 15.552484512329102, 101 -55.25654220581055, -26.884889602661133, 0.159261092543602 102 ], 103 'descriptor': {shape: [24], dataType: 'float32'} 104 } 105 }, 106 'operators': [{ 107 'name': 'tan', 108 'arguments': [{'input': 'tanInput'}], 109 'outputs': 'tanOutput' 110 }], 111 'expectedOutputs': { 112 'tanOutput': { 113 'data': [ 114 -0.8582430481910706, 1.410544753074646, -0.6978657245635986, 115 -0.5156278610229492, -1.2633823156356812, -0.8205758929252625, 116 -0.5734118819236755, -0.21978461742401123, -0.1530018001794815, 117 -23.731182098388672, 0.7106066942214966, -0.7149254679679871, 118 -2.7969717979431152, 1.086239218711853, -0.3560185432434082, 119 -0.24726025760173798, 3.7865755558013916, 0.016766052693128586, 120 -0.025338610634207726, -4.203672409057617, -0.1567438244819641, 121 3.495089292526245, 5.453553199768066, 0.16062140464782715 122 ], 123 'descriptor': {shape: [24], dataType: 'float32'} 124 } 125 } 126 } 127 }, 128 { 129 'name': 'tan float32 2D tensor', 130 'graph': { 131 'inputs': { 132 'tanInput': { 133 'data': [ 134 52.69781494140625, 70.06912994384766, 90.49689483642578, 135 24.65666961669922, 11.66512680053711, -50.95264434814453, 136 40.320064544677734, -9.641122817993164, -31.567750930786133, 137 45.59520721435547, -55.93085861206055, -44.602970123291016, 138 80.4539794921875, -2.314880847930908, -25.474767684936523, 139 62.589454650878906, -70.94403076171875, 62.84861755371094, 140 84.79766845703125, -95.58502960205078, 15.552484512329102, 141 -55.25654220581055, -26.884889602661133, 0.159261092543602 142 ], 143 'descriptor': {shape: [4, 6], dataType: 'float32'} 144 } 145 }, 146 'operators': [{ 147 'name': 'tan', 148 'arguments': [{'input': 'tanInput'}], 149 'outputs': 'tanOutput' 150 }], 151 'expectedOutputs': { 152 'tanOutput': { 153 'data': [ 154 -0.8582430481910706, 1.410544753074646, -0.6978657245635986, 155 -0.5156278610229492, -1.2633823156356812, -0.8205758929252625, 156 -0.5734118819236755, -0.21978461742401123, -0.1530018001794815, 157 -23.731182098388672, 0.7106066942214966, -0.7149254679679871, 158 -2.7969717979431152, 1.086239218711853, -0.3560185432434082, 159 -0.24726025760173798, 3.7865755558013916, 0.016766052693128586, 160 -0.025338610634207726, -4.203672409057617, -0.1567438244819641, 161 3.495089292526245, 5.453553199768066, 0.16062140464782715 162 ], 163 'descriptor': {shape: [4, 6], dataType: 'float32'} 164 } 165 } 166 } 167 }, 168 { 169 'name': 'tan float32 3D tensor', 170 'graph': { 171 'inputs': { 172 'tanInput': { 173 'data': [ 174 52.69781494140625, 70.06912994384766, 90.49689483642578, 175 24.65666961669922, 11.66512680053711, -50.95264434814453, 176 40.320064544677734, -9.641122817993164, -31.567750930786133, 177 45.59520721435547, -55.93085861206055, -44.602970123291016, 178 80.4539794921875, -2.314880847930908, -25.474767684936523, 179 62.589454650878906, -70.94403076171875, 62.84861755371094, 180 84.79766845703125, -95.58502960205078, 15.552484512329102, 181 -55.25654220581055, -26.884889602661133, 0.159261092543602 182 ], 183 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 184 } 185 }, 186 'operators': [{ 187 'name': 'tan', 188 'arguments': [{'input': 'tanInput'}], 189 'outputs': 'tanOutput' 190 }], 191 'expectedOutputs': { 192 'tanOutput': { 193 'data': [ 194 -0.8582430481910706, 1.410544753074646, -0.6978657245635986, 195 -0.5156278610229492, -1.2633823156356812, -0.8205758929252625, 196 -0.5734118819236755, -0.21978461742401123, -0.1530018001794815, 197 -23.731182098388672, 0.7106066942214966, -0.7149254679679871, 198 -2.7969717979431152, 1.086239218711853, -0.3560185432434082, 199 -0.24726025760173798, 3.7865755558013916, 0.016766052693128586, 200 -0.025338610634207726, -4.203672409057617, -0.1567438244819641, 201 3.495089292526245, 5.453553199768066, 0.16062140464782715 202 ], 203 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 204 } 205 } 206 } 207 }, 208 { 209 'name': 'tan float32 4D tensor', 210 'graph': { 211 'inputs': { 212 'tanInput': { 213 'data': [ 214 52.69781494140625, 70.06912994384766, 90.49689483642578, 215 24.65666961669922, 11.66512680053711, -50.95264434814453, 216 40.320064544677734, -9.641122817993164, -31.567750930786133, 217 45.59520721435547, -55.93085861206055, -44.602970123291016, 218 80.4539794921875, -2.314880847930908, -25.474767684936523, 219 62.589454650878906, -70.94403076171875, 62.84861755371094, 220 84.79766845703125, -95.58502960205078, 15.552484512329102, 221 -55.25654220581055, -26.884889602661133, 0.159261092543602 222 ], 223 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 224 } 225 }, 226 'operators': [{ 227 'name': 'tan', 228 'arguments': [{'input': 'tanInput'}], 229 'outputs': 'tanOutput' 230 }], 231 'expectedOutputs': { 232 'tanOutput': { 233 'data': [ 234 -0.8582430481910706, 1.410544753074646, -0.6978657245635986, 235 -0.5156278610229492, -1.2633823156356812, -0.8205758929252625, 236 -0.5734118819236755, -0.21978461742401123, -0.1530018001794815, 237 -23.731182098388672, 0.7106066942214966, -0.7149254679679871, 238 -2.7969717979431152, 1.086239218711853, -0.3560185432434082, 239 -0.24726025760173798, 3.7865755558013916, 0.016766052693128586, 240 -0.025338610634207726, -4.203672409057617, -0.1567438244819641, 241 3.495089292526245, 5.453553199768066, 0.16062140464782715 242 ], 243 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 244 } 245 } 246 } 247 }, 248 { 249 'name': 'tan float32 5D tensor', 250 'graph': { 251 'inputs': { 252 'tanInput': { 253 'data': [ 254 52.69781494140625, 70.06912994384766, 90.49689483642578, 255 24.65666961669922, 11.66512680053711, -50.95264434814453, 256 40.320064544677734, -9.641122817993164, -31.567750930786133, 257 45.59520721435547, -55.93085861206055, -44.602970123291016, 258 80.4539794921875, -2.314880847930908, -25.474767684936523, 259 62.589454650878906, -70.94403076171875, 62.84861755371094, 260 84.79766845703125, -95.58502960205078, 15.552484512329102, 261 -55.25654220581055, -26.884889602661133, 0.159261092543602 262 ], 263 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 264 } 265 }, 266 'operators': [{ 267 'name': 'tan', 268 'arguments': [{'input': 'tanInput'}], 269 'outputs': 'tanOutput' 270 }], 271 'expectedOutputs': { 272 'tanOutput': { 273 'data': [ 274 -0.8582430481910706, 1.410544753074646, -0.6978657245635986, 275 -0.5156278610229492, -1.2633823156356812, -0.8205758929252625, 276 -0.5734118819236755, -0.21978461742401123, -0.1530018001794815, 277 -23.731182098388672, 0.7106066942214966, -0.7149254679679871, 278 -2.7969717979431152, 1.086239218711853, -0.3560185432434082, 279 -0.24726025760173798, 3.7865755558013916, 0.016766052693128586, 280 -0.025338610634207726, -4.203672409057617, -0.1567438244819641, 281 3.495089292526245, 5.453553199768066, 0.16062140464782715 282 ], 283 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 284 } 285 } 286 } 287 }, 288 289 // float16 tests 290 { 291 'name': 'tan float16 0D scalar', 292 'graph': { 293 'inputs': { 294 'tanInput': 295 {'data': [52.6875], 'descriptor': {shape: [], dataType: 'float16'}} 296 }, 297 'operators': [{ 298 'name': 'tan', 299 'arguments': [{'input': 'tanInput'}], 300 'outputs': 'tanOutput' 301 }], 302 'expectedOutputs': { 303 'tanOutput': { 304 'data': [-0.87646484375], 305 'descriptor': {shape: [], dataType: 'float16'} 306 } 307 } 308 } 309 }, 310 { 311 'name': 'tan float16 1D constant tensor', 312 'graph': { 313 'inputs': { 314 'tanInput': { 315 'data': [ 316 52.6875, 70.0625, 90.5, 24.65625, 11.6640625, 317 -50.9375, 40.3125, -9.640625, -31.5625, 5.59375, 318 -55.9375, -44.59375, 80.4375, -2.314453125, -25.46875, 319 62.59375, -70.9375, 62.84375, 84.8125, -95.5625, 320 15.5546875, -55.25, -26.890625, 0.1593017578125 321 ], 322 'descriptor': {shape: [24], dataType: 'float16'}, 323 'constant': true 324 } 325 }, 326 'operators': [{ 327 'name': 'tan', 328 'arguments': [{'input': 'tanInput'}], 329 'outputs': 'tanOutput' 330 }], 331 'expectedOutputs': { 332 'tanOutput': { 333 'data': [ 334 -0.87646484375, 1.390625, -0.693359375, 335 -0.51611328125, -1.2666015625, -0.79541015625, 336 -0.58349609375, -0.21923828125, -0.1475830078125, 337 -0.82421875, 0.70068359375, -0.701171875, 338 -2.94921875, 1.0869140625, -0.349365234375, 339 -0.24267578125, 3.888671875, 0.01189422607421875, 340 -0.01050567626953125, -3.8203125, -0.154541015625, 341 3.583984375, 5.28125, 0.16064453125 342 ], 343 'descriptor': {shape: [24], dataType: 'float16'} 344 } 345 } 346 } 347 }, 348 { 349 'name': 'tan float16 1D tensor', 350 'graph': { 351 'inputs': { 352 'tanInput': { 353 'data': [ 354 52.6875, 70.0625, 90.5, 24.65625, 11.6640625, 355 -50.9375, 40.3125, -9.640625, -31.5625, 5.59375, 356 -55.9375, -44.59375, 80.4375, -2.314453125, -25.46875, 357 62.59375, -70.9375, 62.84375, 84.8125, -95.5625, 358 15.5546875, -55.25, -26.890625, 0.1593017578125 359 ], 360 'descriptor': {shape: [24], dataType: 'float16'} 361 } 362 }, 363 'operators': [{ 364 'name': 'tan', 365 'arguments': [{'input': 'tanInput'}], 366 'outputs': 'tanOutput' 367 }], 368 'expectedOutputs': { 369 'tanOutput': { 370 'data': [ 371 -0.87646484375, 1.390625, -0.693359375, 372 -0.51611328125, -1.2666015625, -0.79541015625, 373 -0.58349609375, -0.21923828125, -0.1475830078125, 374 -0.82421875, 0.70068359375, -0.701171875, 375 -2.94921875, 1.0869140625, -0.349365234375, 376 -0.24267578125, 3.888671875, 0.01189422607421875, 377 -0.01050567626953125, -3.8203125, -0.154541015625, 378 3.583984375, 5.28125, 0.16064453125 379 ], 380 'descriptor': {shape: [24], dataType: 'float16'} 381 } 382 } 383 } 384 }, 385 { 386 'name': 'tan float16 2D tensor', 387 'graph': { 388 'inputs': { 389 'tanInput': { 390 'data': [ 391 52.6875, 70.0625, 90.5, 24.65625, 11.6640625, 392 -50.9375, 40.3125, -9.640625, -31.5625, 5.59375, 393 -55.9375, -44.59375, 80.4375, -2.314453125, -25.46875, 394 62.59375, -70.9375, 62.84375, 84.8125, -95.5625, 395 15.5546875, -55.25, -26.890625, 0.1593017578125 396 ], 397 'descriptor': {shape: [4, 6], dataType: 'float16'} 398 } 399 }, 400 'operators': [{ 401 'name': 'tan', 402 'arguments': [{'input': 'tanInput'}], 403 'outputs': 'tanOutput' 404 }], 405 'expectedOutputs': { 406 'tanOutput': { 407 'data': [ 408 -0.87646484375, 1.390625, -0.693359375, 409 -0.51611328125, -1.2666015625, -0.79541015625, 410 -0.58349609375, -0.21923828125, -0.1475830078125, 411 -0.82421875, 0.70068359375, -0.701171875, 412 -2.94921875, 1.0869140625, -0.349365234375, 413 -0.24267578125, 3.888671875, 0.01189422607421875, 414 -0.01050567626953125, -3.8203125, -0.154541015625, 415 3.583984375, 5.28125, 0.16064453125 416 ], 417 'descriptor': {shape: [4, 6], dataType: 'float16'} 418 } 419 } 420 } 421 }, 422 { 423 'name': 'tan float16 3D tensor', 424 'graph': { 425 'inputs': { 426 'tanInput': { 427 'data': [ 428 52.6875, 70.0625, 90.5, 24.65625, 11.6640625, 429 -50.9375, 40.3125, -9.640625, -31.5625, 5.59375, 430 -55.9375, -44.59375, 80.4375, -2.314453125, -25.46875, 431 62.59375, -70.9375, 62.84375, 84.8125, -95.5625, 432 15.5546875, -55.25, -26.890625, 0.1593017578125 433 ], 434 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 435 } 436 }, 437 'operators': [{ 438 'name': 'tan', 439 'arguments': [{'input': 'tanInput'}], 440 'outputs': 'tanOutput' 441 }], 442 'expectedOutputs': { 443 'tanOutput': { 444 'data': [ 445 -0.87646484375, 1.390625, -0.693359375, 446 -0.51611328125, -1.2666015625, -0.79541015625, 447 -0.58349609375, -0.21923828125, -0.1475830078125, 448 -0.82421875, 0.70068359375, -0.701171875, 449 -2.94921875, 1.0869140625, -0.349365234375, 450 -0.24267578125, 3.888671875, 0.01189422607421875, 451 -0.01050567626953125, -3.8203125, -0.154541015625, 452 3.583984375, 5.28125, 0.16064453125 453 ], 454 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 455 } 456 } 457 } 458 }, 459 { 460 'name': 'tan float16 4D tensor', 461 'graph': { 462 'inputs': { 463 'tanInput': { 464 'data': [ 465 52.6875, 70.0625, 90.5, 24.65625, 11.6640625, 466 -50.9375, 40.3125, -9.640625, -31.5625, 5.59375, 467 -55.9375, -44.59375, 80.4375, -2.314453125, -25.46875, 468 62.59375, -70.9375, 62.84375, 84.8125, -95.5625, 469 15.5546875, -55.25, -26.890625, 0.1593017578125 470 ], 471 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 472 } 473 }, 474 'operators': [{ 475 'name': 'tan', 476 'arguments': [{'input': 'tanInput'}], 477 'outputs': 'tanOutput' 478 }], 479 'expectedOutputs': { 480 'tanOutput': { 481 'data': [ 482 -0.87646484375, 1.390625, -0.693359375, 483 -0.51611328125, -1.2666015625, -0.79541015625, 484 -0.58349609375, -0.21923828125, -0.1475830078125, 485 -0.82421875, 0.70068359375, -0.701171875, 486 -2.94921875, 1.0869140625, -0.349365234375, 487 -0.24267578125, 3.888671875, 0.01189422607421875, 488 -0.01050567626953125, -3.8203125, -0.154541015625, 489 3.583984375, 5.28125, 0.16064453125 490 ], 491 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 492 } 493 } 494 } 495 }, 496 { 497 'name': 'tan float16 5D tensor', 498 'graph': { 499 'inputs': { 500 'tanInput': { 501 'data': [ 502 52.6875, 70.0625, 90.5, 24.65625, 11.6640625, 503 -50.9375, 40.3125, -9.640625, -31.5625, 5.59375, 504 -55.9375, -44.59375, 80.4375, -2.314453125, -25.46875, 505 62.59375, -70.9375, 62.84375, 84.8125, -95.5625, 506 15.5546875, -55.25, -26.890625, 0.1593017578125 507 ], 508 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 509 } 510 }, 511 'operators': [{ 512 'name': 'tan', 513 'arguments': [{'input': 'tanInput'}], 514 'outputs': 'tanOutput' 515 }], 516 'expectedOutputs': { 517 'tanOutput': { 518 'data': [ 519 -0.87646484375, 1.390625, -0.693359375, 520 -0.51611328125, -1.2666015625, -0.79541015625, 521 -0.58349609375, -0.21923828125, -0.1475830078125, 522 -0.82421875, 0.70068359375, -0.701171875, 523 -2.94921875, 1.0869140625, -0.349365234375, 524 -0.24267578125, 3.888671875, 0.01189422607421875, 525 -0.01050567626953125, -3.8203125, -0.154541015625, 526 3.583984375, 5.28125, 0.16064453125 527 ], 528 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 529 } 530 } 531 } 532 } 533 ]; 534 535 webnn_conformance_test( 536 tanTests, buildAndExecuteGraph, getTanPrecisionTolerance);