log.https.any.js (19008B)
1 // META: title=test WebNN API element-wise log 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 natural logarithm of the input tensor, element-wise. 13 // 14 // MLOperand log(MLOperand input); 15 16 17 const getLogPrecisionTolerance = () => { 18 return {metricType: 'ULP', value: 8}; 19 }; 20 21 const logTests = [ 22 { 23 'name': 'log float32 positive 0D scalar', 24 'graph': { 25 'inputs': { 26 'logInput': { 27 'data': [63.82542037963867], 28 'descriptor': {shape: [], dataType: 'float32'} 29 } 30 }, 31 'operators': [{ 32 'name': 'log', 33 'arguments': [{'input': 'logInput'}], 34 'outputs': 'logOutput' 35 }], 36 'expectedOutputs': { 37 'logOutput': { 38 'data': [4.15615177154541], 39 'descriptor': {shape: [], dataType: 'float32'} 40 } 41 } 42 } 43 }, 44 { 45 'name': 'log float32 positive 1D constant tensor', 46 'graph': { 47 'inputs': { 48 'logInput': { 49 'data': [ 50 63.82542037963867, 25.317724227905273, 96.44790649414062, 51 40.91856384277344, 36.579071044921875, 57.81629943847656, 52 10.057244300842285, 17.836828231811523, 50.79246520996094, 53 83.860595703125, 12.065509796142578, 22.702478408813477, 54 47.559814453125, 17.543880462646484, 32.65243911743164, 55 20.353010177612305, 52.54472351074219, 45.608802795410156, 56 30.385812759399414, 13.709558486938477, 10.396759986877441, 57 50.840946197509766, 5.682034492492676, 94.02275848388672 58 ], 59 'descriptor': {shape: [24], dataType: 'float32'}, 60 'constant': true 61 } 62 }, 63 'operators': [{ 64 'name': 'log', 65 'arguments': [{'input': 'logInput'}], 66 'outputs': 'logOutput' 67 }], 68 'expectedOutputs': { 69 'logOutput': { 70 'data': [ 71 4.15615177154541, 3.2315046787261963, 4.569003105163574, 72 3.7115838527679443, 3.5994763374328613, 4.057270526885986, 73 2.308293104171753, 2.88126540184021, 3.927747964859009, 74 4.4291558265686035, 2.4903509616851807, 3.122474193572998, 75 3.861988067626953, 2.8647050857543945, 3.48591947555542, 76 3.0132288932800293, 3.9616646766662598, 3.820100784301758, 77 3.413975715637207, 2.618093252182007, 2.34149432182312, 78 3.9287021160125732, 1.7373093366622925, 4.54353666305542 79 ], 80 'descriptor': {shape: [24], dataType: 'float32'} 81 } 82 } 83 } 84 }, 85 { 86 'name': 'log float32 positive 1D tensor', 87 'graph': { 88 'inputs': { 89 'logInput': { 90 'data': [ 91 63.82542037963867, 25.317724227905273, 96.44790649414062, 92 40.91856384277344, 36.579071044921875, 57.81629943847656, 93 10.057244300842285, 17.836828231811523, 50.79246520996094, 94 83.860595703125, 12.065509796142578, 22.702478408813477, 95 47.559814453125, 17.543880462646484, 32.65243911743164, 96 20.353010177612305, 52.54472351074219, 45.608802795410156, 97 30.385812759399414, 13.709558486938477, 10.396759986877441, 98 50.840946197509766, 5.682034492492676, 94.02275848388672 99 ], 100 'descriptor': {shape: [24], dataType: 'float32'} 101 } 102 }, 103 'operators': [{ 104 'name': 'log', 105 'arguments': [{'input': 'logInput'}], 106 'outputs': 'logOutput' 107 }], 108 'expectedOutputs': { 109 'logOutput': { 110 'data': [ 111 4.15615177154541, 3.2315046787261963, 4.569003105163574, 112 3.7115838527679443, 3.5994763374328613, 4.057270526885986, 113 2.308293104171753, 2.88126540184021, 3.927747964859009, 114 4.4291558265686035, 2.4903509616851807, 3.122474193572998, 115 3.861988067626953, 2.8647050857543945, 3.48591947555542, 116 3.0132288932800293, 3.9616646766662598, 3.820100784301758, 117 3.413975715637207, 2.618093252182007, 2.34149432182312, 118 3.9287021160125732, 1.7373093366622925, 4.54353666305542 119 ], 120 'descriptor': {shape: [24], dataType: 'float32'} 121 } 122 } 123 } 124 }, 125 { 126 'name': 'log float32 positive 2D tensor', 127 'graph': { 128 'inputs': { 129 'logInput': { 130 'data': [ 131 63.82542037963867, 25.317724227905273, 96.44790649414062, 132 40.91856384277344, 36.579071044921875, 57.81629943847656, 133 10.057244300842285, 17.836828231811523, 50.79246520996094, 134 83.860595703125, 12.065509796142578, 22.702478408813477, 135 47.559814453125, 17.543880462646484, 32.65243911743164, 136 20.353010177612305, 52.54472351074219, 45.608802795410156, 137 30.385812759399414, 13.709558486938477, 10.396759986877441, 138 50.840946197509766, 5.682034492492676, 94.02275848388672 139 ], 140 'descriptor': {shape: [4, 6], dataType: 'float32'} 141 } 142 }, 143 'operators': [{ 144 'name': 'log', 145 'arguments': [{'input': 'logInput'}], 146 'outputs': 'logOutput' 147 }], 148 'expectedOutputs': { 149 'logOutput': { 150 'data': [ 151 4.15615177154541, 3.2315046787261963, 4.569003105163574, 152 3.7115838527679443, 3.5994763374328613, 4.057270526885986, 153 2.308293104171753, 2.88126540184021, 3.927747964859009, 154 4.4291558265686035, 2.4903509616851807, 3.122474193572998, 155 3.861988067626953, 2.8647050857543945, 3.48591947555542, 156 3.0132288932800293, 3.9616646766662598, 3.820100784301758, 157 3.413975715637207, 2.618093252182007, 2.34149432182312, 158 3.9287021160125732, 1.7373093366622925, 4.54353666305542 159 ], 160 'descriptor': {shape: [4, 6], dataType: 'float32'} 161 } 162 } 163 } 164 }, 165 { 166 'name': 'log float32 positive 3D tensor', 167 'graph': { 168 'inputs': { 169 'logInput': { 170 'data': [ 171 63.82542037963867, 25.317724227905273, 96.44790649414062, 172 40.91856384277344, 36.579071044921875, 57.81629943847656, 173 10.057244300842285, 17.836828231811523, 50.79246520996094, 174 83.860595703125, 12.065509796142578, 22.702478408813477, 175 47.559814453125, 17.543880462646484, 32.65243911743164, 176 20.353010177612305, 52.54472351074219, 45.608802795410156, 177 30.385812759399414, 13.709558486938477, 10.396759986877441, 178 50.840946197509766, 5.682034492492676, 94.02275848388672 179 ], 180 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 181 } 182 }, 183 'operators': [{ 184 'name': 'log', 185 'arguments': [{'input': 'logInput'}], 186 'outputs': 'logOutput' 187 }], 188 'expectedOutputs': { 189 'logOutput': { 190 'data': [ 191 4.15615177154541, 3.2315046787261963, 4.569003105163574, 192 3.7115838527679443, 3.5994763374328613, 4.057270526885986, 193 2.308293104171753, 2.88126540184021, 3.927747964859009, 194 4.4291558265686035, 2.4903509616851807, 3.122474193572998, 195 3.861988067626953, 2.8647050857543945, 3.48591947555542, 196 3.0132288932800293, 3.9616646766662598, 3.820100784301758, 197 3.413975715637207, 2.618093252182007, 2.34149432182312, 198 3.9287021160125732, 1.7373093366622925, 4.54353666305542 199 ], 200 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 201 } 202 } 203 } 204 }, 205 { 206 'name': 'log float32 positive 4D tensor', 207 'graph': { 208 'inputs': { 209 'logInput': { 210 'data': [ 211 63.82542037963867, 25.317724227905273, 96.44790649414062, 212 40.91856384277344, 36.579071044921875, 57.81629943847656, 213 10.057244300842285, 17.836828231811523, 50.79246520996094, 214 83.860595703125, 12.065509796142578, 22.702478408813477, 215 47.559814453125, 17.543880462646484, 32.65243911743164, 216 20.353010177612305, 52.54472351074219, 45.608802795410156, 217 30.385812759399414, 13.709558486938477, 10.396759986877441, 218 50.840946197509766, 5.682034492492676, 94.02275848388672 219 ], 220 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 221 } 222 }, 223 'operators': [{ 224 'name': 'log', 225 'arguments': [{'input': 'logInput'}], 226 'outputs': 'logOutput' 227 }], 228 'expectedOutputs': { 229 'logOutput': { 230 'data': [ 231 4.15615177154541, 3.2315046787261963, 4.569003105163574, 232 3.7115838527679443, 3.5994763374328613, 4.057270526885986, 233 2.308293104171753, 2.88126540184021, 3.927747964859009, 234 4.4291558265686035, 2.4903509616851807, 3.122474193572998, 235 3.861988067626953, 2.8647050857543945, 3.48591947555542, 236 3.0132288932800293, 3.9616646766662598, 3.820100784301758, 237 3.413975715637207, 2.618093252182007, 2.34149432182312, 238 3.9287021160125732, 1.7373093366622925, 4.54353666305542 239 ], 240 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 241 } 242 } 243 } 244 }, 245 { 246 'name': 'log float32 positive 5D tensor', 247 'graph': { 248 'inputs': { 249 'logInput': { 250 'data': [ 251 63.82542037963867, 25.317724227905273, 96.44790649414062, 252 40.91856384277344, 36.579071044921875, 57.81629943847656, 253 10.057244300842285, 17.836828231811523, 50.79246520996094, 254 83.860595703125, 12.065509796142578, 22.702478408813477, 255 47.559814453125, 17.543880462646484, 32.65243911743164, 256 20.353010177612305, 52.54472351074219, 45.608802795410156, 257 30.385812759399414, 13.709558486938477, 10.396759986877441, 258 50.840946197509766, 5.682034492492676, 94.02275848388672 259 ], 260 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 261 } 262 }, 263 'operators': [{ 264 'name': 'log', 265 'arguments': [{'input': 'logInput'}], 266 'outputs': 'logOutput' 267 }], 268 'expectedOutputs': { 269 'logOutput': { 270 'data': [ 271 4.15615177154541, 3.2315046787261963, 4.569003105163574, 272 3.7115838527679443, 3.5994763374328613, 4.057270526885986, 273 2.308293104171753, 2.88126540184021, 3.927747964859009, 274 4.4291558265686035, 2.4903509616851807, 3.122474193572998, 275 3.861988067626953, 2.8647050857543945, 3.48591947555542, 276 3.0132288932800293, 3.9616646766662598, 3.820100784301758, 277 3.413975715637207, 2.618093252182007, 2.34149432182312, 278 3.9287021160125732, 1.7373093366622925, 4.54353666305542 279 ], 280 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 281 } 282 } 283 } 284 }, 285 286 // float16 tests 287 { 288 'name': 'log float16 positive 0D scalar', 289 'graph': { 290 'inputs': { 291 'logInput': 292 {'data': [63.8125], 'descriptor': {shape: [], dataType: 'float16'}} 293 }, 294 'operators': [{ 295 'name': 'log', 296 'arguments': [{'input': 'logInput'}], 297 'outputs': 'logOutput' 298 }], 299 'expectedOutputs': { 300 'logOutput': 301 {'data': [4.15625], 'descriptor': {shape: [], dataType: 'float16'}} 302 } 303 } 304 }, 305 { 306 'name': 'log float16 positive 1D constant tensor', 307 'graph': { 308 'inputs': { 309 'logInput': { 310 'data': [ 311 63.8125, 25.3125, 96.4375, 40.90625, 36.59375, 312 57.8125, 10.0546875, 17.84375, 50.78125, 83.875, 313 12.0625, 22.703125, 47.5625, 17.546875, 32.65625, 314 20.359375, 52.53125, 45.59375, 30.390625, 13.7109375, 315 10.3984375, 50.84375, 5.68359375, 94 316 ], 317 'descriptor': {shape: [24], dataType: 'float16'}, 318 'constant': true 319 } 320 }, 321 'operators': [{ 322 'name': 'log', 323 'arguments': [{'input': 'logInput'}], 324 'outputs': 'logOutput' 325 }], 326 'expectedOutputs': { 327 'logOutput': { 328 'data': [ 329 4.15625, 3.23046875, 4.5703125, 3.7109375, 3.599609375, 330 4.05859375, 2.30859375, 2.880859375, 3.927734375, 4.4296875, 331 2.490234375, 3.123046875, 3.861328125, 2.865234375, 3.486328125, 332 3.013671875, 3.9609375, 3.8203125, 3.4140625, 2.619140625, 333 2.341796875, 3.9296875, 1.7373046875, 4.54296875 334 ], 335 'descriptor': {shape: [24], dataType: 'float16'} 336 } 337 } 338 } 339 }, 340 { 341 'name': 'log float16 positive 1D tensor', 342 'graph': { 343 'inputs': { 344 'logInput': { 345 'data': [ 346 63.8125, 25.3125, 96.4375, 40.90625, 36.59375, 347 57.8125, 10.0546875, 17.84375, 50.78125, 83.875, 348 12.0625, 22.703125, 47.5625, 17.546875, 32.65625, 349 20.359375, 52.53125, 45.59375, 30.390625, 13.7109375, 350 10.3984375, 50.84375, 5.68359375, 94 351 ], 352 'descriptor': {shape: [24], dataType: 'float16'} 353 } 354 }, 355 'operators': [{ 356 'name': 'log', 357 'arguments': [{'input': 'logInput'}], 358 'outputs': 'logOutput' 359 }], 360 'expectedOutputs': { 361 'logOutput': { 362 'data': [ 363 4.15625, 3.23046875, 4.5703125, 3.7109375, 3.599609375, 364 4.05859375, 2.30859375, 2.880859375, 3.927734375, 4.4296875, 365 2.490234375, 3.123046875, 3.861328125, 2.865234375, 3.486328125, 366 3.013671875, 3.9609375, 3.8203125, 3.4140625, 2.619140625, 367 2.341796875, 3.9296875, 1.7373046875, 4.54296875 368 ], 369 'descriptor': {shape: [24], dataType: 'float16'} 370 } 371 } 372 } 373 }, 374 { 375 'name': 'log float16 positive 2D tensor', 376 'graph': { 377 'inputs': { 378 'logInput': { 379 'data': [ 380 63.8125, 25.3125, 96.4375, 40.90625, 36.59375, 381 57.8125, 10.0546875, 17.84375, 50.78125, 83.875, 382 12.0625, 22.703125, 47.5625, 17.546875, 32.65625, 383 20.359375, 52.53125, 45.59375, 30.390625, 13.7109375, 384 10.3984375, 50.84375, 5.68359375, 94 385 ], 386 'descriptor': {shape: [4, 6], dataType: 'float16'} 387 } 388 }, 389 'operators': [{ 390 'name': 'log', 391 'arguments': [{'input': 'logInput'}], 392 'outputs': 'logOutput' 393 }], 394 'expectedOutputs': { 395 'logOutput': { 396 'data': [ 397 4.15625, 3.23046875, 4.5703125, 3.7109375, 3.599609375, 398 4.05859375, 2.30859375, 2.880859375, 3.927734375, 4.4296875, 399 2.490234375, 3.123046875, 3.861328125, 2.865234375, 3.486328125, 400 3.013671875, 3.9609375, 3.8203125, 3.4140625, 2.619140625, 401 2.341796875, 3.9296875, 1.7373046875, 4.54296875 402 ], 403 'descriptor': {shape: [4, 6], dataType: 'float16'} 404 } 405 } 406 } 407 }, 408 { 409 'name': 'log float16 positive 3D tensor', 410 'graph': { 411 'inputs': { 412 'logInput': { 413 'data': [ 414 63.8125, 25.3125, 96.4375, 40.90625, 36.59375, 415 57.8125, 10.0546875, 17.84375, 50.78125, 83.875, 416 12.0625, 22.703125, 47.5625, 17.546875, 32.65625, 417 20.359375, 52.53125, 45.59375, 30.390625, 13.7109375, 418 10.3984375, 50.84375, 5.68359375, 94 419 ], 420 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 421 } 422 }, 423 'operators': [{ 424 'name': 'log', 425 'arguments': [{'input': 'logInput'}], 426 'outputs': 'logOutput' 427 }], 428 'expectedOutputs': { 429 'logOutput': { 430 'data': [ 431 4.15625, 3.23046875, 4.5703125, 3.7109375, 3.599609375, 432 4.05859375, 2.30859375, 2.880859375, 3.927734375, 4.4296875, 433 2.490234375, 3.123046875, 3.861328125, 2.865234375, 3.486328125, 434 3.013671875, 3.9609375, 3.8203125, 3.4140625, 2.619140625, 435 2.341796875, 3.9296875, 1.7373046875, 4.54296875 436 ], 437 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 438 } 439 } 440 } 441 }, 442 { 443 'name': 'log float16 positive 4D tensor', 444 'graph': { 445 'inputs': { 446 'logInput': { 447 'data': [ 448 63.8125, 25.3125, 96.4375, 40.90625, 36.59375, 449 57.8125, 10.0546875, 17.84375, 50.78125, 83.875, 450 12.0625, 22.703125, 47.5625, 17.546875, 32.65625, 451 20.359375, 52.53125, 45.59375, 30.390625, 13.7109375, 452 10.3984375, 50.84375, 5.68359375, 94 453 ], 454 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 455 } 456 }, 457 'operators': [{ 458 'name': 'log', 459 'arguments': [{'input': 'logInput'}], 460 'outputs': 'logOutput' 461 }], 462 'expectedOutputs': { 463 'logOutput': { 464 'data': [ 465 4.15625, 3.23046875, 4.5703125, 3.7109375, 3.599609375, 466 4.05859375, 2.30859375, 2.880859375, 3.927734375, 4.4296875, 467 2.490234375, 3.123046875, 3.861328125, 2.865234375, 3.486328125, 468 3.013671875, 3.9609375, 3.8203125, 3.4140625, 2.619140625, 469 2.341796875, 3.9296875, 1.7373046875, 4.54296875 470 ], 471 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 472 } 473 } 474 } 475 }, 476 { 477 'name': 'log float16 positive 5D tensor', 478 'graph': { 479 'inputs': { 480 'logInput': { 481 'data': [ 482 63.8125, 25.3125, 96.4375, 40.90625, 36.59375, 483 57.8125, 10.0546875, 17.84375, 50.78125, 83.875, 484 12.0625, 22.703125, 47.5625, 17.546875, 32.65625, 485 20.359375, 52.53125, 45.59375, 30.390625, 13.7109375, 486 10.3984375, 50.84375, 5.68359375, 94 487 ], 488 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 489 } 490 }, 491 'operators': [{ 492 'name': 'log', 493 'arguments': [{'input': 'logInput'}], 494 'outputs': 'logOutput' 495 }], 496 'expectedOutputs': { 497 'logOutput': { 498 'data': [ 499 4.15625, 3.23046875, 4.5703125, 3.7109375, 3.599609375, 500 4.05859375, 2.30859375, 2.880859375, 3.927734375, 4.4296875, 501 2.490234375, 3.123046875, 3.861328125, 2.865234375, 3.486328125, 502 3.013671875, 3.9609375, 3.8203125, 3.4140625, 2.619140625, 503 2.341796875, 3.9296875, 1.7373046875, 4.54296875 504 ], 505 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 506 } 507 } 508 } 509 } 510 ]; 511 512 webnn_conformance_test( 513 logTests, buildAndExecuteGraph, getLogPrecisionTolerance);