tor-browser

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

reverse.https.any.js (2010B)


      1 // META: title=validation tests for 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_validation.js
      7 
      8 'use strict';
      9 
     10 const tests = [
     11  {
     12    name: '[reverse] Test reverse with default options',
     13    input: {dataType: 'float32', shape: [3, 3]},
     14    output: {dataType: 'float32', shape: [3, 3]}
     15  },
     16  {
     17    name: '[reverse] Test reverse with axes = [0, 1]',
     18    input: {dataType: 'int32', shape: [1, 2, 3]},
     19    axes: [0, 1],
     20    output: {dataType: 'int32', shape: [1, 2, 3]}
     21  },
     22  {
     23    name: '[reverse] Throw if axes is greater than input rank',
     24    input: {dataType: 'float32', shape: [3, 3]},
     25    axes: [3]
     26  },
     27  {
     28    name: '[reverse] Throw if axes is duplicated',
     29    input: {dataType: 'float32', shape: [1, 2, 3, 4]},
     30    axes: [2, 2, 3]
     31  }
     32 ];
     33 
     34 tests.forEach(test => promise_test(async t => {
     35                const builder = new MLGraphBuilder(context);
     36                const input = builder.input('input', test.input);
     37                const options = {};
     38                if (test.axes) {
     39                  options.axes = test.axes;
     40                }
     41 
     42                if (test.output) {
     43                  const output = builder.reverse(input, options);
     44                  assert_equals(output.dataType, test.output.dataType);
     45                  assert_array_equals(output.shape, test.output.shape);
     46                } else {
     47                  const label = 'reverse_1'
     48                  options.label = label;
     49                  const regexp = new RegExp('\\[' + label + '\\]');
     50                  assert_throws_with_label(
     51                      () => builder.reverse(input, options), regexp);
     52                }
     53              }, test.name));
     54 
     55 multi_builder_test(async (t, builder, otherBuilder) => {
     56  const input =
     57      otherBuilder.input('input', {dataType: 'float32', shape: [3, 3]});
     58  assert_throws_js(TypeError, () => builder.reverse(input));
     59 }, '[reverse] Throw if input is from another builder');