tor-browser

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

erf.https.any.js (21024B)


      1 // META: title=test WebNN API element-wise erf 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 error function of the input tensor, element-wise.
     13 //
     14 // MLOperand erf(MLOperand input);
     15 
     16 
     17 const getErfPrecisionTolerance = (graphResources) => {
     18  const toleranceValueDict = {float32: 1 / 1024, float16: 1 / 512};
     19  const expectedDataType =
     20      getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs);
     21  return {metricType: 'ATOL', value: toleranceValueDict[expectedDataType]};
     22 };
     23 
     24 const erfTests = [
     25  {
     26    'name': 'erf float32 0D scalar',
     27    'graph': {
     28      'inputs': {
     29        'erfInput': {
     30          'data': [-0.004352752584964037],
     31          'descriptor': {shape: [], dataType: 'float32'}
     32        }
     33      },
     34      'operators': [{
     35        'name': 'erf',
     36        'arguments': [{'input': 'erfInput'}],
     37        'outputs': 'erfOutput'
     38      }],
     39      'expectedOutputs': {
     40        'erfOutput': {
     41          'data': [-0.004911554511636496],
     42          'descriptor': {shape: [], dataType: 'float32'}
     43        }
     44      }
     45    }
     46  },
     47  {
     48    'name': 'erf float32 1D constant tensor',
     49    'graph': {
     50      'inputs': {
     51        'erfInput': {
     52          'data': [
     53            -0.5883062481880188, -0.5323766469955444, 0.1279870569705963,
     54            0.5772181749343872,  0.904577910900116,   -0.49856746196746826,
     55            0.9843886494636536,  0.21642258763313293, 0.25235170125961304,
     56            -0.1491669863462448, 0.9136939644813538,  -0.5736439824104309,
     57            0.7404468059539795,  0.5202203392982483,  -0.16549505293369293,
     58            0.8005731701850891,  0.4001320004463196,  -0.7489422559738159,
     59            -0.8946002721786499, -0.3920256197452545, 0.6854220628738403,
     60            -0.6744900345802307, -0.439808189868927,  0.2709762454032898
     61          ],
     62          'descriptor': {shape: [24], dataType: 'float32'},
     63          'constant': true
     64        }
     65      },
     66      'operators': [{
     67        'name': 'erf',
     68        'arguments': [{'input': 'erfInput'}],
     69        'outputs': 'erfOutput'
     70      }],
     71      'expectedOutputs': {
     72        'erfOutput': {
     73          'data': [
     74            -0.5945858955383301,  -0.5484867095947266,  0.14363321661949158,
     75            0.5856771469116211,   0.7991966009140015,   -0.5192402005195618,
     76            0.8361185789108276,   0.2404468059539795,   0.27881762385368347,
     77            -0.16707675158977509, 0.8036975860595703,   -0.5827808976173401,
     78            0.7049695253372192,   0.5380884408950806,   -0.1850501298904419,
     79            0.742441713809967,    0.4285193383693695,   -0.710474967956543,
     80            -0.7941843867301941,  -0.4207003712654114,  0.6676210165023804,
     81            -0.6598520874977112,  -0.46604686975479126, 0.29844197630882263
     82          ],
     83          'descriptor': {shape: [24], dataType: 'float32'}
     84        }
     85      }
     86    }
     87  },
     88  {
     89    'name': 'erf float32 1D tensor',
     90    'graph': {
     91      'inputs': {
     92        'erfInput': {
     93          'data': [
     94            -0.5883062481880188, -0.5323766469955444, 0.1279870569705963,
     95            0.5772181749343872,  0.904577910900116,   -0.49856746196746826,
     96            0.9843886494636536,  0.21642258763313293, 0.25235170125961304,
     97            -0.1491669863462448, 0.9136939644813538,  -0.5736439824104309,
     98            0.7404468059539795,  0.5202203392982483,  -0.16549505293369293,
     99            0.8005731701850891,  0.4001320004463196,  -0.7489422559738159,
    100            -0.8946002721786499, -0.3920256197452545, 0.6854220628738403,
    101            -0.6744900345802307, -0.439808189868927,  0.2709762454032898
    102          ],
    103          'descriptor': {shape: [24], dataType: 'float32'}
    104        }
    105      },
    106      'operators': [{
    107        'name': 'erf',
    108        'arguments': [{'input': 'erfInput'}],
    109        'outputs': 'erfOutput'
    110      }],
    111      'expectedOutputs': {
    112        'erfOutput': {
    113          'data': [
    114            -0.5945858955383301,  -0.5484867095947266,  0.14363321661949158,
    115            0.5856771469116211,   0.7991966009140015,   -0.5192402005195618,
    116            0.8361185789108276,   0.2404468059539795,   0.27881762385368347,
    117            -0.16707675158977509, 0.8036975860595703,   -0.5827808976173401,
    118            0.7049695253372192,   0.5380884408950806,   -0.1850501298904419,
    119            0.742441713809967,    0.4285193383693695,   -0.710474967956543,
    120            -0.7941843867301941,  -0.4207003712654114,  0.6676210165023804,
    121            -0.6598520874977112,  -0.46604686975479126, 0.29844197630882263
    122          ],
    123          'descriptor': {shape: [24], dataType: 'float32'}
    124        }
    125      }
    126    }
    127  },
    128  {
    129    'name': 'erf float32 2D tensor',
    130    'graph': {
    131      'inputs': {
    132        'erfInput': {
    133          'data': [
    134            -0.5883062481880188, -0.5323766469955444, 0.1279870569705963,
    135            0.5772181749343872,  0.904577910900116,   -0.49856746196746826,
    136            0.9843886494636536,  0.21642258763313293, 0.25235170125961304,
    137            -0.1491669863462448, 0.9136939644813538,  -0.5736439824104309,
    138            0.7404468059539795,  0.5202203392982483,  -0.16549505293369293,
    139            0.8005731701850891,  0.4001320004463196,  -0.7489422559738159,
    140            -0.8946002721786499, -0.3920256197452545, 0.6854220628738403,
    141            -0.6744900345802307, -0.439808189868927,  0.2709762454032898
    142          ],
    143          'descriptor': {shape: [4, 6], dataType: 'float32'}
    144        }
    145      },
    146      'operators': [{
    147        'name': 'erf',
    148        'arguments': [{'input': 'erfInput'}],
    149        'outputs': 'erfOutput'
    150      }],
    151      'expectedOutputs': {
    152        'erfOutput': {
    153          'data': [
    154            -0.5945858955383301,  -0.5484867095947266,  0.14363321661949158,
    155            0.5856771469116211,   0.7991966009140015,   -0.5192402005195618,
    156            0.8361185789108276,   0.2404468059539795,   0.27881762385368347,
    157            -0.16707675158977509, 0.8036975860595703,   -0.5827808976173401,
    158            0.7049695253372192,   0.5380884408950806,   -0.1850501298904419,
    159            0.742441713809967,    0.4285193383693695,   -0.710474967956543,
    160            -0.7941843867301941,  -0.4207003712654114,  0.6676210165023804,
    161            -0.6598520874977112,  -0.46604686975479126, 0.29844197630882263
    162          ],
    163          'descriptor': {shape: [4, 6], dataType: 'float32'}
    164        }
    165      }
    166    }
    167  },
    168  {
    169    'name': 'erf float32 3D tensor',
    170    'graph': {
    171      'inputs': {
    172        'erfInput': {
    173          'data': [
    174            -0.5883062481880188, -0.5323766469955444, 0.1279870569705963,
    175            0.5772181749343872,  0.904577910900116,   -0.49856746196746826,
    176            0.9843886494636536,  0.21642258763313293, 0.25235170125961304,
    177            -0.1491669863462448, 0.9136939644813538,  -0.5736439824104309,
    178            0.7404468059539795,  0.5202203392982483,  -0.16549505293369293,
    179            0.8005731701850891,  0.4001320004463196,  -0.7489422559738159,
    180            -0.8946002721786499, -0.3920256197452545, 0.6854220628738403,
    181            -0.6744900345802307, -0.439808189868927,  0.2709762454032898
    182          ],
    183          'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
    184        }
    185      },
    186      'operators': [{
    187        'name': 'erf',
    188        'arguments': [{'input': 'erfInput'}],
    189        'outputs': 'erfOutput'
    190      }],
    191      'expectedOutputs': {
    192        'erfOutput': {
    193          'data': [
    194            -0.5945858955383301,  -0.5484867095947266,  0.14363321661949158,
    195            0.5856771469116211,   0.7991966009140015,   -0.5192402005195618,
    196            0.8361185789108276,   0.2404468059539795,   0.27881762385368347,
    197            -0.16707675158977509, 0.8036975860595703,   -0.5827808976173401,
    198            0.7049695253372192,   0.5380884408950806,   -0.1850501298904419,
    199            0.742441713809967,    0.4285193383693695,   -0.710474967956543,
    200            -0.7941843867301941,  -0.4207003712654114,  0.6676210165023804,
    201            -0.6598520874977112,  -0.46604686975479126, 0.29844197630882263
    202          ],
    203          'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
    204        }
    205      }
    206    }
    207  },
    208  {
    209    'name': 'erf float32 4D tensor',
    210    'graph': {
    211      'inputs': {
    212        'erfInput': {
    213          'data': [
    214            -0.5883062481880188, -0.5323766469955444, 0.1279870569705963,
    215            0.5772181749343872,  0.904577910900116,   -0.49856746196746826,
    216            0.9843886494636536,  0.21642258763313293, 0.25235170125961304,
    217            -0.1491669863462448, 0.9136939644813538,  -0.5736439824104309,
    218            0.7404468059539795,  0.5202203392982483,  -0.16549505293369293,
    219            0.8005731701850891,  0.4001320004463196,  -0.7489422559738159,
    220            -0.8946002721786499, -0.3920256197452545, 0.6854220628738403,
    221            -0.6744900345802307, -0.439808189868927,  0.2709762454032898
    222          ],
    223          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'}
    224        }
    225      },
    226      'operators': [{
    227        'name': 'erf',
    228        'arguments': [{'input': 'erfInput'}],
    229        'outputs': 'erfOutput'
    230      }],
    231      'expectedOutputs': {
    232        'erfOutput': {
    233          'data': [
    234            -0.5945858955383301,  -0.5484867095947266,  0.14363321661949158,
    235            0.5856771469116211,   0.7991966009140015,   -0.5192402005195618,
    236            0.8361185789108276,   0.2404468059539795,   0.27881762385368347,
    237            -0.16707675158977509, 0.8036975860595703,   -0.5827808976173401,
    238            0.7049695253372192,   0.5380884408950806,   -0.1850501298904419,
    239            0.742441713809967,    0.4285193383693695,   -0.710474967956543,
    240            -0.7941843867301941,  -0.4207003712654114,  0.6676210165023804,
    241            -0.6598520874977112,  -0.46604686975479126, 0.29844197630882263
    242          ],
    243          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'}
    244        }
    245      }
    246    }
    247  },
    248  {
    249    'name': 'erf float32 5D tensor',
    250    'graph': {
    251      'inputs': {
    252        'erfInput': {
    253          'data': [
    254            -0.5883062481880188, -0.5323766469955444, 0.1279870569705963,
    255            0.5772181749343872,  0.904577910900116,   -0.49856746196746826,
    256            0.9843886494636536,  0.21642258763313293, 0.25235170125961304,
    257            -0.1491669863462448, 0.9136939644813538,  -0.5736439824104309,
    258            0.7404468059539795,  0.5202203392982483,  -0.16549505293369293,
    259            0.8005731701850891,  0.4001320004463196,  -0.7489422559738159,
    260            -0.8946002721786499, -0.3920256197452545, 0.6854220628738403,
    261            -0.6744900345802307, -0.439808189868927,  0.2709762454032898
    262          ],
    263          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'}
    264        }
    265      },
    266      'operators': [{
    267        'name': 'erf',
    268        'arguments': [{'input': 'erfInput'}],
    269        'outputs': 'erfOutput'
    270      }],
    271      'expectedOutputs': {
    272        'erfOutput': {
    273          'data': [
    274            -0.5945858955383301,  -0.5484867095947266,  0.14363321661949158,
    275            0.5856771469116211,   0.7991966009140015,   -0.5192402005195618,
    276            0.8361185789108276,   0.2404468059539795,   0.27881762385368347,
    277            -0.16707675158977509, 0.8036975860595703,   -0.5827808976173401,
    278            0.7049695253372192,   0.5380884408950806,   -0.1850501298904419,
    279            0.742441713809967,    0.4285193383693695,   -0.710474967956543,
    280            -0.7941843867301941,  -0.4207003712654114,  0.6676210165023804,
    281            -0.6598520874977112,  -0.46604686975479126, 0.29844197630882263
    282          ],
    283          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'}
    284        }
    285      }
    286    }
    287  },
    288 
    289  // float16 tests
    290  {
    291    'name': 'erf float16 0D scalar',
    292    'graph': {
    293      'inputs': {
    294        'erfInput': {
    295          'data': [-0.004352569580078125],
    296          'descriptor': {shape: [], dataType: 'float16'}
    297        }
    298      },
    299      'operators': [{
    300        'name': 'erf',
    301        'arguments': [{'input': 'erfInput'}],
    302        'outputs': 'erfOutput'
    303      }],
    304      'expectedOutputs': {
    305        'erfOutput': {
    306          'data': [-0.004909515380859375],
    307          'descriptor': {shape: [], dataType: 'float16'}
    308        }
    309      }
    310    }
    311  },
    312  {
    313    'name': 'erf float16 1D constant tensor',
    314    'graph': {
    315      'inputs': {
    316        'erfInput': {
    317          'data': [
    318            -0.58837890625, -0.5322265625,   0.1279296875,    0.5771484375,
    319            0.90478515625,  -0.49853515625,  0.984375,        0.2164306640625,
    320            0.25244140625,  -0.149169921875, 0.91357421875,   -0.57373046875,
    321            0.740234375,    0.52001953125,   -0.16552734375,  0.80078125,
    322            0.400146484375, -0.7490234375,   -0.89453125,     -0.39208984375,
    323            0.685546875,    -0.67431640625,  -0.439697265625, 0.27099609375
    324          ],
    325          'descriptor': {shape: [24], dataType: 'float16'},
    326          'constant': true
    327        }
    328      },
    329      'operators': [{
    330        'name': 'erf',
    331        'arguments': [{'input': 'erfInput'}],
    332        'outputs': 'erfOutput'
    333      }],
    334      'expectedOutputs': {
    335        'erfOutput': {
    336          'data': [
    337            -0.5947265625,  -0.54833984375,   0.1435546875,    0.58544921875,
    338            0.79931640625,  -0.51904296875,   0.8359375,       0.240478515625,
    339            0.27880859375,  -0.1671142578125, 0.8037109375,    -0.5830078125,
    340            0.70458984375,  0.5380859375,     -0.18505859375,  0.74267578125,
    341            0.428466796875, -0.71044921875,   -0.7939453125,   -0.420654296875,
    342            0.66748046875,  -0.65966796875,   -0.466064453125, 0.298583984375
    343          ],
    344          'descriptor': {shape: [24], dataType: 'float16'}
    345        }
    346      }
    347    }
    348  },
    349  {
    350    'name': 'erf float16 1D tensor',
    351    'graph': {
    352      'inputs': {
    353        'erfInput': {
    354          'data': [
    355            -0.58837890625, -0.5322265625,   0.1279296875,    0.5771484375,
    356            0.90478515625,  -0.49853515625,  0.984375,        0.2164306640625,
    357            0.25244140625,  -0.149169921875, 0.91357421875,   -0.57373046875,
    358            0.740234375,    0.52001953125,   -0.16552734375,  0.80078125,
    359            0.400146484375, -0.7490234375,   -0.89453125,     -0.39208984375,
    360            0.685546875,    -0.67431640625,  -0.439697265625, 0.27099609375
    361          ],
    362          'descriptor': {shape: [24], dataType: 'float16'}
    363        }
    364      },
    365      'operators': [{
    366        'name': 'erf',
    367        'arguments': [{'input': 'erfInput'}],
    368        'outputs': 'erfOutput'
    369      }],
    370      'expectedOutputs': {
    371        'erfOutput': {
    372          'data': [
    373            -0.5947265625,  -0.54833984375,   0.1435546875,    0.58544921875,
    374            0.79931640625,  -0.51904296875,   0.8359375,       0.240478515625,
    375            0.27880859375,  -0.1671142578125, 0.8037109375,    -0.5830078125,
    376            0.70458984375,  0.5380859375,     -0.18505859375,  0.74267578125,
    377            0.428466796875, -0.71044921875,   -0.7939453125,   -0.420654296875,
    378            0.66748046875,  -0.65966796875,   -0.466064453125, 0.298583984375
    379          ],
    380          'descriptor': {shape: [24], dataType: 'float16'}
    381        }
    382      }
    383    }
    384  },
    385  {
    386    'name': 'erf float16 2D tensor',
    387    'graph': {
    388      'inputs': {
    389        'erfInput': {
    390          'data': [
    391            -0.58837890625, -0.5322265625,   0.1279296875,    0.5771484375,
    392            0.90478515625,  -0.49853515625,  0.984375,        0.2164306640625,
    393            0.25244140625,  -0.149169921875, 0.91357421875,   -0.57373046875,
    394            0.740234375,    0.52001953125,   -0.16552734375,  0.80078125,
    395            0.400146484375, -0.7490234375,   -0.89453125,     -0.39208984375,
    396            0.685546875,    -0.67431640625,  -0.439697265625, 0.27099609375
    397          ],
    398          'descriptor': {shape: [4, 6], dataType: 'float16'}
    399        }
    400      },
    401      'operators': [{
    402        'name': 'erf',
    403        'arguments': [{'input': 'erfInput'}],
    404        'outputs': 'erfOutput'
    405      }],
    406      'expectedOutputs': {
    407        'erfOutput': {
    408          'data': [
    409            -0.5947265625,  -0.54833984375,   0.1435546875,    0.58544921875,
    410            0.79931640625,  -0.51904296875,   0.8359375,       0.240478515625,
    411            0.27880859375,  -0.1671142578125, 0.8037109375,    -0.5830078125,
    412            0.70458984375,  0.5380859375,     -0.18505859375,  0.74267578125,
    413            0.428466796875, -0.71044921875,   -0.7939453125,   -0.420654296875,
    414            0.66748046875,  -0.65966796875,   -0.466064453125, 0.298583984375
    415          ],
    416          'descriptor': {shape: [4, 6], dataType: 'float16'}
    417        }
    418      }
    419    }
    420  },
    421  {
    422    'name': 'erf float16 3D tensor',
    423    'graph': {
    424      'inputs': {
    425        'erfInput': {
    426          'data': [
    427            -0.58837890625, -0.5322265625,   0.1279296875,    0.5771484375,
    428            0.90478515625,  -0.49853515625,  0.984375,        0.2164306640625,
    429            0.25244140625,  -0.149169921875, 0.91357421875,   -0.57373046875,
    430            0.740234375,    0.52001953125,   -0.16552734375,  0.80078125,
    431            0.400146484375, -0.7490234375,   -0.89453125,     -0.39208984375,
    432            0.685546875,    -0.67431640625,  -0.439697265625, 0.27099609375
    433          ],
    434          'descriptor': {shape: [2, 3, 4], dataType: 'float16'}
    435        }
    436      },
    437      'operators': [{
    438        'name': 'erf',
    439        'arguments': [{'input': 'erfInput'}],
    440        'outputs': 'erfOutput'
    441      }],
    442      'expectedOutputs': {
    443        'erfOutput': {
    444          'data': [
    445            -0.5947265625,  -0.54833984375,   0.1435546875,    0.58544921875,
    446            0.79931640625,  -0.51904296875,   0.8359375,       0.240478515625,
    447            0.27880859375,  -0.1671142578125, 0.8037109375,    -0.5830078125,
    448            0.70458984375,  0.5380859375,     -0.18505859375,  0.74267578125,
    449            0.428466796875, -0.71044921875,   -0.7939453125,   -0.420654296875,
    450            0.66748046875,  -0.65966796875,   -0.466064453125, 0.298583984375
    451          ],
    452          'descriptor': {shape: [2, 3, 4], dataType: 'float16'}
    453        }
    454      }
    455    }
    456  },
    457  {
    458    'name': 'erf float16 4D tensor',
    459    'graph': {
    460      'inputs': {
    461        'erfInput': {
    462          'data': [
    463            -0.58837890625, -0.5322265625,   0.1279296875,    0.5771484375,
    464            0.90478515625,  -0.49853515625,  0.984375,        0.2164306640625,
    465            0.25244140625,  -0.149169921875, 0.91357421875,   -0.57373046875,
    466            0.740234375,    0.52001953125,   -0.16552734375,  0.80078125,
    467            0.400146484375, -0.7490234375,   -0.89453125,     -0.39208984375,
    468            0.685546875,    -0.67431640625,  -0.439697265625, 0.27099609375
    469          ],
    470          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'}
    471        }
    472      },
    473      'operators': [{
    474        'name': 'erf',
    475        'arguments': [{'input': 'erfInput'}],
    476        'outputs': 'erfOutput'
    477      }],
    478      'expectedOutputs': {
    479        'erfOutput': {
    480          'data': [
    481            -0.5947265625,  -0.54833984375,   0.1435546875,    0.58544921875,
    482            0.79931640625,  -0.51904296875,   0.8359375,       0.240478515625,
    483            0.27880859375,  -0.1671142578125, 0.8037109375,    -0.5830078125,
    484            0.70458984375,  0.5380859375,     -0.18505859375,  0.74267578125,
    485            0.428466796875, -0.71044921875,   -0.7939453125,   -0.420654296875,
    486            0.66748046875,  -0.65966796875,   -0.466064453125, 0.298583984375
    487          ],
    488          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'}
    489        }
    490      }
    491    }
    492  },
    493  {
    494    'name': 'erf float16 5D tensor',
    495    'graph': {
    496      'inputs': {
    497        'erfInput': {
    498          'data': [
    499            -0.58837890625, -0.5322265625,   0.1279296875,    0.5771484375,
    500            0.90478515625,  -0.49853515625,  0.984375,        0.2164306640625,
    501            0.25244140625,  -0.149169921875, 0.91357421875,   -0.57373046875,
    502            0.740234375,    0.52001953125,   -0.16552734375,  0.80078125,
    503            0.400146484375, -0.7490234375,   -0.89453125,     -0.39208984375,
    504            0.685546875,    -0.67431640625,  -0.439697265625, 0.27099609375
    505          ],
    506          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'}
    507        }
    508      },
    509      'operators': [{
    510        'name': 'erf',
    511        'arguments': [{'input': 'erfInput'}],
    512        'outputs': 'erfOutput'
    513      }],
    514      'expectedOutputs': {
    515        'erfOutput': {
    516          'data': [
    517            -0.5947265625,  -0.54833984375,   0.1435546875,    0.58544921875,
    518            0.79931640625,  -0.51904296875,   0.8359375,       0.240478515625,
    519            0.27880859375,  -0.1671142578125, 0.8037109375,    -0.5830078125,
    520            0.70458984375,  0.5380859375,     -0.18505859375,  0.74267578125,
    521            0.428466796875, -0.71044921875,   -0.7939453125,   -0.420654296875,
    522            0.66748046875,  -0.65966796875,   -0.466064453125, 0.298583984375
    523          ],
    524          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'}
    525        }
    526      }
    527    }
    528  }
    529 ];
    530 
    531 webnn_conformance_test(
    532    erfTests, buildAndExecuteGraph, getErfPrecisionTolerance);