tor-browser

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

mlNumber.https.any.js (7001B)


      1 // META: title=test WebNN MLNumber
      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-mlnumber-typedef
     12 
     13 const getClampPrecisionTolerance = () => {
     14  return {metricType: 'ULP', value: 0};
     15 };
     16 
     17 const mlNumberTests = [
     18  {
     19    'name': 'cast BigInt to int64',
     20    'graph': {
     21      'inputs': {
     22        'clampInput': {
     23          'data': [-21474836470, 21474836470, -2, 1, 0],
     24          'descriptor': {shape: [5], dataType: 'int64'},
     25          'constant': true
     26        }
     27      },
     28      'operators': [{
     29        'name': 'clamp',
     30        'arguments': [{'input': 'clampInput'}, {'options': {'minValue': -2n}}],
     31        'outputs': 'clampOutput'
     32      }],
     33      'expectedOutputs': {
     34        'clampOutput': {
     35          'data': [-2, 21474836470, -2, 1, 0],
     36          'descriptor': {shape: [5], dataType: 'int64'}
     37        }
     38      }
     39    }
     40  },
     41  {
     42    'name': 'cast BigInt to int64 overflow',
     43    'graph': {
     44      'inputs': {
     45        'clampInput': {
     46          'data': [-21474836470, 21474836470, -2, 1, 0],
     47          'descriptor': {shape: [5], dataType: 'int64'},
     48          'constant': true
     49        }
     50      },
     51      'operators': [{
     52        'name': 'clamp',
     53        'arguments': [
     54          {'input': 'clampInput'},
     55          {'options': {'minValue': 9223372036854775820n}}
     56        ],
     57        'outputs': 'clampOutput'
     58      }],
     59      'expectedOutputs': {
     60        'clampOutput': {
     61          'data': [
     62            9223372036854775807n, 9223372036854775807n, 9223372036854775807n,
     63            9223372036854775807n, 9223372036854775807n
     64          ],
     65          'descriptor': {shape: [5], dataType: 'int64'}
     66        }
     67      }
     68    }
     69  },
     70  {
     71    'name': 'cast BigInt to int64 underflow',
     72    'graph': {
     73      'inputs': {
     74        'clampInput': {
     75          'data': [-21474836470, 21474836470, -2, 1, 0],
     76          'descriptor': {shape: [5], dataType: 'int64'},
     77          'constant': true
     78        }
     79      },
     80      'operators': [{
     81        'name': 'clamp',
     82        'arguments': [
     83          {'input': 'clampInput'},
     84          {'options': {'maxValue': -9223372036854775820n}}
     85        ],
     86        'outputs': 'clampOutput'
     87      }],
     88      'expectedOutputs': {
     89        'clampOutput': {
     90          'data': [
     91            -9223372036854775808, -9223372036854775808, -9223372036854775808,
     92            -9223372036854775808, -9223372036854775808
     93          ],
     94          'descriptor': {shape: [5], dataType: 'int64'}
     95        }
     96      }
     97    }
     98  },
     99  {
    100    'name': 'cast BigInt to uint64',
    101    'graph': {
    102      'inputs': {
    103        'clampInput': {
    104          'data': [42949672950, 127, 5, 0],
    105          'descriptor': {shape: [4], dataType: 'uint64'},
    106          'constant': true
    107        }
    108      },
    109      'operators': [{
    110        'name': 'clamp',
    111        'arguments': [{'input': 'clampInput'}, {'options': {'minValue': 5n}}],
    112        'outputs': 'clampOutput'
    113      }],
    114      'expectedOutputs': {
    115        'clampOutput': {
    116          'data': [42949672950, 127, 5, 5],
    117          'descriptor': {shape: [4], dataType: 'uint64'}
    118        }
    119      }
    120    }
    121  },
    122  {
    123    'name': 'cast BigInt to uint64 overflow',
    124    'graph': {
    125      'inputs': {
    126        'clampInput': {
    127          'data': [42949672950, 127, 5, 0],
    128          'descriptor': {shape: [4], dataType: 'uint64'},
    129          'constant': true
    130        }
    131      },
    132      'operators': [{
    133        'name': 'clamp',
    134        'arguments': [
    135          {'input': 'clampInput'},
    136          {'options': {'minValue': 184467440737095511615n}}
    137        ],
    138        'outputs': 'clampOutput'
    139      }],
    140      'expectedOutputs': {
    141        'clampOutput': {
    142          'data': [
    143            18446744073709551615n, 18446744073709551615n, 18446744073709551615n,
    144            18446744073709551615n
    145          ],
    146          'descriptor': {shape: [4], dataType: 'uint64'}
    147        }
    148      }
    149    }
    150  },
    151  {
    152    'name': 'cast BigInt to uint64 underflow',
    153    'graph': {
    154      'inputs': {
    155        'clampInput': {
    156          'data': [42949672950, 127, 5, 0],
    157          'descriptor': {shape: [4], dataType: 'uint64'},
    158          'constant': true
    159        }
    160      },
    161      'operators': [{
    162        'name': 'clamp',
    163        'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': -1n}}],
    164        'outputs': 'clampOutput'
    165      }],
    166      'expectedOutputs': {
    167        'clampOutput': {
    168          'data': [0, 0, 0, 0],
    169          'descriptor': {shape: [4], dataType: 'uint64'}
    170        }
    171      }
    172    }
    173  },
    174  {
    175    'name': 'cast float to integer',
    176    'graph': {
    177      'inputs': {
    178        'clampInput': {
    179          'data': [129, 4294967295, 127, 1, 0],
    180          'descriptor': {shape: [5], dataType: 'uint64'},
    181          'constant': true
    182        }
    183      },
    184      'operators': [{
    185        'name': 'clamp',
    186        'arguments':
    187            [{'input': 'clampInput'}, {'options': {'maxValue': 128.0}}],
    188        'outputs': 'clampOutput'
    189      }],
    190      'expectedOutputs': {
    191        'clampOutput': {
    192          'data': [128, 128, 127, 1, 0],
    193          'descriptor': {shape: [5], dataType: 'uint64'}
    194        }
    195      }
    196    }
    197  },
    198  {
    199    'name': 'cast float to integer overflows',
    200    'graph': {
    201      'inputs': {
    202        'clampInput': {
    203          'data': [255, 127, 5, 0],
    204          'descriptor': {shape: [4], dataType: 'uint8'},
    205          'constant': true
    206        }
    207      },
    208      'operators': [{
    209        'name': 'clamp',
    210        'arguments':
    211            [{'input': 'clampInput'}, {'options': {'minValue': 1000.0}}],
    212        'outputs': 'clampOutput'
    213      }],
    214      'expectedOutputs': {
    215        'clampOutput': {
    216          'data': [255, 255, 255, 255],
    217          'descriptor': {shape: [4], dataType: 'uint8'}
    218        }
    219      }
    220    }
    221  },
    222  {
    223    'name': 'cast float to integer underflows',
    224    'graph': {
    225      'inputs': {
    226        'clampInput': {
    227          'data': [255, 127, 5, 0],
    228          'descriptor': {shape: [4], dataType: 'uint8'},
    229          'constant': true
    230        }
    231      },
    232      'operators': [{
    233        'name': 'clamp',
    234        'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': -1.0}}],
    235        'outputs': 'clampOutput'
    236      }],
    237      'expectedOutputs': {
    238        'clampOutput': {
    239          'data': [0, 0, 0, 0],
    240          'descriptor': {shape: [4], dataType: 'uint8'}
    241        }
    242      }
    243    }
    244  },
    245  {
    246    'name': 'cast fractional float to integer',
    247    'graph': {
    248      'inputs': {
    249        'clampInput': {
    250          'data': [3, 4, 5, -1, 0],
    251          'descriptor': {shape: [5], dataType: 'int64'},
    252          'constant': true
    253        }
    254      },
    255      'operators': [{
    256        'name': 'clamp',
    257        'arguments': [{'input': 'clampInput'}, {'options': {'minValue': 3.9}}],
    258        'outputs': 'clampOutput'
    259      }],
    260      'expectedOutputs': {
    261        'clampOutput': {
    262          'data': [3, 4, 5, 3, 3],
    263          'descriptor': {shape: [5], dataType: 'int64'}
    264        }
    265      }
    266    }
    267  },
    268 ];
    269 
    270 webnn_conformance_test(
    271    mlNumberTests, buildAndExecuteGraph, getClampPrecisionTolerance);