Split

Split - 13

Version

  • name: Split (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

Split a tensor into a list of tensors, along the specified ‘axis’. Lengths of the parts can be specified using input ‘split’. Otherwise, the tensor is split to equal sized parts.

Attributes

  • axis: Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1] where r = rank(input).

Inputs

Between 1 and 2 inputs.

  • input (heterogeneous) - T: The tensor to split

  • split (optional, heterogeneous) - tensor(int64): Optional length of each output. Values should be >= 0.Sum of the values must be equal to the dim value at ‘axis’ specified.

Outputs

Between 1 and 2147483647 outputs.

  • outputs (variadic, heterogeneous) - T: One or more outputs forming list of tensors after splitting

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 types to all tensor types.

Examples

_1d

import numpy as np
import onnx

input = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).astype(np.float32)

node = onnx.helper.make_node(
    "Split",
    inputs=["input"],
    outputs=["output_1", "output_2", "output_3"],
    axis=0,
)

expected_outputs = [
    np.array([1.0, 2.0]).astype(np.float32),
    np.array([3.0, 4.0]).astype(np.float32),
    np.array([5.0, 6.0]).astype(np.float32),
]
expect(
    node,
    inputs=[input],
    outputs=[y for y in expected_outputs],
    name="test_split_equal_parts_1d",
)

split = np.array([2, 4]).astype(np.int64)
node = onnx.helper.make_node(
    "Split",
    inputs=["input", "split"],
    outputs=["output_1", "output_2"],
    axis=0,
)

expected_outputs = [
    np.array([1.0, 2.0]).astype(np.float32),
    np.array([3.0, 4.0, 5.0, 6.0]).astype(np.float32),
]
expect(
    node,
    inputs=[input, split],
    outputs=[y for y in expected_outputs],
    name="test_split_variable_parts_1d",
)

_2d

import numpy as np
import onnx

input = np.array(
    [[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [7.0, 8.0, 9.0, 10.0, 11.0, 12.0]]
).astype(np.float32)

node = onnx.helper.make_node(
    "Split", inputs=["input"], outputs=["output_1", "output_2"], axis=1
)

expected_outputs = [
    np.array([[1.0, 2.0, 3.0], [7.0, 8.0, 9.0]]).astype(np.float32),
    np.array([[4.0, 5.0, 6.0], [10.0, 11.0, 12.0]]).astype(np.float32),
]

expect(
    node,
    inputs=[input],
    outputs=[y for y in expected_outputs],
    name="test_split_equal_parts_2d",
)

split = np.array([2, 4]).astype(np.int64)
node = onnx.helper.make_node(
    "Split",
    inputs=["input", "split"],
    outputs=["output_1", "output_2"],
    axis=1,
)

expected_outputs = [
    np.array([[1.0, 2.0], [7.0, 8.0]]).astype(np.float32),
    np.array([[3.0, 4.0, 5.0, 6.0], [9.0, 10.0, 11.0, 12.0]]).astype(
        np.float32
    ),
]

expect(
    node,
    inputs=[input, split],
    outputs=[y for y in expected_outputs],
    name="test_split_variable_parts_2d",
)

_default_values

import numpy as np
import onnx

input = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).astype(np.float32)

# If axis is not specified, split is applied on default axis 0
node = onnx.helper.make_node(
    "Split", inputs=["input"], outputs=["output_1", "output_2", "output_3"]
)

expected_outputs = [
    np.array([1.0, 2.0]).astype(np.float32),
    np.array([3.0, 4.0]).astype(np.float32),
    np.array([5.0, 6.0]).astype(np.float32),
]
expect(
    node,
    inputs=[input],
    outputs=[y for y in expected_outputs],
    name="test_split_equal_parts_default_axis",
)

split = np.array([2, 4]).astype(np.int64)
node = onnx.helper.make_node(
    "Split", inputs=["input", "split"], outputs=["output_1", "output_2"]
)

expected_outputs = [
    np.array([1.0, 2.0]).astype(np.float32),
    np.array([3.0, 4.0, 5.0, 6.0]).astype(np.float32),
]
expect(
    node,
    inputs=[input, split],
    outputs=[y for y in expected_outputs],
    name="test_split_variable_parts_default_axis",
)

_zero_size_splits

import numpy as np
import onnx

input = np.array([]).astype(np.float32)

# Split emtpy tensor to tensors of size zero
split = np.array([0, 0, 0]).astype(np.int64)
node = onnx.helper.make_node(
    "Split",
    inputs=["input", "split"],
    outputs=["output_1", "output_2", "output_3"],
)

expected_outputs = [
    np.array([]).astype(np.float32),
    np.array([]).astype(np.float32),
    np.array([]).astype(np.float32),
]
expect(
    node,
    inputs=[input, split],
    outputs=[y for y in expected_outputs],
    name="test_split_zero_size_splits",
)

Split - 11

Version

  • name: Split (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

Split a tensor into a list of tensors, along the specified ‘axis’. Lengths of the parts can be specified using argument ‘split’. Otherwise, the tensor is split to equal sized parts.

Attributes

  • axis: Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1] where r = rank(input).

  • split: length of each output. Values should be >= 0.

Inputs

  • input (heterogeneous) - T: The tensor to split

Outputs

Between 1 and 2147483647 outputs.

  • outputs (variadic, heterogeneous) - T: One or more outputs forming list of tensors after splitting

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 types to all tensor types.

Split - 2

Version

  • name: Split (GitHub)

  • domain: main

  • since_version: 2

  • function: False

  • support_level: SupportType.COMMON

  • shape inference: True

This version of the operator has been available since version 2.

Summary

Split a tensor into a list of tensors, along the specified ‘axis’. Lengths of the parts can be specified using argument ‘split’. Otherwise, the tensor is split to equal sized parts.

Attributes

  • axis: Which axis to split on.

  • split: length of each output

Inputs

  • input (heterogeneous) - T: The tensor to split

Outputs

Between 1 and 2147483647 outputs.

  • outputs (variadic, heterogeneous) - T: One or more outputs forming list of tensors after splitting

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 types to all tensor types.

Split - 1

Version

  • name: Split (GitHub)

  • domain: main

  • since_version: 1

  • function: False

  • support_level: SupportType.COMMON

  • shape inference: False

This version of the operator has been available since version 1.

Summary

Split a tensor into a list of tensors, along the specified ‘axis’. The lengths of the split can be specified using argument ‘axis’ or optional second input blob to the operator. Otherwise, the tensor is split to equal sized parts.

Attributes

  • axis: Which axis to split on

  • split: length of each output

Inputs

Between 1 and 2 inputs.

  • input (heterogeneous) - T: The tensor to split

  • split (optional, heterogeneous) - T: Optional list of output lengths (see also arg ‘split’)

Outputs

Between 1 and 2147483647 outputs.

  • outputs… (variadic, heterogeneous) - T: One or more outputs forming list of tensors after splitting

Type Constraints

  • T in ( tensor(double), tensor(float), tensor(float16) ): Constrain input types to float tensors.