linear.https.any.js (40232B)
1 // META: title=test WebNN API linear 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-linear 12 // Calculate a linear function y = alpha * x + beta on the input tensor. 13 // 14 // dictionary MLLinearOptions { 15 // double alpha = 1; 16 // double beta = 0; 17 // }; 18 // 19 // MLOperand linear(MLOperand input, optional MLLinearOptions options = {}); 20 21 const linearTests = [ 22 // float32 tests 23 { 24 'name': 'linear float32 1D constant tensor default options', 25 'graph': { 26 'inputs': { 27 'linearInput': { 28 'data': [ 29 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 30 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 31 3.7465922832489014, -4.487029552459717, 6.407402038574219, 32 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 33 -6.330113887786865, 8.580595016479492, -6.764922142028809, 34 6.433565616607666, -9.708685874938965, 2.6431379318237305, 35 5.2140889167785645, 9.65861701965332, -8.721749305725098, 36 -0.4533396363258362, 9.992619514465332, -6.469675064086914 37 ], 38 'descriptor': {shape: [24], dataType: 'float32'}, 39 'constant': true 40 } 41 }, 42 'operators': [{ 43 'name': 'linear', 44 'arguments': [{'input': 'linearInput'}], 45 'outputs': 'linearOutput' 46 }], 47 'expectedOutputs': { 48 'linearOutput': { 49 'data': [ 50 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 51 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 52 3.7465922832489014, -4.487029552459717, 6.407402038574219, 53 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 54 -6.330113887786865, 8.580595016479492, -6.764922142028809, 55 6.433565616607666, -9.708685874938965, 2.6431379318237305, 56 5.2140889167785645, 9.65861701965332, -8.721749305725098, 57 -0.4533396363258362, 9.992619514465332, -6.469675064086914 58 ], 59 'descriptor': {shape: [24], dataType: 'float32'} 60 } 61 } 62 } 63 }, 64 { 65 'name': 'linear float32 0D tensor default options', 66 'graph': { 67 'inputs': { 68 'linearInput': { 69 'data': [-1.12251615524292], 70 'descriptor': {shape: [], dataType: 'float32'} 71 } 72 }, 73 'operators': [{ 74 'name': 'linear', 75 'arguments': [{'input': 'linearInput'}], 76 'outputs': 'linearOutput' 77 }], 78 'expectedOutputs': { 79 'linearOutput': { 80 'data': [-1.12251615524292], 81 'descriptor': {shape: [], dataType: 'float32'} 82 } 83 } 84 } 85 }, 86 { 87 'name': 'linear float32 1D tensor default options', 88 'graph': { 89 'inputs': { 90 'linearInput': { 91 'data': [ 92 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 93 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 94 3.7465922832489014, -4.487029552459717, 6.407402038574219, 95 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 96 -6.330113887786865, 8.580595016479492, -6.764922142028809, 97 6.433565616607666, -9.708685874938965, 2.6431379318237305, 98 5.2140889167785645, 9.65861701965332, -8.721749305725098, 99 -0.4533396363258362, 9.992619514465332, -6.469675064086914 100 ], 101 'descriptor': {shape: [24], dataType: 'float32'} 102 } 103 }, 104 'operators': [{ 105 'name': 'linear', 106 'arguments': [{'input': 'linearInput'}], 107 'outputs': 'linearOutput' 108 }], 109 'expectedOutputs': { 110 'linearOutput': { 111 'data': [ 112 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 113 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 114 3.7465922832489014, -4.487029552459717, 6.407402038574219, 115 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 116 -6.330113887786865, 8.580595016479492, -6.764922142028809, 117 6.433565616607666, -9.708685874938965, 2.6431379318237305, 118 5.2140889167785645, 9.65861701965332, -8.721749305725098, 119 -0.4533396363258362, 9.992619514465332, -6.469675064086914 120 ], 121 'descriptor': {shape: [24], dataType: 'float32'} 122 } 123 } 124 } 125 }, 126 { 127 'name': 'linear float32 2D tensor default options', 128 'graph': { 129 'inputs': { 130 'linearInput': { 131 'data': [ 132 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 133 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 134 3.7465922832489014, -4.487029552459717, 6.407402038574219, 135 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 136 -6.330113887786865, 8.580595016479492, -6.764922142028809, 137 6.433565616607666, -9.708685874938965, 2.6431379318237305, 138 5.2140889167785645, 9.65861701965332, -8.721749305725098, 139 -0.4533396363258362, 9.992619514465332, -6.469675064086914 140 ], 141 'descriptor': {shape: [4, 6], dataType: 'float32'} 142 } 143 }, 144 'operators': [{ 145 'name': 'linear', 146 'arguments': [{'input': 'linearInput'}], 147 'outputs': 'linearOutput' 148 }], 149 'expectedOutputs': { 150 'linearOutput': { 151 'data': [ 152 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 153 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 154 3.7465922832489014, -4.487029552459717, 6.407402038574219, 155 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 156 -6.330113887786865, 8.580595016479492, -6.764922142028809, 157 6.433565616607666, -9.708685874938965, 2.6431379318237305, 158 5.2140889167785645, 9.65861701965332, -8.721749305725098, 159 -0.4533396363258362, 9.992619514465332, -6.469675064086914 160 ], 161 'descriptor': {shape: [4, 6], dataType: 'float32'} 162 } 163 } 164 } 165 }, 166 { 167 'name': 'linear float32 3D tensor default options', 168 'graph': { 169 'inputs': { 170 'linearInput': { 171 'data': [ 172 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 173 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 174 3.7465922832489014, -4.487029552459717, 6.407402038574219, 175 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 176 -6.330113887786865, 8.580595016479492, -6.764922142028809, 177 6.433565616607666, -9.708685874938965, 2.6431379318237305, 178 5.2140889167785645, 9.65861701965332, -8.721749305725098, 179 -0.4533396363258362, 9.992619514465332, -6.469675064086914 180 ], 181 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 182 } 183 }, 184 'operators': [{ 185 'name': 'linear', 186 'arguments': [{'input': 'linearInput'}], 187 'outputs': 'linearOutput' 188 }], 189 'expectedOutputs': { 190 'linearOutput': { 191 'data': [ 192 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 193 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 194 3.7465922832489014, -4.487029552459717, 6.407402038574219, 195 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 196 -6.330113887786865, 8.580595016479492, -6.764922142028809, 197 6.433565616607666, -9.708685874938965, 2.6431379318237305, 198 5.2140889167785645, 9.65861701965332, -8.721749305725098, 199 -0.4533396363258362, 9.992619514465332, -6.469675064086914 200 ], 201 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 202 } 203 } 204 } 205 }, 206 { 207 'name': 'linear float32 4D tensor default options', 208 'graph': { 209 'inputs': { 210 'linearInput': { 211 'data': [ 212 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 213 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 214 3.7465922832489014, -4.487029552459717, 6.407402038574219, 215 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 216 -6.330113887786865, 8.580595016479492, -6.764922142028809, 217 6.433565616607666, -9.708685874938965, 2.6431379318237305, 218 5.2140889167785645, 9.65861701965332, -8.721749305725098, 219 -0.4533396363258362, 9.992619514465332, -6.469675064086914 220 ], 221 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 222 } 223 }, 224 'operators': [{ 225 'name': 'linear', 226 'arguments': [{'input': 'linearInput'}], 227 'outputs': 'linearOutput' 228 }], 229 'expectedOutputs': { 230 'linearOutput': { 231 'data': [ 232 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 233 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 234 3.7465922832489014, -4.487029552459717, 6.407402038574219, 235 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 236 -6.330113887786865, 8.580595016479492, -6.764922142028809, 237 6.433565616607666, -9.708685874938965, 2.6431379318237305, 238 5.2140889167785645, 9.65861701965332, -8.721749305725098, 239 -0.4533396363258362, 9.992619514465332, -6.469675064086914 240 ], 241 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 242 } 243 } 244 } 245 }, 246 { 247 'name': 'linear float32 5D tensor default options', 248 'graph': { 249 'inputs': { 250 'linearInput': { 251 'data': [ 252 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 253 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 254 3.7465922832489014, -4.487029552459717, 6.407402038574219, 255 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 256 -6.330113887786865, 8.580595016479492, -6.764922142028809, 257 6.433565616607666, -9.708685874938965, 2.6431379318237305, 258 5.2140889167785645, 9.65861701965332, -8.721749305725098, 259 -0.4533396363258362, 9.992619514465332, -6.469675064086914 260 ], 261 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 262 } 263 }, 264 'operators': [{ 265 'name': 'linear', 266 'arguments': [{'input': 'linearInput'}], 267 'outputs': 'linearOutput' 268 }], 269 'expectedOutputs': { 270 'linearOutput': { 271 'data': [ 272 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 273 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 274 3.7465922832489014, -4.487029552459717, 6.407402038574219, 275 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 276 -6.330113887786865, 8.580595016479492, -6.764922142028809, 277 6.433565616607666, -9.708685874938965, 2.6431379318237305, 278 5.2140889167785645, 9.65861701965332, -8.721749305725098, 279 -0.4533396363258362, 9.992619514465332, -6.469675064086914 280 ], 281 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 282 } 283 } 284 } 285 }, 286 { 287 'name': 288 'linear float32 4D tensor specified options.alpha and default options.beta', 289 'graph': { 290 'inputs': { 291 'linearInput': { 292 'data': [ 293 -1.12251615524292, -6.605223178863525, -1.9555538892745972, 294 -4.598548412322998, 4.234208106994629, 3.0975420475006104, 295 3.7465922832489014, -4.487029552459717, 6.407402038574219, 296 -4.354544162750244, -5.819092750549316, 3.7214345932006836, 297 -6.330113887786865, 8.580595016479492, -6.764922142028809, 298 6.433565616607666, -9.708685874938965, 2.6431379318237305, 299 5.2140889167785645, 9.65861701965332, -8.721749305725098, 300 -0.4533396363258362, 9.992619514465332, -6.469675064086914 301 ], 302 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 303 } 304 }, 305 'operators': [{ 306 'name': 'linear', 307 'arguments': [ 308 {'input': 'linearInput'}, {'options': {'alpha': 7.398793812746618}} 309 ], 310 'outputs': 'linearOutput' 311 }], 312 'expectedOutputs': { 313 'linearOutput': { 314 'data': [ 315 -8.305265426635742, -48.87068176269531, -14.46873950958252, 316 -34.023712158203125, 31.328031539916992, 22.918073654174805, 317 27.72026252746582, -33.198604583740234, 47.407047271728516, 318 -32.2183723449707, -43.05426788330078, 27.53412628173828, 319 -46.835205078125, 63.486053466796875, -50.05226516723633, 320 47.600624084472656, -71.83256530761719, 19.556032180786133, 321 38.57796859741211, 71.46211242675781, -64.53042602539062, 322 -3.3541665077209473, 73.9333267211914, -47.86779022216797 323 ], 324 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 325 } 326 } 327 } 328 }, 329 { 330 'name': 331 'linear float32 positive 4D tensor specified positive options.beta and default options.alpha', 332 'graph': { 333 'inputs': { 334 'linearInput': { 335 'data': [ 336 5.098546028137207, 3.381463050842285, 8.054762840270996, 337 8.074773788452148, 0.47079092264175415, 5.243824005126953, 338 3.827306032180786, 5.3697686195373535, 6.1033172607421875, 339 3.7505786418914795, 0.7479738593101501, 1.8931976556777954, 340 1.9056464433670044, 7.863316059112549, 4.58075475692749, 341 9.373635292053223, 6.584214210510254, 9.344809532165527, 342 5.16057825088501, 0.8060914278030396, 9.130533218383789, 343 3.1937403678894043, 5.748293399810791, 4.113487720489502 344 ], 345 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 346 } 347 }, 348 'operators': [{ 349 'name': 'linear', 350 'arguments': [ 351 {'input': 'linearInput'}, {'options': {'beta': 5.919095653700928}} 352 ], 353 'outputs': 'linearOutput' 354 }], 355 'expectedOutputs': { 356 'linearOutput': { 357 'data': [ 358 11.017641067504883, 9.300558090209961, 13.973857879638672, 359 13.99386978149414, 6.389886379241943, 11.162919998168945, 360 9.7464017868042, 11.288864135742188, 12.02241325378418, 361 9.669673919677734, 6.667069435119629, 7.81229305267334, 362 7.824741840362549, 13.782411575317383, 10.499850273132324, 363 15.292730331420898, 12.50330924987793, 15.263904571533203, 364 11.079673767089844, 6.725186824798584, 15.049629211425781, 365 9.112835884094238, 11.667388916015625, 10.032583236694336 366 ], 367 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 368 } 369 } 370 } 371 }, 372 { 373 'name': 374 'linear float32 negative 4D tensor specified negative options.beta and default options.alpha', 375 'graph': { 376 'inputs': { 377 'linearInput': { 378 'data': [ 379 -5.098546028137207, -3.381463050842285, -8.054762840270996, 380 -8.074773788452148, -0.47079092264175415, -5.243824005126953, 381 -3.827306032180786, -5.3697686195373535, -6.1033172607421875, 382 -3.7505786418914795, -0.7479738593101501, -1.8931976556777954, 383 -1.9056464433670044, -7.863316059112549, -4.58075475692749, 384 -9.373635292053223, -6.584214210510254, -9.344809532165527, 385 -5.16057825088501, -0.8060914278030396, -9.130533218383789, 386 -3.1937403678894043, -5.748293399810791, -4.113487720489502 387 ], 388 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 389 } 390 }, 391 'operators': [{ 392 'name': 'linear', 393 'arguments': [ 394 {'input': 'linearInput'}, {'options': {'beta': -5.919095653700928}} 395 ], 396 'outputs': 'linearOutput' 397 }], 398 'expectedOutputs': { 399 'linearOutput': { 400 'data': [ 401 -11.017641067504883, -9.300558090209961, -13.973857879638672, 402 -13.99386978149414, -6.389886379241943, -11.162919998168945, 403 -9.7464017868042, -11.288864135742188, -12.02241325378418, 404 -9.669673919677734, -6.667069435119629, -7.81229305267334, 405 -7.824741840362549, -13.782411575317383, -10.499850273132324, 406 -15.292730331420898, -12.50330924987793, -15.263904571533203, 407 -11.079673767089844, -6.725186824798584, -15.049629211425781, 408 -9.112835884094238, -11.667388916015625, -10.032583236694336 409 ], 410 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 411 } 412 } 413 } 414 }, 415 { 416 'name': 417 'linear float32 positive 4D tensor all options (positive options.alpha and positive options.beta)', 418 'graph': { 419 'inputs': { 420 'linearInput': { 421 'data': [ 422 5.098546028137207, 3.381463050842285, 8.054762840270996, 423 8.074773788452148, 0.47079092264175415, 5.243824005126953, 424 3.827306032180786, 5.3697686195373535, 6.1033172607421875, 425 3.7505786418914795, 0.7479738593101501, 1.8931976556777954, 426 1.9056464433670044, 7.863316059112549, 4.58075475692749, 427 9.373635292053223, 6.584214210510254, 9.344809532165527, 428 5.16057825088501, 0.8060914278030396, 9.130533218383789, 429 3.1937403678894043, 5.748293399810791, 4.113487720489502 430 ], 431 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 432 } 433 }, 434 'operators': [{ 435 'name': 'linear', 436 'arguments': [ 437 {'input': 'linearInput'}, 438 {'options': {'alpha': 7.398793812746618, 'beta': 5.919095653700928}} 439 ], 440 'outputs': 'linearOutput' 441 }], 442 'expectedOutputs': { 443 'linearOutput': { 444 'data': [ 445 43.64218521118164, 30.937843322753906, 65.5146255493164, 446 65.66268157958984, 9.402379989624023, 44.71706771850586, 447 34.236541748046875, 45.64890670776367, 51.0762825012207, 448 33.668853759765625, 11.45319938659668, 19.92647361755371, 449 20.018579483032227, 64.09815216064453, 39.811153411865234, 450 75.27268981933594, 54.63433837890625, 75.05941009521484, 451 44.10115051269531, 11.883199691772461, 73.47402954101562, 452 29.548921585083008, 48.44953155517578, 36.35394287109375 453 ], 454 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 455 } 456 } 457 } 458 }, 459 { 460 'name': 461 'linear float32 positive 4D tensor all options (negative options.alpha and negative options.beta)', 462 'graph': { 463 'inputs': { 464 'linearInput': { 465 'data': [ 466 5.098546028137207, 3.381463050842285, 8.054762840270996, 467 8.074773788452148, 0.47079092264175415, 5.243824005126953, 468 3.827306032180786, 5.3697686195373535, 6.1033172607421875, 469 3.7505786418914795, 0.7479738593101501, 1.8931976556777954, 470 1.9056464433670044, 7.863316059112549, 4.58075475692749, 471 9.373635292053223, 6.584214210510254, 9.344809532165527, 472 5.16057825088501, 0.8060914278030396, 9.130533218383789, 473 3.1937403678894043, 5.748293399810791, 4.113487720489502 474 ], 475 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 476 } 477 }, 478 'operators': [{ 479 'name': 'linear', 480 'arguments': [ 481 {'input': 'linearInput'}, 482 {'options': {'alpha': -7.398793812746618, 'beta': -5.919095653700928}} 483 ], 484 'outputs': 'linearOutput' 485 }], 486 'expectedOutputs': { 487 'linearOutput': { 488 'data': [ 489 -43.64218521118164, -30.937843322753906, -65.5146255493164, 490 -65.66268157958984, -9.402379989624023, -44.71706771850586, 491 -34.236541748046875, -45.64890670776367, -51.0762825012207, 492 -33.668853759765625, -11.45319938659668, -19.92647361755371, 493 -20.018579483032227, -64.09815216064453, -39.811153411865234, 494 -75.27268981933594, -54.63433837890625, -75.05941009521484, 495 -44.10115051269531, -11.883199691772461, -73.47402954101562, 496 -29.548921585083008, -48.44953155517578, -36.35394287109375 497 ], 498 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 499 } 500 } 501 } 502 }, 503 { 504 'name': 505 'linear float32 negative 4D tensor all options (positive options.alpha and negative options.beta)', 506 'graph': { 507 'inputs': { 508 'linearInput': { 509 'data': [ 510 -5.098546028137207, -3.381463050842285, -8.054762840270996, 511 -8.074773788452148, -0.47079092264175415, -5.243824005126953, 512 -3.827306032180786, -5.3697686195373535, -6.1033172607421875, 513 -3.7505786418914795, -0.7479738593101501, -1.8931976556777954, 514 -1.9056464433670044, -7.863316059112549, -4.58075475692749, 515 -9.373635292053223, -6.584214210510254, -9.344809532165527, 516 -5.16057825088501, -0.8060914278030396, -9.130533218383789, 517 -3.1937403678894043, -5.748293399810791, -4.113487720489502 518 ], 519 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 520 } 521 }, 522 'operators': [{ 523 'name': 'linear', 524 'arguments': [ 525 {'input': 'linearInput'}, 526 {'options': {'alpha': 7.398793812746618, 'beta': -5.919095653700928}} 527 ], 528 'outputs': 'linearOutput' 529 }], 530 'expectedOutputs': { 531 'linearOutput': { 532 'data': [ 533 -43.64218521118164, -30.937843322753906, -65.5146255493164, 534 -65.66268157958984, -9.402379989624023, -44.71706771850586, 535 -34.236541748046875, -45.64890670776367, -51.0762825012207, 536 -33.668853759765625, -11.45319938659668, -19.92647361755371, 537 -20.018579483032227, -64.09815216064453, -39.811153411865234, 538 -75.27268981933594, -54.63433837890625, -75.05941009521484, 539 -44.10115051269531, -11.883199691772461, -73.47402954101562, 540 -29.548921585083008, -48.44953155517578, -36.35394287109375 541 ], 542 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 543 } 544 } 545 } 546 }, 547 548 // float16 tests 549 { 550 'name': 'linear float16 1D constant tensor default options', 551 'graph': { 552 'inputs': { 553 'linearInput': { 554 'data': [ 555 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 556 4.234375, 3.09765625, 3.74609375, -4.48828125, 557 6.40625, -4.35546875, -5.8203125, 3.720703125, 558 -6.33203125, 8.578125, -6.765625, 6.43359375, 559 -9.7109375, 2.642578125, 5.21484375, 9.65625, 560 -8.71875, -0.453369140625, 9.9921875, -6.46875 561 ], 562 'descriptor': {shape: [24], dataType: 'float16'}, 563 'constant': true 564 } 565 }, 566 'operators': [{ 567 'name': 'linear', 568 'arguments': [{'input': 'linearInput'}], 569 'outputs': 'linearOutput' 570 }], 571 'expectedOutputs': { 572 'linearOutput': { 573 'data': [ 574 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 575 4.234375, 3.09765625, 3.74609375, -4.48828125, 576 6.40625, -4.35546875, -5.8203125, 3.720703125, 577 -6.33203125, 8.578125, -6.765625, 6.43359375, 578 -9.7109375, 2.642578125, 5.21484375, 9.65625, 579 -8.71875, -0.453369140625, 9.9921875, -6.46875 580 ], 581 'descriptor': {shape: [24], dataType: 'float16'} 582 } 583 } 584 } 585 }, 586 { 587 'name': 'linear float16 0D tensor default options', 588 'graph': { 589 'inputs': { 590 'linearInput': { 591 'data': [-1.1220703125], 592 'descriptor': {shape: [], dataType: 'float16'} 593 } 594 }, 595 'operators': [{ 596 'name': 'linear', 597 'arguments': [{'input': 'linearInput'}], 598 'outputs': 'linearOutput' 599 }], 600 'expectedOutputs': { 601 'linearOutput': { 602 'data': [-1.1220703125], 603 'descriptor': {shape: [], dataType: 'float16'} 604 } 605 } 606 } 607 }, 608 { 609 'name': 'linear float16 1D tensor default options', 610 'graph': { 611 'inputs': { 612 'linearInput': { 613 'data': [ 614 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 615 4.234375, 3.09765625, 3.74609375, -4.48828125, 616 6.40625, -4.35546875, -5.8203125, 3.720703125, 617 -6.33203125, 8.578125, -6.765625, 6.43359375, 618 -9.7109375, 2.642578125, 5.21484375, 9.65625, 619 -8.71875, -0.453369140625, 9.9921875, -6.46875 620 ], 621 'descriptor': {shape: [24], dataType: 'float16'} 622 } 623 }, 624 'operators': [{ 625 'name': 'linear', 626 'arguments': [{'input': 'linearInput'}], 627 'outputs': 'linearOutput' 628 }], 629 'expectedOutputs': { 630 'linearOutput': { 631 'data': [ 632 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 633 4.234375, 3.09765625, 3.74609375, -4.48828125, 634 6.40625, -4.35546875, -5.8203125, 3.720703125, 635 -6.33203125, 8.578125, -6.765625, 6.43359375, 636 -9.7109375, 2.642578125, 5.21484375, 9.65625, 637 -8.71875, -0.453369140625, 9.9921875, -6.46875 638 ], 639 'descriptor': {shape: [24], dataType: 'float16'} 640 } 641 } 642 } 643 }, 644 { 645 'name': 'linear float16 2D tensor default options', 646 'graph': { 647 'inputs': { 648 'linearInput': { 649 'data': [ 650 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 651 4.234375, 3.09765625, 3.74609375, -4.48828125, 652 6.40625, -4.35546875, -5.8203125, 3.720703125, 653 -6.33203125, 8.578125, -6.765625, 6.43359375, 654 -9.7109375, 2.642578125, 5.21484375, 9.65625, 655 -8.71875, -0.453369140625, 9.9921875, -6.46875 656 ], 657 'descriptor': {shape: [4, 6], dataType: 'float16'} 658 } 659 }, 660 'operators': [{ 661 'name': 'linear', 662 'arguments': [{'input': 'linearInput'}], 663 'outputs': 'linearOutput' 664 }], 665 'expectedOutputs': { 666 'linearOutput': { 667 'data': [ 668 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 669 4.234375, 3.09765625, 3.74609375, -4.48828125, 670 6.40625, -4.35546875, -5.8203125, 3.720703125, 671 -6.33203125, 8.578125, -6.765625, 6.43359375, 672 -9.7109375, 2.642578125, 5.21484375, 9.65625, 673 -8.71875, -0.453369140625, 9.9921875, -6.46875 674 ], 675 'descriptor': {shape: [4, 6], dataType: 'float16'} 676 } 677 } 678 } 679 }, 680 { 681 'name': 'linear float16 3D tensor default options', 682 'graph': { 683 'inputs': { 684 'linearInput': { 685 'data': [ 686 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 687 4.234375, 3.09765625, 3.74609375, -4.48828125, 688 6.40625, -4.35546875, -5.8203125, 3.720703125, 689 -6.33203125, 8.578125, -6.765625, 6.43359375, 690 -9.7109375, 2.642578125, 5.21484375, 9.65625, 691 -8.71875, -0.453369140625, 9.9921875, -6.46875 692 ], 693 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 694 } 695 }, 696 'operators': [{ 697 'name': 'linear', 698 'arguments': [{'input': 'linearInput'}], 699 'outputs': 'linearOutput' 700 }], 701 'expectedOutputs': { 702 'linearOutput': { 703 'data': [ 704 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 705 4.234375, 3.09765625, 3.74609375, -4.48828125, 706 6.40625, -4.35546875, -5.8203125, 3.720703125, 707 -6.33203125, 8.578125, -6.765625, 6.43359375, 708 -9.7109375, 2.642578125, 5.21484375, 9.65625, 709 -8.71875, -0.453369140625, 9.9921875, -6.46875 710 ], 711 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 712 } 713 } 714 } 715 }, 716 { 717 'name': 'linear float16 4D tensor default options', 718 'graph': { 719 'inputs': { 720 'linearInput': { 721 'data': [ 722 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 723 4.234375, 3.09765625, 3.74609375, -4.48828125, 724 6.40625, -4.35546875, -5.8203125, 3.720703125, 725 -6.33203125, 8.578125, -6.765625, 6.43359375, 726 -9.7109375, 2.642578125, 5.21484375, 9.65625, 727 -8.71875, -0.453369140625, 9.9921875, -6.46875 728 ], 729 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 730 } 731 }, 732 'operators': [{ 733 'name': 'linear', 734 'arguments': [{'input': 'linearInput'}], 735 'outputs': 'linearOutput' 736 }], 737 'expectedOutputs': { 738 'linearOutput': { 739 'data': [ 740 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 741 4.234375, 3.09765625, 3.74609375, -4.48828125, 742 6.40625, -4.35546875, -5.8203125, 3.720703125, 743 -6.33203125, 8.578125, -6.765625, 6.43359375, 744 -9.7109375, 2.642578125, 5.21484375, 9.65625, 745 -8.71875, -0.453369140625, 9.9921875, -6.46875 746 ], 747 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 748 } 749 } 750 } 751 }, 752 { 753 'name': 'linear float16 5D tensor default options', 754 'graph': { 755 'inputs': { 756 'linearInput': { 757 'data': [ 758 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 759 4.234375, 3.09765625, 3.74609375, -4.48828125, 760 6.40625, -4.35546875, -5.8203125, 3.720703125, 761 -6.33203125, 8.578125, -6.765625, 6.43359375, 762 -9.7109375, 2.642578125, 5.21484375, 9.65625, 763 -8.71875, -0.453369140625, 9.9921875, -6.46875 764 ], 765 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 766 } 767 }, 768 'operators': [{ 769 'name': 'linear', 770 'arguments': [{'input': 'linearInput'}], 771 'outputs': 'linearOutput' 772 }], 773 'expectedOutputs': { 774 'linearOutput': { 775 'data': [ 776 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 777 4.234375, 3.09765625, 3.74609375, -4.48828125, 778 6.40625, -4.35546875, -5.8203125, 3.720703125, 779 -6.33203125, 8.578125, -6.765625, 6.43359375, 780 -9.7109375, 2.642578125, 5.21484375, 9.65625, 781 -8.71875, -0.453369140625, 9.9921875, -6.46875 782 ], 783 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 784 } 785 } 786 } 787 }, 788 { 789 'name': 790 'linear float16 4D tensor specified options.alpha and default options.beta', 791 'graph': { 792 'inputs': { 793 'linearInput': { 794 'data': [ 795 -1.1220703125, -6.60546875, -1.955078125, -4.59765625, 796 4.234375, 3.09765625, 3.74609375, -4.48828125, 797 6.40625, -4.35546875, -5.8203125, 3.720703125, 798 -6.33203125, 8.578125, -6.765625, 6.43359375, 799 -9.7109375, 2.642578125, 5.21484375, 9.65625, 800 -8.71875, -0.453369140625, 9.9921875, -6.46875 801 ], 802 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 803 } 804 }, 805 'operators': [{ 806 'name': 'linear', 807 'arguments': [ 808 {'input': 'linearInput'}, {'options': {'alpha': 7.398793812746618}} 809 ], 810 'outputs': 'linearOutput' 811 }], 812 'expectedOutputs': { 813 'linearOutput': { 814 'data': [ 815 -8.3046875, -48.875, -14.46875, -34.03125, 31.328125, 816 22.921875, 27.71875, -33.21875, 47.40625, -32.21875, 817 -43.0625, 27.53125, -46.84375, 63.46875, -50.0625, 818 47.59375, -71.875, 19.546875, 38.59375, 71.4375, 819 -64.5, -3.353515625, 73.9375, -47.875 820 ], 821 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 822 } 823 } 824 } 825 }, 826 { 827 'name': 828 'linear float16 positive 4D tensor specified positive options.beta and default options.alpha', 829 'graph': { 830 'inputs': { 831 'linearInput': { 832 'data': [ 833 5.09765625, 3.380859375, 8.0546875, 8.078125, 0.470703125, 834 5.2421875, 3.828125, 5.37109375, 6.1015625, 3.75, 835 0.748046875, 1.8935546875, 1.9052734375, 7.86328125, 4.58203125, 836 9.375, 6.5859375, 9.34375, 5.16015625, 0.80615234375, 837 9.1328125, 3.193359375, 5.75, 4.11328125 838 ], 839 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 840 } 841 }, 842 'operators': [{ 843 'name': 'linear', 844 'arguments': [ 845 {'input': 'linearInput'}, {'options': {'beta': 5.919095653700928}} 846 ], 847 'outputs': 'linearOutput' 848 }], 849 'expectedOutputs': { 850 'linearOutput': { 851 'data': [ 852 11.015625, 9.296875, 13.9765625, 14, 6.390625, 853 11.1640625, 9.75, 11.2890625, 12.0234375, 9.671875, 854 6.66796875, 7.8125, 7.82421875, 13.78125, 10.5, 855 15.296875, 12.5078125, 15.265625, 11.078125, 6.7265625, 856 15.0546875, 9.109375, 11.671875, 10.03125 857 ], 858 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 859 } 860 } 861 } 862 }, 863 { 864 'name': 865 'linear float16 negative 4D tensor specified negative options.beta and default options.alpha', 866 'graph': { 867 'inputs': { 868 'linearInput': { 869 'data': [ 870 -5.09765625, -3.380859375, -8.0546875, -8.078125, 871 -0.470703125, -5.2421875, -3.828125, -5.37109375, 872 -6.1015625, -3.75, -0.748046875, -1.8935546875, 873 -1.9052734375, -7.86328125, -4.58203125, -9.375, 874 -6.5859375, -9.34375, -5.16015625, -0.80615234375, 875 -9.1328125, -3.193359375, -5.75, -4.11328125 876 ], 877 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 878 } 879 }, 880 'operators': [{ 881 'name': 'linear', 882 'arguments': [ 883 {'input': 'linearInput'}, {'options': {'beta': -5.919095653700928}} 884 ], 885 'outputs': 'linearOutput' 886 }], 887 'expectedOutputs': { 888 'linearOutput': { 889 'data': [ 890 -11.015625, -9.296875, -13.9765625, -14, -6.390625, 891 -11.1640625, -9.75, -11.2890625, -12.0234375, -9.671875, 892 -6.66796875, -7.8125, -7.82421875, -13.78125, -10.5, 893 -15.296875, -12.5078125, -15.265625, -11.078125, -6.7265625, 894 -15.0546875, -9.109375, -11.671875, -10.03125 895 ], 896 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 897 } 898 } 899 } 900 }, 901 { 902 'name': 903 'linear float16 positive 4D tensor all options (positive options.alpha and positive options.beta)', 904 'graph': { 905 'inputs': { 906 'linearInput': { 907 'data': [ 908 5.09765625, 3.380859375, 8.0546875, 8.078125, 0.470703125, 909 5.2421875, 3.828125, 5.37109375, 6.1015625, 3.75, 910 0.748046875, 1.8935546875, 1.9052734375, 7.86328125, 4.58203125, 911 9.375, 6.5859375, 9.34375, 5.16015625, 0.80615234375, 912 9.1328125, 3.193359375, 5.75, 4.11328125 913 ], 914 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 915 } 916 }, 917 'operators': [{ 918 'name': 'linear', 919 'arguments': [ 920 {'input': 'linearInput'}, 921 {'options': {'alpha': 7.398793812746618, 'beta': 5.919095653700928}} 922 ], 923 'outputs': 'linearOutput' 924 }], 925 'expectedOutputs': { 926 'linearOutput': { 927 'data': [ 928 43.625, 30.9375, 65.5, 65.6875, 9.3984375, 44.71875, 929 34.25, 45.65625, 51.0625, 33.65625, 11.453125, 19.921875, 930 20.015625, 64.125, 39.8125, 75.3125, 54.65625, 75.0625, 931 44.09375, 11.8828125, 73.5, 29.546875, 48.46875, 36.34375 932 ], 933 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 934 } 935 } 936 } 937 }, 938 { 939 'name': 940 'linear float16 positive 4D tensor all options (negative options.alpha and negative options.beta)', 941 'graph': { 942 'inputs': { 943 'linearInput': { 944 'data': [ 945 5.09765625, 3.380859375, 8.0546875, 8.078125, 0.470703125, 946 5.2421875, 3.828125, 5.37109375, 6.1015625, 3.75, 947 0.748046875, 1.8935546875, 1.9052734375, 7.86328125, 4.58203125, 948 9.375, 6.5859375, 9.34375, 5.16015625, 0.80615234375, 949 9.1328125, 3.193359375, 5.75, 4.11328125 950 ], 951 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 952 } 953 }, 954 'operators': [{ 955 'name': 'linear', 956 'arguments': [ 957 {'input': 'linearInput'}, 958 {'options': {'alpha': -7.398793812746618, 'beta': -5.919095653700928}} 959 ], 960 'outputs': 'linearOutput' 961 }], 962 'expectedOutputs': { 963 'linearOutput': { 964 'data': [ 965 -43.625, -30.9375, -65.5, -65.6875, -9.3984375, 966 -44.71875, -34.25, -45.65625, -51.0625, -33.65625, 967 -11.453125, -19.921875, -20.015625, -64.125, -39.8125, 968 -75.3125, -54.65625, -75.0625, -44.09375, -11.8828125, 969 -73.5, -29.546875, -48.46875, -36.34375 970 ], 971 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 972 } 973 } 974 } 975 }, 976 { 977 'name': 978 'linear float16 negative 4D tensor all options (positive options.alpha and negative options.beta)', 979 'graph': { 980 'inputs': { 981 'linearInput': { 982 'data': [ 983 -5.09765625, -3.380859375, -8.0546875, -8.078125, 984 -0.470703125, -5.2421875, -3.828125, -5.37109375, 985 -6.1015625, -3.75, -0.748046875, -1.8935546875, 986 -1.9052734375, -7.86328125, -4.58203125, -9.375, 987 -6.5859375, -9.34375, -5.16015625, -0.80615234375, 988 -9.1328125, -3.193359375, -5.75, -4.11328125 989 ], 990 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 991 } 992 }, 993 'operators': [{ 994 'name': 'linear', 995 'arguments': [ 996 {'input': 'linearInput'}, 997 {'options': {'alpha': 7.398793812746618, 'beta': -5.919095653700928}} 998 ], 999 'outputs': 'linearOutput' 1000 }], 1001 'expectedOutputs': { 1002 'linearOutput': { 1003 'data': [ 1004 -43.625, -30.9375, -65.5, -65.6875, -9.3984375, 1005 -44.71875, -34.25, -45.65625, -51.0625, -33.65625, 1006 -11.453125, -19.921875, -20.015625, -64.125, -39.8125, 1007 -75.3125, -54.65625, -75.0625, -44.09375, -11.8828125, 1008 -73.5, -29.546875, -48.46875, -36.34375 1009 ], 1010 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 1011 } 1012 } 1013 } 1014 } 1015 ]; 1016 1017 webnn_conformance_test( 1018 linearTests, buildAndExecuteGraph, getPrecisionTolerance);