floor.https.any.js (15365B)
1 // META: title=test WebNN API element-wise floor 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 floor of the input tensor, element-wise. 13 // 14 // MLOperand floor(MLOperand input); 15 16 17 const getFloorPrecisionTolerance = (graphResources) => { 18 const toleranceValueDict = {float32: 0, float16: 0}; 19 const expectedDataType = 20 getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs); 21 return {metricType: 'ULP', value: toleranceValueDict[expectedDataType]}; 22 }; 23 24 const floorTests = [ 25 { 26 'name': 'floor float32 0D scalar', 27 'graph': { 28 'inputs': { 29 'floorInput': { 30 'data': [89.69458770751953], 31 'descriptor': {shape: [], dataType: 'float32'} 32 } 33 }, 34 'operators': [{ 35 'name': 'floor', 36 'arguments': [{'input': 'floorInput'}], 37 'outputs': 'floorOutput' 38 }], 39 'expectedOutputs': { 40 'floorOutput': 41 {'data': [89], 'descriptor': {shape: [], dataType: 'float32'}} 42 } 43 } 44 }, 45 { 46 'name': 'floor float32 1D constant tensor', 47 'graph': { 48 'inputs': { 49 'floorInput': { 50 'data': [ 51 89.69458770751953, -79.67150115966797, -66.80949401855469, 52 -71.88439178466797, 86.33935546875, 6.823808670043945, 53 24.908447265625, 0.9734055399894714, 19.948184967041016, 54 0.8437776565551758, -24.752939224243164, 77.76482391357422, 55 -33.644466400146484, 80.7762451171875, 44.47844314575195, 56 -37.65005874633789, -83.78780364990234, 65.840087890625, 57 -39.83677673339844, 32.5257568359375, -21.213542938232422, 58 -80.30911254882812, 16.674850463867188, -72.88893127441406 59 ], 60 'descriptor': {shape: [24], dataType: 'float32'}, 61 'constant': true 62 } 63 }, 64 'operators': [{ 65 'name': 'floor', 66 'arguments': [{'input': 'floorInput'}], 67 'outputs': 'floorOutput' 68 }], 69 'expectedOutputs': { 70 'floorOutput': { 71 'data': [ 72 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 73 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 74 ], 75 'descriptor': {shape: [24], dataType: 'float32'} 76 } 77 } 78 } 79 }, 80 { 81 'name': 'floor float32 1D tensor', 82 'graph': { 83 'inputs': { 84 'floorInput': { 85 'data': [ 86 89.69458770751953, -79.67150115966797, -66.80949401855469, 87 -71.88439178466797, 86.33935546875, 6.823808670043945, 88 24.908447265625, 0.9734055399894714, 19.948184967041016, 89 0.8437776565551758, -24.752939224243164, 77.76482391357422, 90 -33.644466400146484, 80.7762451171875, 44.47844314575195, 91 -37.65005874633789, -83.78780364990234, 65.840087890625, 92 -39.83677673339844, 32.5257568359375, -21.213542938232422, 93 -80.30911254882812, 16.674850463867188, -72.88893127441406 94 ], 95 'descriptor': {shape: [24], dataType: 'float32'} 96 } 97 }, 98 'operators': [{ 99 'name': 'floor', 100 'arguments': [{'input': 'floorInput'}], 101 'outputs': 'floorOutput' 102 }], 103 'expectedOutputs': { 104 'floorOutput': { 105 'data': [ 106 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 107 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 108 ], 109 'descriptor': {shape: [24], dataType: 'float32'} 110 } 111 } 112 } 113 }, 114 { 115 'name': 'floor float32 2D tensor', 116 'graph': { 117 'inputs': { 118 'floorInput': { 119 'data': [ 120 89.69458770751953, -79.67150115966797, -66.80949401855469, 121 -71.88439178466797, 86.33935546875, 6.823808670043945, 122 24.908447265625, 0.9734055399894714, 19.948184967041016, 123 0.8437776565551758, -24.752939224243164, 77.76482391357422, 124 -33.644466400146484, 80.7762451171875, 44.47844314575195, 125 -37.65005874633789, -83.78780364990234, 65.840087890625, 126 -39.83677673339844, 32.5257568359375, -21.213542938232422, 127 -80.30911254882812, 16.674850463867188, -72.88893127441406 128 ], 129 'descriptor': {shape: [4, 6], dataType: 'float32'} 130 } 131 }, 132 'operators': [{ 133 'name': 'floor', 134 'arguments': [{'input': 'floorInput'}], 135 'outputs': 'floorOutput' 136 }], 137 'expectedOutputs': { 138 'floorOutput': { 139 'data': [ 140 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 141 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 142 ], 143 'descriptor': {shape: [4, 6], dataType: 'float32'} 144 } 145 } 146 } 147 }, 148 { 149 'name': 'floor float32 3D tensor', 150 'graph': { 151 'inputs': { 152 'floorInput': { 153 'data': [ 154 89.69458770751953, -79.67150115966797, -66.80949401855469, 155 -71.88439178466797, 86.33935546875, 6.823808670043945, 156 24.908447265625, 0.9734055399894714, 19.948184967041016, 157 0.8437776565551758, -24.752939224243164, 77.76482391357422, 158 -33.644466400146484, 80.7762451171875, 44.47844314575195, 159 -37.65005874633789, -83.78780364990234, 65.840087890625, 160 -39.83677673339844, 32.5257568359375, -21.213542938232422, 161 -80.30911254882812, 16.674850463867188, -72.88893127441406 162 ], 163 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 164 } 165 }, 166 'operators': [{ 167 'name': 'floor', 168 'arguments': [{'input': 'floorInput'}], 169 'outputs': 'floorOutput' 170 }], 171 'expectedOutputs': { 172 'floorOutput': { 173 'data': [ 174 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 175 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 176 ], 177 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 178 } 179 } 180 } 181 }, 182 { 183 'name': 'floor float32 4D tensor', 184 'graph': { 185 'inputs': { 186 'floorInput': { 187 'data': [ 188 89.69458770751953, -79.67150115966797, -66.80949401855469, 189 -71.88439178466797, 86.33935546875, 6.823808670043945, 190 24.908447265625, 0.9734055399894714, 19.948184967041016, 191 0.8437776565551758, -24.752939224243164, 77.76482391357422, 192 -33.644466400146484, 80.7762451171875, 44.47844314575195, 193 -37.65005874633789, -83.78780364990234, 65.840087890625, 194 -39.83677673339844, 32.5257568359375, -21.213542938232422, 195 -80.30911254882812, 16.674850463867188, -72.88893127441406 196 ], 197 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 198 } 199 }, 200 'operators': [{ 201 'name': 'floor', 202 'arguments': [{'input': 'floorInput'}], 203 'outputs': 'floorOutput' 204 }], 205 'expectedOutputs': { 206 'floorOutput': { 207 'data': [ 208 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 209 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 210 ], 211 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 212 } 213 } 214 } 215 }, 216 { 217 'name': 'floor float32 5D tensor', 218 'graph': { 219 'inputs': { 220 'floorInput': { 221 'data': [ 222 89.69458770751953, -79.67150115966797, -66.80949401855469, 223 -71.88439178466797, 86.33935546875, 6.823808670043945, 224 24.908447265625, 0.9734055399894714, 19.948184967041016, 225 0.8437776565551758, -24.752939224243164, 77.76482391357422, 226 -33.644466400146484, 80.7762451171875, 44.47844314575195, 227 -37.65005874633789, -83.78780364990234, 65.840087890625, 228 -39.83677673339844, 32.5257568359375, -21.213542938232422, 229 -80.30911254882812, 16.674850463867188, -72.88893127441406 230 ], 231 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 232 } 233 }, 234 'operators': [{ 235 'name': 'floor', 236 'arguments': [{'input': 'floorInput'}], 237 'outputs': 'floorOutput' 238 }], 239 'expectedOutputs': { 240 'floorOutput': { 241 'data': [ 242 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 243 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 244 ], 245 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 246 } 247 } 248 } 249 }, 250 251 // float16 tests 252 { 253 'name': 'floor float16 0D scalar', 254 'graph': { 255 'inputs': { 256 'floorInput': 257 {'data': [89.6875], 'descriptor': {shape: [], dataType: 'float16'}} 258 }, 259 'operators': [{ 260 'name': 'floor', 261 'arguments': [{'input': 'floorInput'}], 262 'outputs': 'floorOutput' 263 }], 264 'expectedOutputs': { 265 'floorOutput': 266 {'data': [89], 'descriptor': {shape: [], dataType: 'float16'}} 267 } 268 } 269 }, 270 { 271 'name': 'floor float16 1D constant tensor', 272 'graph': { 273 'inputs': { 274 'floorInput': { 275 'data': [ 276 89.6875, -79.6875, -66.8125, -71.875, 86.3125, 277 6.82421875, 24.90625, 0.9736328125, 19.953125, 0.84375, 278 -24.75, 77.75, -33.65625, 80.75, 44.46875, 279 -37.65625, -83.8125, 65.8125, -39.84375, 32.53125, 280 -21.21875, -80.3125, 16.671875, -72.875 281 ], 282 'descriptor': {shape: [24], dataType: 'float16'}, 283 'constant': true 284 } 285 }, 286 'operators': [{ 287 'name': 'floor', 288 'arguments': [{'input': 'floorInput'}], 289 'outputs': 'floorOutput' 290 }], 291 'expectedOutputs': { 292 'floorOutput': { 293 'data': [ 294 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 295 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 296 ], 297 'descriptor': {shape: [24], dataType: 'float16'} 298 } 299 } 300 } 301 }, 302 { 303 'name': 'floor float16 1D tensor', 304 'graph': { 305 'inputs': { 306 'floorInput': { 307 'data': [ 308 89.6875, -79.6875, -66.8125, -71.875, 86.3125, 309 6.82421875, 24.90625, 0.9736328125, 19.953125, 0.84375, 310 -24.75, 77.75, -33.65625, 80.75, 44.46875, 311 -37.65625, -83.8125, 65.8125, -39.84375, 32.53125, 312 -21.21875, -80.3125, 16.671875, -72.875 313 ], 314 'descriptor': {shape: [24], dataType: 'float16'} 315 } 316 }, 317 'operators': [{ 318 'name': 'floor', 319 'arguments': [{'input': 'floorInput'}], 320 'outputs': 'floorOutput' 321 }], 322 'expectedOutputs': { 323 'floorOutput': { 324 'data': [ 325 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 326 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 327 ], 328 'descriptor': {shape: [24], dataType: 'float16'} 329 } 330 } 331 } 332 }, 333 { 334 'name': 'floor float16 2D tensor', 335 'graph': { 336 'inputs': { 337 'floorInput': { 338 'data': [ 339 89.6875, -79.6875, -66.8125, -71.875, 86.3125, 340 6.82421875, 24.90625, 0.9736328125, 19.953125, 0.84375, 341 -24.75, 77.75, -33.65625, 80.75, 44.46875, 342 -37.65625, -83.8125, 65.8125, -39.84375, 32.53125, 343 -21.21875, -80.3125, 16.671875, -72.875 344 ], 345 'descriptor': {shape: [4, 6], dataType: 'float16'} 346 } 347 }, 348 'operators': [{ 349 'name': 'floor', 350 'arguments': [{'input': 'floorInput'}], 351 'outputs': 'floorOutput' 352 }], 353 'expectedOutputs': { 354 'floorOutput': { 355 'data': [ 356 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 357 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 358 ], 359 'descriptor': {shape: [4, 6], dataType: 'float16'} 360 } 361 } 362 } 363 }, 364 { 365 'name': 'floor float16 3D tensor', 366 'graph': { 367 'inputs': { 368 'floorInput': { 369 'data': [ 370 89.6875, -79.6875, -66.8125, -71.875, 86.3125, 371 6.82421875, 24.90625, 0.9736328125, 19.953125, 0.84375, 372 -24.75, 77.75, -33.65625, 80.75, 44.46875, 373 -37.65625, -83.8125, 65.8125, -39.84375, 32.53125, 374 -21.21875, -80.3125, 16.671875, -72.875 375 ], 376 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 377 } 378 }, 379 'operators': [{ 380 'name': 'floor', 381 'arguments': [{'input': 'floorInput'}], 382 'outputs': 'floorOutput' 383 }], 384 'expectedOutputs': { 385 'floorOutput': { 386 'data': [ 387 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 388 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 389 ], 390 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 391 } 392 } 393 } 394 }, 395 { 396 'name': 'floor float16 4D tensor', 397 'graph': { 398 'inputs': { 399 'floorInput': { 400 'data': [ 401 89.6875, -79.6875, -66.8125, -71.875, 86.3125, 402 6.82421875, 24.90625, 0.9736328125, 19.953125, 0.84375, 403 -24.75, 77.75, -33.65625, 80.75, 44.46875, 404 -37.65625, -83.8125, 65.8125, -39.84375, 32.53125, 405 -21.21875, -80.3125, 16.671875, -72.875 406 ], 407 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 408 } 409 }, 410 'operators': [{ 411 'name': 'floor', 412 'arguments': [{'input': 'floorInput'}], 413 'outputs': 'floorOutput' 414 }], 415 'expectedOutputs': { 416 'floorOutput': { 417 'data': [ 418 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 419 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 420 ], 421 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 422 } 423 } 424 } 425 }, 426 { 427 'name': 'floor float16 5D tensor', 428 'graph': { 429 'inputs': { 430 'floorInput': { 431 'data': [ 432 89.6875, -79.6875, -66.8125, -71.875, 86.3125, 433 6.82421875, 24.90625, 0.9736328125, 19.953125, 0.84375, 434 -24.75, 77.75, -33.65625, 80.75, 44.46875, 435 -37.65625, -83.8125, 65.8125, -39.84375, 32.53125, 436 -21.21875, -80.3125, 16.671875, -72.875 437 ], 438 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 439 } 440 }, 441 'operators': [{ 442 'name': 'floor', 443 'arguments': [{'input': 'floorInput'}], 444 'outputs': 'floorOutput' 445 }], 446 'expectedOutputs': { 447 'floorOutput': { 448 'data': [ 449 89, -80, -67, -72, 86, 6, 24, 0, 19, 0, -25, 77, 450 -34, 80, 44, -38, -84, 65, -40, 32, -22, -81, 16, -73 451 ], 452 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 453 } 454 } 455 } 456 } 457 ]; 458 459 webnn_conformance_test( 460 floorTests, buildAndExecuteGraph, getFloorPrecisionTolerance);