tor-browser

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

tile.https.any.js (2847B)


      1 // META: title=validation tests for WebNN API tile 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 validateInputFromAnotherBuilder('tile');
     11 
     12 const label = 'xxx-tile';
     13 const regrexp = new RegExp('\\[' + label + '\\]');
     14 const tests = [
     15  {
     16    name:
     17        '[tile] Test building tile with repetitions=[1, 1, 1, 1], float32 data type.',
     18    input: {dataType: 'float32', shape: [1, 2, 3, 4]},
     19    repetitions: [1, 1, 1, 1],
     20    output: {dataType: 'float32', shape: [1, 2, 3, 4]},
     21    options: {
     22      label: label,
     23    },
     24  },
     25  {
     26    name:
     27        '[tile] Test building tile with repetitions=[1, 2, 3, 4], uint32 data type.',
     28    input: {dataType: 'uint32', shape: [1, 2, 3, 4]},
     29    repetitions: [1, 2, 3, 4],
     30    output: {dataType: 'uint32', shape: [1, 4, 9, 16]},
     31  },
     32  {
     33    name:
     34        '[tile] Throw if repetitions\'s size is not the same as input\'s rank.',
     35    input: {dataType: 'int32', shape: [1, 2, 4]},
     36    repetitions: [1, 2, 3, 4],
     37  },
     38  {
     39    name: '[tile] Throw if any value in repetitions is zero.',
     40    input: {dataType: 'int32', shape: [1, 2, 3, 4]},
     41    repetitions: [0, 1, 2, 3],
     42  },
     43  {
     44    name: '[tile] Throw if any value in repetitions is negative.',
     45    input: {dataType: 'int32', shape: [1, 2, 3, 4]},
     46    repetitions: [-1, 1, 2, 3],
     47  },
     48  {
     49    name:
     50        '[tile] Throw if any value in repetitions causes tiled dimension size overflow.',
     51    input: {dataType: 'int32', shape: [1, 2, 3, 4]},
     52    repetitions: [1, 1, kMaxUnsignedLong, 3],
     53  }
     54 ];
     55 
     56 tests.forEach(
     57    test => promise_test(async t => {
     58      const builder = new MLGraphBuilder(context);
     59      const input = builder.input('input', test.input);
     60      if (test.output) {
     61        const output = builder.tile(input, test.repetitions, test.options);
     62        assert_equals(output.dataType, test.output.dataType);
     63        assert_array_equals(output.shape, test.output.shape);
     64      } else {
     65        const options = {...test.options};
     66        if (options.label) {
     67          builder.tile(input, test.repetitions, options);
     68          assert_throws_with_label(
     69              () => builder.tile(input, test.repetitions, options), regrexp);
     70        } else {
     71          assert_throws_js(
     72              TypeError, () => builder.tile(input, test.repetitions, options));
     73        }
     74      }
     75    }, test.name));
     76 
     77 promise_test(async t => {
     78  const builder = new MLGraphBuilder(context);
     79 
     80  const input = builder.input('input', {
     81      dataType: 'float32',
     82      shape: [1, 1, 1, context.opSupportLimits().maxTensorByteLength / 4]});
     83 
     84  const options = {label};
     85  const repetitions =  [1, 2, 3, 4];
     86  assert_throws_with_label(
     87      () => builder.tile(input, repetitions, options), regrexp);
     88 }, '[tile] throw if the output tensor byte length exceeds limit');