tor-browser

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

cumulativeSum.https.any.js (2681B)


      1 // META: title=validation tests for WebNN API relu 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: '[cumulativeSum] Test with default options',
     13    input: {dataType: 'float32', shape: [3, 2, 5]},
     14    axis: 0,
     15    output: {dataType: 'float32', shape: [3, 2, 5]}
     16  },
     17  {
     18    name: '[cumulativeSum] Test with integer input',
     19    input: {dataType: 'int32', shape: [3, 2, 5]},
     20    axis: 0,
     21    output: {dataType: 'int32', shape: [3, 2, 5]}
     22  },
     23  {
     24    name: '[cumulativeSum] Test with axis=1',
     25    input: {dataType: 'float32', shape: [3, 2, 5]},
     26    axis: 1,
     27    output: {dataType: 'float32', shape: [3, 2, 5]}
     28  },
     29  {
     30    name: '[cumulativeSum] Test with exclusive=true',
     31    input: {dataType: 'float32', shape: [3, 2, 5]},
     32    axis: 1,
     33    options: {exclusive: true},
     34    output: {dataType: 'float32', shape: [3, 2, 5]}
     35  },
     36  {
     37    name: '[cumulativeSum] Test with reversed=true',
     38    input: {dataType: 'float32', shape: [3, 2, 5]},
     39    axis: 1,
     40    options: {reversed: true},
     41    output: {dataType: 'float32', shape: [3, 2, 5]}
     42  },
     43  {
     44    name: '[cumulativeSum] Throw if input is a scalar',
     45    input: {dataType: 'float32', shape: []},
     46    axis: 0
     47  },
     48  {
     49    name: '[cumulativeSum] Throw if axis is invalid',
     50    input: {dataType: 'float32', shape: [1, 2, 3]},
     51    axis: 3
     52  },
     53 ]
     54 
     55 tests.forEach(
     56    test => promise_test(async t => {
     57      const builder = new MLGraphBuilder(context);
     58      const input = builder.input('input', test.input);
     59 
     60      const options = {};
     61      if (test.options) {
     62        if (test.options.exclusive) {
     63          options.exclusive = test.options.exclusive;
     64        }
     65        if (test.options.reversed) {
     66          options.reversed = test.options.reversed;
     67        }
     68      }
     69      if (test.output) {
     70        const output = builder.cumulativeSum(input, test.axis, options);
     71        assert_equals(output.dataType, test.output.dataType);
     72        assert_array_equals(output.shape, test.output.shape);
     73      } else {
     74        const label = 'cumulative_sum';
     75        options.label = label;
     76        const regexp = new RegExp('\\[' + label + '\\]');
     77        assert_throws_with_label(
     78            () => builder.cumulativeSum(input, test.axis, options), regexp);
     79      }
     80    }, test.name));
     81 
     82 multi_builder_test(async (t, builder, otherBuilder) => {
     83  const inputFromOtherBuilder =
     84      otherBuilder.input('input', {dataType: 'float32', shape: [3, 2, 5]});
     85  assert_throws_js(
     86      TypeError, () => builder.cumulativeSum(inputFromOtherBuilder, 0));
     87 }, '[cumulativeSum] throw if input is from another builder');