tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

reverse.https.any.js (8752B)


      1 // META: title=test WebNN API reverse 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-reverse-method
     12 // Reverse the order of the input tensor along specified axes.
     13 //
     14 // dictionary MLReverseOptions : MLOperatorOptions {
     15 //   sequence<[EnforceRange] unsigned long> axes;
     16 // };
     17 //
     18 // MLOperand reverse(MLOperand input, optional MLReverseOptions options = {});
     19 
     20 const reverseTests = [
     21  {
     22    'name': 'reverse float32 2D input with default options',
     23    'graph': {
     24      'inputs': {
     25        'reverseInput': {
     26          'data': [
     27            -30.0561466217041, 99.56941986083984, 88.04620361328125,
     28            -91.87507629394531, -23.7972354888916, -91.28665161132812,
     29            -63.15204620361328, 12.0669527053833, -96.1172866821289,
     30            -44.77365493774414, -80.08650970458984, -64.43756866455078
     31          ],
     32          'descriptor': {shape: [3, 4], dataType: 'float32'}
     33        }
     34      },
     35      'operators': [{
     36        'name': 'reverse',
     37        'arguments': [{'input': 'reverseInput'}],
     38        'outputs': 'reverseOutput'
     39      }],
     40      'expectedOutputs': {
     41        'reverseOutput': {
     42          'data': [
     43            -64.43756866455078, -80.08650970458984, -44.77365493774414,
     44            -96.1172866821289, 12.0669527053833, -63.15204620361328,
     45            -91.28665161132812, -23.7972354888916, -91.87507629394531,
     46            88.04620361328125, 99.56941986083984, -30.0561466217041
     47          ],
     48          'descriptor': {shape: [3, 4], dataType: 'float32'}
     49        }
     50      }
     51    }
     52  },
     53  {
     54    'name': 'reverse float32 3D input options.axes=[1, 2]',
     55    'graph': {
     56      'inputs': {
     57        'reverseInput': {
     58          'data': [
     59            -30.0561466217041, 99.56941986083984, 88.04620361328125,
     60            -91.87507629394531, -23.7972354888916, -91.28665161132812,
     61            -63.15204620361328, 12.0669527053833, -96.1172866821289,
     62            -44.77365493774414, -80.08650970458984, -64.43756866455078
     63          ],
     64          'descriptor': {shape: [3, 2, 2], dataType: 'float32'}
     65        }
     66      },
     67      'operators': [{
     68        'name': 'reverse',
     69        'arguments': [{'input': 'reverseInput'}, {'options': {'axes': [1, 2]}}],
     70        'outputs': 'reverseOutput'
     71      }],
     72      'expectedOutputs': {
     73        'reverseOutput': {
     74          'data': [
     75            -91.87507629394531, 88.04620361328125, 99.56941986083984,
     76            -30.0561466217041, 12.0669527053833, -63.15204620361328,
     77            -91.28665161132812, -23.7972354888916, -64.43756866455078,
     78            -80.08650970458984, -44.77365493774414, -96.1172866821289
     79          ],
     80          'descriptor': {shape: [3, 2, 2], dataType: 'float32'}
     81        }
     82      }
     83    }
     84  },
     85  {
     86    'name': 'reverse float32 4D input options.axes=[3, 1]',
     87    'graph': {
     88      'inputs': {
     89        'reverseInput': {
     90          'data': [
     91            -30.0561466217041, 99.56941986083984, 88.04620361328125,
     92            -91.87507629394531, -23.7972354888916, -91.28665161132812,
     93            -63.15204620361328, 12.0669527053833, -96.1172866821289,
     94            -44.77365493774414, -80.08650970458984, -64.43756866455078
     95          ],
     96          'descriptor': {shape: [3, 2, 1, 2], dataType: 'float32'}
     97        }
     98      },
     99      'operators': [{
    100        'name': 'reverse',
    101        'arguments': [{'input': 'reverseInput'}, {'options': {'axes': [3, 1]}}],
    102        'outputs': 'reverseOutput'
    103      }],
    104      'expectedOutputs': {
    105        'reverseOutput': {
    106          'data': [
    107            -91.87507629394531, 88.04620361328125, 99.56941986083984,
    108            -30.0561466217041, 12.0669527053833, -63.15204620361328,
    109            -91.28665161132812, -23.7972354888916, -64.43756866455078,
    110            -80.08650970458984, -44.77365493774414, -96.1172866821289
    111          ],
    112          'descriptor': {shape: [3, 2, 1, 2], dataType: 'float32'}
    113        }
    114      }
    115    }
    116  },
    117  {
    118    'name': 'reverse float32 4D input options.axes=[]',
    119    'graph': {
    120      'inputs': {
    121        'reverseInput': {
    122          'data': [
    123            -30.0561466217041, 99.56941986083984, 88.04620361328125,
    124            -91.87507629394531, -23.7972354888916, -91.28665161132812,
    125            -63.15204620361328, 12.0669527053833, -96.1172866821289,
    126            -44.77365493774414, -80.08650970458984, -64.43756866455078
    127          ],
    128          'descriptor': {shape: [2, 1, 2, 3], dataType: 'float32'}
    129        }
    130      },
    131      'operators': [{
    132        'name': 'reverse',
    133        'arguments': [{'input': 'reverseInput'}, {'options': {'axes': []}}],
    134        'outputs': 'reverseOutput'
    135      }],
    136      'expectedOutputs': {
    137        'reverseOutput': {
    138          'data': [
    139            -30.0561466217041, 99.56941986083984, 88.04620361328125,
    140            -91.87507629394531, -23.7972354888916, -91.28665161132812,
    141            -63.15204620361328, 12.0669527053833, -96.1172866821289,
    142            -44.77365493774414, -80.08650970458984, -64.43756866455078
    143          ],
    144          'descriptor': {shape: [2, 1, 2, 3], dataType: 'float32'}
    145        }
    146      }
    147    }
    148  },
    149 
    150  // float16 tests
    151  {
    152    'name': 'reverse float16 2D input with default options',
    153    'graph': {
    154      'inputs': {
    155        'reverseInput': {
    156          'data': [
    157            -30.0625, 99.5625, 88.0625, -91.875, -23.796875, -91.3125,
    158            -63.15625, 12.0703125, -96.125, -44.78125, -80.0625, -64.4375
    159          ],
    160          'descriptor': {shape: [3, 4], dataType: 'float16'}
    161        }
    162      },
    163      'operators': [{
    164        'name': 'reverse',
    165        'arguments': [{'input': 'reverseInput'}],
    166        'outputs': 'reverseOutput'
    167      }],
    168      'expectedOutputs': {
    169        'reverseOutput': {
    170          'data': [
    171            -64.4375, -80.0625, -44.78125, -96.125, 12.0703125, -63.15625,
    172            -91.3125, -23.796875, -91.875, 88.0625, 99.5625, -30.0625
    173          ],
    174          'descriptor': {shape: [3, 4], dataType: 'float16'}
    175        }
    176      }
    177    }
    178  },
    179  {
    180    'name': 'reverse float16 3D input options.axes=[1, 2]',
    181    'graph': {
    182      'inputs': {
    183        'reverseInput': {
    184          'data': [
    185            -30.0625, 99.5625, 88.0625, -91.875, -23.796875, -91.3125,
    186            -63.15625, 12.0703125, -96.125, -44.78125, -80.0625, -64.4375
    187          ],
    188          'descriptor': {shape: [3, 2, 2], dataType: 'float16'}
    189        }
    190      },
    191      'operators': [{
    192        'name': 'reverse',
    193        'arguments': [{'input': 'reverseInput'}, {'options': {'axes': [1, 2]}}],
    194        'outputs': 'reverseOutput'
    195      }],
    196      'expectedOutputs': {
    197        'reverseOutput': {
    198          'data': [
    199            -91.875, 88.0625, 99.5625, -30.0625, 12.0703125, -63.15625,
    200            -91.3125, -23.796875, -64.4375, -80.0625, -44.78125, -96.125
    201          ],
    202          'descriptor': {shape: [3, 2, 2], dataType: 'float16'}
    203        }
    204      }
    205    }
    206  },
    207  {
    208    'name': 'reverse float16 4D input options.axes=[3, 1]',
    209    'graph': {
    210      'inputs': {
    211        'reverseInput': {
    212          'data': [
    213            -30.0625, 99.5625, 88.0625, -91.875, -23.796875, -91.3125,
    214            -63.15625, 12.0703125, -96.125, -44.78125, -80.0625, -64.4375
    215          ],
    216          'descriptor': {shape: [3, 2, 1, 2], dataType: 'float16'}
    217        }
    218      },
    219      'operators': [{
    220        'name': 'reverse',
    221        'arguments': [{'input': 'reverseInput'}, {'options': {'axes': [3, 1]}}],
    222        'outputs': 'reverseOutput'
    223      }],
    224      'expectedOutputs': {
    225        'reverseOutput': {
    226          'data': [
    227            -91.875, 88.0625, 99.5625, -30.0625, 12.0703125, -63.15625,
    228            -91.3125, -23.796875, -64.4375, -80.0625, -44.78125, -96.125
    229          ],
    230          'descriptor': {shape: [3, 2, 1, 2], dataType: 'float16'}
    231        }
    232      }
    233    }
    234  },
    235  {
    236    'name': 'reverse float16 4D input options.axes=[]',
    237    'graph': {
    238      'inputs': {
    239        'reverseInput': {
    240          'data': [
    241            -30.0625, 99.5625, 88.0625, -91.875, -23.796875, -91.3125,
    242            -63.15625, 12.0703125, -96.125, -44.78125, -80.0625, -64.4375
    243          ],
    244          'descriptor': {shape: [2, 1, 2, 3], dataType: 'float16'}
    245        }
    246      },
    247      'operators': [{
    248        'name': 'reverse',
    249        'arguments': [{'input': 'reverseInput'}, {'options': {'axes': []}}],
    250        'outputs': 'reverseOutput'
    251      }],
    252      'expectedOutputs': {
    253        'reverseOutput': {
    254          'data': [
    255            -30.0625, 99.5625, 88.0625, -91.875, -23.796875, -91.3125,
    256            -63.15625, 12.0703125, -96.125, -44.78125, -80.0625, -64.4375
    257          ],
    258          'descriptor': {shape: [2, 1, 2, 3], dataType: 'float16'}
    259        }
    260      }
    261    }
    262  }
    263 ];
    264 
    265 webnn_conformance_test(reverseTests, buildAndExecuteGraph, getZeroULPTolerance);