1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// META: title=validation tests for WebNN API split operation
// META: global=window,dedicatedworker
// META: script=../resources/utils_validation.js
'use strict';
multi_builder_test(async (t, builder, otherBuilder) => {
const inputFromOtherBuilder =
otherBuilder.input('input', {dataType: 'float32', dimensions: [4, 4]});
const splits = 2;
assert_throws_js(
TypeError, () => builder.split(inputFromOtherBuilder, splits));
}, '[split] throw if input is from another builder');
const tests = [
{
name: '[split] Test with default options.',
input: {dataType: 'float32', dimensions: [2, 6]},
splits: [2],
outputs: [
{dataType: 'float32', dimensions: [2, 6]},
]
},
{
name:
'[split] Test with a sequence of unsigned long splits and with options.axis = 1.',
input: {dataType: 'float32', dimensions: [2, 6]},
splits: [1, 2, 3],
options: {axis: 1},
outputs: [
{dataType: 'float32', dimensions: [2, 1]},
{dataType: 'float32', dimensions: [2, 2]},
{dataType: 'float32', dimensions: [2, 3]},
]
},
{
name: '[split] Throw if splitting a scalar.',
input: {dataType: 'float32', dimensions: []},
splits: [2],
},
{
name: '[split] Throw if axis is larger than input rank.',
input: {dataType: 'float32', dimensions: [2, 6]},
splits: [2],
options: {
axis: 2,
}
},
{
name: '[split] Throw if splits is equal to 0.',
input: {dataType: 'float32', dimensions: [2, 6]},
splits: [0],
options: {
axis: 2,
}
},
{
name:
'[split] Throw if the splits can not evenly divide the dimension size of input along options.axis.',
input: {dataType: 'float32', dimensions: [2, 5]},
splits: [2],
options: {
axis: 1,
}
},
{
name:
'[split] Throw if the sum of splits sizes not equal to the dimension size of input along options.axis.',
input: {dataType: 'float32', dimensions: [2, 6]},
splits: [2, 2, 3],
options: {
axis: 1,
}
},
];
tests.forEach(
test => promise_test(async t => {
const input = builder.input(
'input',
{dataType: test.input.dataType, dimensions: test.input.dimensions});
if (test.outputs) {
const outputs = builder.split(input, test.splits, test.options);
assert_equals(outputs.length, test.outputs.length);
for (let i = 0; i < outputs.length; ++i) {
assert_equals(outputs[i].dataType(), test.outputs[i].dataType);
assert_array_equals(outputs[i].shape(), test.outputs[i].dimensions);
}
} else {
assert_throws_js(
TypeError, () => builder.split(input, test.splits, test.options));
}
}, test.name));
|