tor-browser

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

logical_xor.https.any.js (10354B)


      1 // META: title=test WebNN API element-wise logicalXor 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 // MLOperand logicalXor(MLOperand a, MLOperand b, optional MLOperatorOptions options = {});
     12 
     13 const logicalXorTests = [
     14 {
     15  'name': 'logicalXor uint8 0D scalar',
     16  'graph': {
     17    'inputs': {
     18      'inputA': {
     19        'data': [1],
     20        'descriptor': {shape: [], dataType: 'uint8'}
     21      },
     22      'inputB': {
     23        'data': [0],
     24        'descriptor': {shape: [], dataType: 'uint8'}
     25      }
     26    },
     27    'operators': [{
     28      'name': 'logicalXor',
     29      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
     30      'outputs': 'output'
     31    }],
     32    'expectedOutputs': {
     33      'output': {'data': [1], 'descriptor': {shape: [], dataType: 'uint8'}}
     34    }
     35  }
     36 },
     37 {
     38  'name': 'logicalXor uint8 1D constant tensors',
     39  'graph': {
     40    'inputs': {
     41      'inputA': {
     42        'data': [
     43          0, 0, 1, 1, 0, 0, 2, 2, 0, 0, 8, 8,
     44          0, 0, 8, 8, 0, 0, 255, 255, 0, 0, 255, 255
     45        ],
     46        'descriptor': {shape: [24], dataType: 'uint8'},
     47        'constant': true
     48      },
     49      'inputB': {
     50        'data': [
     51          0, 1, 0, 1, 0, 2, 0, 2, 0, 8, 0, 8,
     52          0, 2, 0, 2, 0, 255, 0, 255, 0, 8, 0, 8
     53        ],
     54        'descriptor': {shape: [24], dataType: 'uint8'},
     55        'constant': true
     56      }
     57    },
     58    'operators': [{
     59      'name': 'logicalXor',
     60      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
     61      'outputs': 'output'
     62    }],
     63    'expectedOutputs': {
     64      'output': {
     65        'data': [
     66          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
     67          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0
     68        ],
     69        'descriptor': {shape: [24], dataType: 'uint8'}
     70      }
     71    }
     72  }
     73 },
     74 {
     75  'name': 'logicalXor uint8 1D tensors',
     76  'graph': {
     77    'inputs': {
     78      'inputA': {
     79        'data': [
     80          0, 0, 1, 1, 0, 0, 2, 2, 0, 0, 8, 8,
     81          0, 0, 8, 8, 0, 0, 255, 255, 0, 0, 255, 255
     82        ],
     83        'descriptor': {shape: [24], dataType: 'uint8'}
     84      },
     85      'inputB': {
     86        'data': [
     87          0, 1, 0, 1, 0, 2, 0, 2, 0, 8, 0, 8,
     88          0, 2, 0, 2, 0, 255, 0, 255, 0, 8, 0, 8
     89        ],
     90        'descriptor': {shape: [24], dataType: 'uint8'}
     91      }
     92    },
     93    'operators': [{
     94      'name': 'logicalXor',
     95      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
     96      'outputs': 'output'
     97    }],
     98    'expectedOutputs': {
     99      'output': {
    100        'data': [
    101          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
    102          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0
    103        ],
    104        'descriptor': {shape: [24], dataType: 'uint8'}
    105      }
    106    }
    107  }
    108 },
    109 {
    110  'name': 'logicalXor uint8 2D tensors',
    111  'graph': {
    112    'inputs': {
    113      'inputA': {
    114        'data': [
    115          0, 0, 1, 1, 0, 0, 2, 2, 0, 0, 8, 8,
    116          0, 0, 8, 8, 0, 0, 255, 255, 0, 0, 255, 255
    117        ],
    118        'descriptor': {shape: [4, 6], dataType: 'uint8'}
    119      },
    120      'inputB': {
    121        'data': [
    122          0, 1, 0, 1, 0, 2, 0, 2, 0, 8, 0, 8,
    123          0, 2, 0, 2, 0, 255, 0, 255, 0, 8, 0, 8
    124        ],
    125        'descriptor': {shape: [4, 6], dataType: 'uint8'}
    126      }
    127    },
    128    'operators': [{
    129      'name': 'logicalXor',
    130      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
    131      'outputs': 'output'
    132    }],
    133    'expectedOutputs': {
    134      'output': {
    135        'data': [
    136          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
    137          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0
    138        ],
    139        'descriptor': {shape: [4, 6], dataType: 'uint8'}
    140      }
    141    }
    142  }
    143 },
    144 {
    145  'name': 'logicalXor uint8 3D tensors',
    146  'graph': {
    147    'inputs': {
    148      'inputA': {
    149        'data': [
    150          0, 0, 1, 1, 0, 0, 2, 2, 0, 0, 8, 8,
    151          0, 0, 8, 8, 0, 0, 255, 255, 0, 0, 255, 255
    152        ],
    153        'descriptor': {shape: [2, 3, 4], dataType: 'uint8'}
    154      },
    155      'inputB': {
    156        'data': [
    157          0, 1, 0, 1, 0, 2, 0, 2, 0, 8, 0, 8,
    158          0, 2, 0, 2, 0, 255, 0, 255, 0, 8, 0, 8
    159        ],
    160        'descriptor': {shape: [2, 3, 4], dataType: 'uint8'}
    161      }
    162    },
    163    'operators': [{
    164      'name': 'logicalXor',
    165      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
    166      'outputs': 'output'
    167    }],
    168    'expectedOutputs': {
    169      'output': {
    170        'data': [
    171          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
    172          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0
    173        ],
    174        'descriptor': {shape: [2, 3, 4], dataType: 'uint8'}
    175      }
    176    }
    177  }
    178 },
    179 {
    180  'name': 'logicalXor uint8 4D tensors',
    181  'graph': {
    182    'inputs': {
    183      'inputA': {
    184        'data': [
    185          0, 0, 1, 1, 0, 0, 2, 2, 0, 0, 8, 8,
    186          0, 0, 8, 8, 0, 0, 255, 255, 0, 0, 255, 255
    187        ],
    188        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    189      },
    190      'inputB': {
    191        'data': [
    192          0, 1, 0, 1, 0, 2, 0, 2, 0, 8, 0, 8,
    193          0, 2, 0, 2, 0, 255, 0, 255, 0, 8, 0, 8
    194        ],
    195        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    196      }
    197    },
    198    'operators': [{
    199      'name': 'logicalXor',
    200      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
    201      'outputs': 'output'
    202    }],
    203    'expectedOutputs': {
    204      'output': {
    205        'data': [
    206          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
    207          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0
    208        ],
    209        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    210      }
    211    }
    212  }
    213 },
    214 {
    215  'name': 'logicalXor uint8 5D tensors',
    216  'graph': {
    217    'inputs': {
    218      'inputA': {
    219        'data': [
    220          0, 0, 1, 1, 0, 0, 2, 2, 0, 0, 8, 8,
    221          0, 0, 8, 8, 0, 0, 255, 255, 0, 0, 255, 255
    222        ],
    223        'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'uint8'}
    224      },
    225      'inputB': {
    226        'data': [
    227          0, 1, 0, 1, 0, 2, 0, 2, 0, 8, 0, 8,
    228          0, 2, 0, 2, 0, 255, 0, 255, 0, 8, 0, 8
    229        ],
    230        'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'uint8'}
    231      }
    232    },
    233    'operators': [{
    234      'name': 'logicalXor',
    235      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
    236      'outputs': 'output'
    237    }],
    238    'expectedOutputs': {
    239      'output': {
    240        'data': [
    241          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
    242          0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0
    243        ],
    244        'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'uint8'}
    245      }
    246    }
    247  }
    248 },
    249 {
    250  'name': 'logicalXor uint8 broadcast 0D to 4D',
    251  'graph': {
    252    'inputs': {
    253      'inputA': {
    254        'data': [1],
    255        'descriptor': {shape: [], dataType: 'uint8'}
    256      },
    257      'inputB': {
    258        'data': [
    259          0, 1, 0, 1, 0, 2, 0, 2, 0, 8, 0, 8,
    260          0, 2, 0, 2, 0, 255, 0, 255, 0, 8, 0, 8
    261        ],
    262        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    263      }
    264    },
    265    'operators': [{
    266      'name': 'logicalXor',
    267      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
    268      'outputs': 'output'
    269    }],
    270    'expectedOutputs': {
    271      'output': {
    272        'data': [
    273          1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
    274          1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0
    275        ],
    276        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    277      }
    278    }
    279  }
    280 },
    281 {
    282  'name': 'logicalXor uint8 broadcast 1D to 4D',
    283  'graph': {
    284    'inputs': {
    285      'inputA': {
    286        'data': [1],
    287        'descriptor': {shape: [1], dataType: 'uint8'}
    288      },
    289      'inputB': {
    290        'data': [
    291          0, 1, 0, 1, 0, 2, 0, 2, 0, 8, 0, 8,
    292          0, 2, 0, 2, 0, 255, 0, 255, 0, 8, 0, 8
    293        ],
    294        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    295      }
    296    },
    297    'operators': [{
    298      'name': 'logicalXor',
    299      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
    300      'outputs': 'output'
    301    }],
    302    'expectedOutputs': {
    303      'output': {
    304        'data': [
    305          1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
    306          1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0
    307        ],
    308        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    309      }
    310    }
    311  }
    312 },
    313 {
    314  'name': 'logicalXor uint8 broadcast 2D to 4D',
    315  'graph': {
    316    'inputs': {
    317      'inputA': {
    318        'data': [
    319          0, 0, 1, 1, 0, 0, 2, 2, 0, 0, 8, 8,
    320          0, 0, 8, 8, 0, 0, 255, 255, 0, 0, 255, 255
    321        ],
    322        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    323      },
    324      'inputB': {
    325        'data': [
    326          0, 1, 0, 1, 255, 255
    327        ],
    328        'descriptor': {shape: [2, 3], dataType: 'uint8'}
    329      }
    330    },
    331    'operators': [{
    332      'name': 'logicalXor',
    333      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
    334      'outputs': 'output'
    335    }],
    336    'expectedOutputs': {
    337      'output': {
    338        'data': [
    339          0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0,
    340          0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0
    341        ],
    342        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    343      }
    344    }
    345  }
    346 },
    347 {
    348  'name': 'logicalXor uint8 broadcast 3D to 4D',
    349  'graph': {
    350    'inputs': {
    351      'inputA': {
    352        'data': [
    353          0, 0, 1, 1, 0, 0, 2, 2, 0, 0, 8, 8,
    354          0, 0, 8, 8, 0, 0, 255, 255, 0, 0, 255, 255
    355        ],
    356        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    357      },
    358      'inputB': {
    359        'data': [
    360          0, 1, 0, 255
    361        ],
    362        'descriptor': {shape: [2, 2, 1], dataType: 'uint8'}
    363      }
    364    },
    365    'operators': [{
    366      'name': 'logicalXor',
    367      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
    368      'outputs': 'output'
    369    }],
    370    'expectedOutputs': {
    371      'output': {
    372        'data': [
    373          0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0,
    374          0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0
    375        ],
    376        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    377      }
    378    }
    379  }
    380 },
    381 {
    382  'name': 'logicalXor uint8 broadcast 4D to 4D',
    383  'graph': {
    384    'inputs': {
    385      'inputA': {
    386        'data': [1],
    387        'descriptor': {shape: [1, 1, 1, 1], dataType: 'uint8'}
    388      },
    389      'inputB': {
    390        'data': [
    391          0, 1, 0, 1, 0, 2, 0, 2, 0, 8, 0, 8,
    392          0, 2, 0, 2, 0, 255, 0, 255, 0, 8, 0, 8
    393        ],
    394        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    395      }
    396    },
    397    'operators': [{
    398      'name': 'logicalXor',
    399      'arguments': [{'a': 'inputA'}, {'b': 'inputB'}],
    400      'outputs': 'output'
    401    }],
    402    'expectedOutputs': {
    403      'output': {
    404        'data': [
    405          1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
    406          1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0
    407        ],
    408        'descriptor': {shape: [2, 2, 2, 3], dataType: 'uint8'}
    409      }
    410    }
    411  }
    412 }
    413 ];
    414 
    415 webnn_conformance_test(
    416    logicalXorTests, buildAndExecuteGraph, getZeroULPTolerance);