Flatten#
Flatten - 13#
Version
name: Flatten (GitHub)
domain: main
since_version: 13
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 13.
Summary
Flattens the input tensor into a 2D matrix. If input tensor has shape (d_0, d_1, … d_n) then the output will have shape (d_0 X d_1 … d_(axis-1), d_axis X d_(axis+1) … X dn).
Attributes
axis: Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [-r, r], where r is the rank of the input tensor. Negative value means counting dimensions from the back. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 … d_n), where the shape of the input tensor is (d_0, d_1, … d_n). Default value is
1
.
Inputs
input (heterogeneous) - T: A tensor of rank >= axis.
Outputs
output (heterogeneous) - T: A 2D tensor with the contents of the input tensor, with input dimensions up to axis flattened to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output.
Type Constraints
T in ( tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output to all tensor types.
Examples
flatten_with_default_axis
node = onnx.helper.make_node(
'Flatten',
inputs=['a'],
outputs=['b'], # Default value for axis: axis=1
)
shape = (5, 4, 3, 2)
a = np.random.random_sample(shape).astype(np.float32)
new_shape = (5, 24)
b = np.reshape(a, new_shape)
expect(node, inputs=[a], outputs=[b],
name='test_flatten_default_axis')
flatten_negative_axis
shape = (2, 3, 4, 5)
a = np.random.random_sample(shape).astype(np.float32)
for i in range(-len(shape), 0):
node = onnx.helper.make_node(
'Flatten',
inputs=['a'],
outputs=['b'],
axis=i,
)
new_shape = (np.prod(shape[0:i]).astype(int), -1)
b = np.reshape(a, new_shape)
expect(node, inputs=[a], outputs=[b],
name='test_flatten_negative_axis' + str(abs(i)))
Differences
0 | 0 | Flattens the input tensor into a 2D matrix. If input tensor has shape | Flattens the input tensor into a 2D matrix. If input tensor has shape |
1 | 1 | (d_0, d_1, ... d_n) then the output will have shape | (d_0, d_1, ... d_n) then the output will have shape |
2 | 2 | (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). | (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). |
3 | 3 |
|
|
4 | 4 | **Attributes** | **Attributes** |
5 | 5 |
|
|
6 | 6 | * **axis**: | * **axis**: |
7 | 7 | Indicate up to which input dimensions (exclusive) should be | Indicate up to which input dimensions (exclusive) should be |
8 | 8 | flattened to the outer dimension of the output. The value for axis | flattened to the outer dimension of the output. The value for axis |
9 | 9 | must be in the range [-r, r], where r is the rank of the input | must be in the range [-r, r], where r is the rank of the input |
10 | 10 | tensor. Negative value means counting dimensions from the back. When | tensor. Negative value means counting dimensions from the back. When |
11 | 11 | axis = 0, the shape of the output tensor is (1, (d_0 X d_1 ... d_n), | axis = 0, the shape of the output tensor is (1, (d_0 X d_1 ... d_n), |
12 | 12 | where the shape of the input tensor is (d_0, d_1, ... d_n). Default value is 1. | where the shape of the input tensor is (d_0, d_1, ... d_n). Default value is 1. |
13 | 13 |
|
|
14 | 14 | **Inputs** | **Inputs** |
15 | 15 |
|
|
16 | 16 | * **input** (heterogeneous) - **T**: | * **input** (heterogeneous) - **T**: |
17 | 17 | A tensor of rank >= axis. | A tensor of rank >= axis. |
18 | 18 |
|
|
19 | 19 | **Outputs** | **Outputs** |
20 | 20 |
|
|
21 | 21 | * **output** (heterogeneous) - **T**: | * **output** (heterogeneous) - **T**: |
22 | 22 | A 2D tensor with the contents of the input tensor, with input | A 2D tensor with the contents of the input tensor, with input |
23 | 23 | dimensions up to axis flattened to the outer dimension of the output | dimensions up to axis flattened to the outer dimension of the output |
24 | 24 | and remaining input dimensions flattened into the inner dimension of | and remaining input dimensions flattened into the inner dimension of |
25 | 25 | the output. | the output. |
26 | 26 |
|
|
27 | 27 | **Type Constraints** | **Type Constraints** |
28 | 28 |
|
|
29 | 29 | * **T** in ( | * **T** in ( |
30 | tensor(bfloat16), | ||
30 | 31 | tensor(bool), | tensor(bool), |
31 | 32 | tensor(complex128), | tensor(complex128), |
32 | 33 | tensor(complex64), | tensor(complex64), |
33 | 34 | tensor(double), | tensor(double), |
34 | 35 | tensor(float), | tensor(float), |
35 | 36 | tensor(float16), | tensor(float16), |
36 | 37 | tensor(int16), | tensor(int16), |
37 | 38 | tensor(int32), | tensor(int32), |
38 | 39 | tensor(int64), | tensor(int64), |
39 | 40 | tensor(int8), | tensor(int8), |
40 | 41 | tensor(string), | tensor(string), |
41 | 42 | tensor(uint16), | tensor(uint16), |
42 | 43 | tensor(uint32), | tensor(uint32), |
43 | 44 | tensor(uint64), | tensor(uint64), |
44 | 45 | tensor(uint8) | tensor(uint8) |
45 | 46 | ): | ): |
46 | 47 | Constrain input and output to all tensor types. | Constrain input and output to all tensor types. |
Flatten - 11#
Version
name: Flatten (GitHub)
domain: main
since_version: 11
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 11.
Summary
Flattens the input tensor into a 2D matrix. If input tensor has shape (d_0, d_1, … d_n) then the output will have shape (d_0 X d_1 … d_(axis-1), d_axis X d_(axis+1) … X dn).
Attributes
axis: Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [-r, r], where r is the rank of the input tensor. Negative value means counting dimensions from the back. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 … d_n), where the shape of the input tensor is (d_0, d_1, … d_n). Default value is
1
.
Inputs
input (heterogeneous) - T: A tensor of rank >= axis.
Outputs
output (heterogeneous) - T: A 2D tensor with the contents of the input tensor, with input dimensions up to axis flattened to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output.
Type Constraints
T in ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output to all tensor types.
Differences
0 | 0 | Flattens the input tensor into a 2D matrix. If input tensor has shape | Flattens the input tensor into a 2D matrix. If input tensor has shape |
1 | 1 | (d_0, d_1, ... d_n) then the output will have shape | (d_0, d_1, ... d_n) then the output will have shape |
2 | 2 | (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). | (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). |
3 | 3 |
|
|
4 | 4 | **Attributes** | **Attributes** |
5 | 5 |
|
|
6 | 6 | * **axis**: | * **axis**: |
7 | 7 | Indicate up to which input dimensions (exclusive) should be | Indicate up to which input dimensions (exclusive) should be |
8 | 8 | flattened to the outer dimension of the output. The value for axis | flattened to the outer dimension of the output. The value for axis |
9 | 9 | must be in the range [0, R], where R is the rank of the input |
|
10 | tensor. Negative value means counting dimensions from the back. When | ||
10 | 11 | tensor. When axis = 0, the shape of the output tensor is (1, (d_0 X |
|
11 | 12 | d_1 ... d_n), where the shape of the input tensor is (d_0, d_1, ... |
|
12 | d_n). Default value is 1. | ||
13 | 13 |
|
|
14 | 14 | **Inputs** | **Inputs** |
15 | 15 |
|
|
16 | 16 | * **input** (heterogeneous) - **T**: | * **input** (heterogeneous) - **T**: |
17 | 17 | A tensor of rank >= axis. | A tensor of rank >= axis. |
18 | 18 |
|
|
19 | 19 | **Outputs** | **Outputs** |
20 | 20 |
|
|
21 | 21 | * **output** (heterogeneous) - **T**: | * **output** (heterogeneous) - **T**: |
22 | 22 | A 2D tensor with the contents of the input tensor, with input | A 2D tensor with the contents of the input tensor, with input |
23 | 23 | dimensions up to axis flattened to the outer dimension of the output | dimensions up to axis flattened to the outer dimension of the output |
24 | 24 | and remaining input dimensions flattened into the inner dimension of | and remaining input dimensions flattened into the inner dimension of |
25 | 25 | the output. | the output. |
26 | 26 |
|
|
27 | 27 | **Type Constraints** | **Type Constraints** |
28 | 28 |
|
|
29 | 29 | * **T** in ( | * **T** in ( |
30 | 30 | tensor(bool), | tensor(bool), |
31 | 31 | tensor(complex128), | tensor(complex128), |
32 | 32 | tensor(complex64), | tensor(complex64), |
33 | 33 | tensor(double), | tensor(double), |
34 | 34 | tensor(float), | tensor(float), |
35 | 35 | tensor(float16), | tensor(float16), |
36 | 36 | tensor(int16), | tensor(int16), |
37 | 37 | tensor(int32), | tensor(int32), |
38 | 38 | tensor(int64), | tensor(int64), |
39 | 39 | tensor(int8), | tensor(int8), |
40 | 40 | tensor(string), | tensor(string), |
41 | 41 | tensor(uint16), | tensor(uint16), |
42 | 42 | tensor(uint32), | tensor(uint32), |
43 | 43 | tensor(uint64), | tensor(uint64), |
44 | 44 | tensor(uint8) | tensor(uint8) |
45 | 45 | ): | ): |
46 | 46 | Constrain input and output to all tensor types. | Constrain input and output to all tensor types. |
Flatten - 9#
Version
name: Flatten (GitHub)
domain: main
since_version: 9
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 9.
Summary
Flattens the input tensor into a 2D matrix. If input tensor has shape (d_0, d_1, … d_n) then the output will have shape (d_0 X d_1 … d_(axis-1), d_axis X d_(axis+1) … X dn).
Attributes
axis: Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [0, R], where R is the rank of the input tensor. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 … d_n), where the shape of the input tensor is (d_0, d_1, … d_n). Default value is
1
.
Inputs
input (heterogeneous) - T: A tensor of rank >= axis.
Outputs
output (heterogeneous) - T: A 2D tensor with the contents of the input tensor, with input dimensions up to axis flattened to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output.
Type Constraints
T in ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output to all tensor types.
Differences
0 | 0 | Flattens the input tensor into a 2D matrix. If input tensor has shape | Flattens the input tensor into a 2D matrix. If input tensor has shape |
1 | 1 | (d_0, d_1, ... d_n) then the output will have shape | (d_0, d_1, ... d_n) then the output will have shape |
2 | 2 | (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). | (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). |
3 | 3 |
|
|
4 | 4 | **Attributes** | **Attributes** |
5 | 5 |
|
|
6 | 6 | * **axis**: | * **axis**: |
7 | 7 | Indicate up to which input dimensions (exclusive) should be | Indicate up to which input dimensions (exclusive) should be |
8 | 8 | flattened to the outer dimension of the output. The value for axis | flattened to the outer dimension of the output. The value for axis |
9 | 9 | must be in the range [0, R], where R is the rank of the input | must be in the range [0, R], where R is the rank of the input |
10 | 10 | tensor. When axis = 0, the shape of the output tensor is (1, (d_0 X | tensor. When axis = 0, the shape of the output tensor is (1, (d_0 X |
11 | 11 | d_1 ... d_n), where the shape of the input tensor is (d_0, d_1, ... | d_1 ... d_n), where the shape of the input tensor is (d_0, d_1, ... |
12 | 12 | d_n). Default value is 1. | d_n). Default value is 1. |
13 | 13 |
|
|
14 | 14 | **Inputs** | **Inputs** |
15 | 15 |
|
|
16 | 16 | * **input** (heterogeneous) - **T**: | * **input** (heterogeneous) - **T**: |
17 | 17 | A tensor of rank >= axis. | A tensor of rank >= axis. |
18 | 18 |
|
|
19 | 19 | **Outputs** | **Outputs** |
20 | 20 |
|
|
21 | 21 | * **output** (heterogeneous) - **T**: | * **output** (heterogeneous) - **T**: |
22 | 22 | A 2D tensor with the contents of the input tensor, with input | A 2D tensor with the contents of the input tensor, with input |
23 | 23 | dimensions up to axis flattened to the outer dimension of the output | dimensions up to axis flattened to the outer dimension of the output |
24 | 24 | and remaining input dimensions flattened into the inner dimension of | and remaining input dimensions flattened into the inner dimension of |
25 | 25 | the output. | the output. |
26 | 26 |
|
|
27 | 27 | **Type Constraints** | **Type Constraints** |
28 | 28 |
|
|
29 | 29 | * **T** in ( | * **T** in ( |
30 | tensor(bool), | ||
31 | tensor(complex128), | ||
32 | tensor(complex64), | ||
30 | 33 | tensor(double), | tensor(double), |
31 | 34 | tensor(float), | tensor(float), |
32 | 35 | tensor(float16) |
|
36 | tensor(int16), | ||
37 | tensor(int32), | ||
38 | tensor(int64), | ||
39 | tensor(int8), | ||
40 | tensor(string), | ||
41 | tensor(uint16), | ||
42 | tensor(uint32), | ||
43 | tensor(uint64), | ||
44 | tensor(uint8) | ||
33 | 45 | ): | ): |
34 | 46 | Constrain input and output types to float tensors. |
|
Flatten - 1#
Version
name: Flatten (GitHub)
domain: main
since_version: 1
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 1.
Summary
Flattens the input tensor into a 2D matrix. If input tensor has shape (d_0, d_1, … d_n) then the output will have shape (d_0 X d_1 … d_(axis-1), d_axis X d_(axis+1) … X dn).
Attributes
axis: Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [0, R], where R is the rank of the input tensor. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 … d_n), where the shape of the input tensor is (d_0, d_1, … d_n). Default value is
1
.
Inputs
input (heterogeneous) - T: A tensor of rank >= axis.
Outputs
output (heterogeneous) - T: A 2D tensor with the contents of the input tensor, with input dimensions up to axis flattened to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output.
Type Constraints
T in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors.