Split#

  • Domain: ai.onnx

  • Since version: 18

Split a tensor into a list of tensors, along the specified ‘axis’. Either input ‘split’ or the attribute ‘num_outputs’ should be specified, but not both. If the attribute ‘num_outputs’ is specified, then the tensor is split into equal sized parts. If the tensor is not evenly splittable into num_outputs, the last chunk will be smaller. If the input ‘split’ is specified, it indicates the sizes of each output in the split.

Inputs

  • input (T): The tensor to split

  • split (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 ∞ outputs.

  • outputs (T): One or more outputs forming list of tensors after splitting

Attributes

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

  • num_outputs (int): Number of outputs to split parts of the tensor into. If the tensor is not evenly splittable the last chunk will be smaller.

Type Constraints

  • T: Constrain input and output types to all tensor types. Allowed types: 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).

Examples#

test_cc_shape_inference_concat_split_even

Node:
  Split(xy) -> (S1, S2)
  Attributes:
    axis = 1
    num_outputs = 2
Inputs:
  xy: shape=(3, 4), dtype=float32
    [[-1.        , -0.9       , -0.8       , -0.7       ],
     [-0.6       , -0.5       , -0.39999998, -0.3       ],
     [-0.19999999, -0.09999996,  0.        ,  0.10000002]]
  input_1: shape=(3, 6), dtype=float32
    [[-0.5       , -0.3       , -0.09999999,  0.10000002,  0.3       ,  0.5       ],
     [ 0.70000005,  0.9       ,  1.1       ,  1.3000001 ,  1.5       ,  1.7       ],
     [ 1.9000001 ,  2.1000001 ,  2.3       ,  2.5       ,  2.7       ,  2.9       ]]

Outputs:
  S1: shape=(3, 10), dtype=float32
    [[0.        , 0.        , 0.10000002, 0.3       , 0.5       , 0.        ,
      0.        , 0.        , 0.        , 0.        ],
     [0.9       , 1.1       , 1.3000001 , 1.5       , 1.7       , 0.        ,
      0.        , 0.        , 0.        , 0.70000005],
     [2.1000001 , 2.3       , 2.5       , 2.7       , 2.9       , 0.        ,
      0.        , 0.        , 0.10000002, 1.9000001 ]]

test_cc_shape_inference_concat_split_odd

Node:
  Split(xy) -> (S1, S2)
  Attributes:
    axis = 1
    num_outputs = 2
Inputs:
  xy: shape=(3, 4), dtype=float32
    [[-1.        , -0.9       , -0.8       , -0.7       ],
     [-0.6       , -0.5       , -0.39999998, -0.3       ],
     [-0.19999999, -0.09999996,  0.        ,  0.10000002]]
  input_1: shape=(3, 6), dtype=float32
    [[-0.5       , -0.3       , -0.09999999,  0.10000002,  0.3       ,  0.5       ],
     [ 0.70000005,  0.9       ,  1.1       ,  1.3000001 ,  1.5       ,  1.7       ],
     [ 1.9000001 ,  2.1000001 ,  2.3       ,  2.5       ,  2.7       ,  2.9       ]]

Outputs:
  S1: shape=(3, 10), dtype=float32
    [[0.        , 0.        , 0.10000002, 0.3       , 0.5       , 0.        ,
      0.        , 0.        , 0.        , 0.        ],
     [0.9       , 1.1       , 1.3000001 , 1.5       , 1.7       , 0.        ,
      0.        , 0.        , 0.        , 0.70000005],
     [2.1000001 , 2.3       , 2.5       , 2.7       , 2.9       , 0.        ,
      0.        , 0.        , 0.10000002, 1.9000001 ]]

test_cc_split_1d_uneven_split_opset18

Node:
  Split(input) -> (output_1, output_2, output_3, output_4)
  Attributes:
    num_outputs = 4
Inputs:
  input: shape=(7,), dtype=float32
    [1., 2., 3., 4., 5., 6., 7.]

Outputs:
  output_1: shape=(2,), dtype=float32
    [1., 2.]
  output_2: shape=(2,), dtype=float32
    [3., 4.]
  output_3: shape=(2,), dtype=float32
    [5., 6.]
  output_4: shape=(1,), dtype=float32
    [7.]

test_cc_split_2d_uneven_split_opset18

Node:
  Split(input) -> (output_1, output_2, output_3)
  Attributes:
    axis = 1
    num_outputs = 3
Inputs:
  input: shape=(2, 8), dtype=float32
    [[ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.],
     [ 9., 10., 11., 12., 13., 14., 15., 16.]]

Outputs:
  output_1: shape=(2, 3), dtype=float32
    [[ 1.,  2.,  3.],
     [ 9., 10., 11.]]
  output_2: shape=(2, 3), dtype=float32
    [[ 4.,  5.,  6.],
     [12., 13., 14.]]
  output_3: shape=(2, 2), dtype=float32
    [[ 7.,  8.],
     [15., 16.]]

test_cc_split_equal_parts_1d_opset18

Node:
  Split(input) -> (output_1, output_2, output_3)
  Attributes:
    axis = 0
    num_outputs = 3
Inputs:
  input: shape=(6,), dtype=float32
    [1., 2., 3., 4., 5., 6.]

Outputs:
  output_1: shape=(2,), dtype=float32
    [1., 2.]
  output_2: shape=(2,), dtype=float32
    [3., 4.]
  output_3: shape=(2,), dtype=float32
    [5., 6.]

test_cc_split_equal_parts_2d

Node:
  Split(input) -> (output_1, output_2)
  Attributes:
    axis = 1
    num_outputs = 2
Inputs:
  input: shape=(2, 6), dtype=float32
    [[ 1.,  2.,  3.,  4.,  5.,  6.],
     [ 7.,  8.,  9., 10., 11., 12.]]

Outputs:
  output_1: shape=(2, 3), dtype=float32
    [[1., 2., 3.],
     [7., 8., 9.]]
  output_2: shape=(2, 3), dtype=float32
    [[ 4.,  5.,  6.],
     [10., 11., 12.]]

test_cc_split_equal_parts_default_axis_opset18

Node:
  Split(input) -> (output_1, output_2, output_3)
  Attributes:
    num_outputs = 3
Inputs:
  input: shape=(6,), dtype=float32
    [1., 2., 3., 4., 5., 6.]

Outputs:
  output_1: shape=(2,), dtype=float32
    [1., 2.]
  output_2: shape=(2,), dtype=float32
    [3., 4.]
  output_3: shape=(2,), dtype=float32
    [5., 6.]

test_cc_split_variable_parts_1d_opset18

Node:
  Split(input, split) -> (output_1, output_2)
  Attributes:
    axis = 0
Inputs:
  input: shape=(6,), dtype=float32
    [1., 2., 3., 4., 5., 6.]
  split: shape=(2,), dtype=int64
    [2, 4]

Outputs:
  output_1: shape=(2,), dtype=float32
    [1., 2.]
  output_2: shape=(4,), dtype=float32
    [3., 4., 5., 6.]

test_cc_split_variable_parts_2d_opset18

Node:
  Split(input, split) -> (output_1, output_2)
  Attributes:
    axis = 1
Inputs:
  input: shape=(2, 6), dtype=float32
    [[ 1.,  2.,  3.,  4.,  5.,  6.],
     [ 7.,  8.,  9., 10., 11., 12.]]
  split: shape=(2,), dtype=int64
    [2, 4]

Outputs:
  output_1: shape=(2, 2), dtype=float32
    [[1., 2.],
     [7., 8.]]
  output_2: shape=(2, 4), dtype=float32
    [[ 3.,  4.,  5.,  6.],
     [ 9., 10., 11., 12.]]

test_cc_split_variable_parts_default_axis_opset18

Node:
  Split(input, split) -> (output_1, output_2)
Inputs:
  input: shape=(6,), dtype=float32
    [1., 2., 3., 4., 5., 6.]
  split: shape=(2,), dtype=int64
    [2, 4]

Outputs:
  output_1: shape=(2,), dtype=float32
    [1., 2.]
  output_2: shape=(4,), dtype=float32
    [3., 4., 5., 6.]

test_cc_split_zero_size_splits_opset18

Node:
  Split(input, split) -> (output_1, output_2, output_3)
Inputs:
  input: shape=(0,), dtype=float32
    []
  split: shape=(3,), dtype=int64
    [0, 0, 0]

Outputs:
  output_1: shape=(0,), dtype=float32
    []
  output_2: shape=(0,), dtype=float32
    []
  output_3: shape=(0,), dtype=float32
    []

Differences with previous version (13)#

SchemaDiff: Split (domain 'ai.onnx')

  • old version: 13

  • new version: 18

  • breaking: no

Attributes:

  • added ‘num_outputs’: type=INT; required=False; default=UNDEFINED

Documentation:

  • line similarity: 0.00 (+5/-3 lines)

--- Split v13
+++ Split v18
@@ -1,3 +1,5 @@
-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.
+Split a tensor into a list of tensors, along the specified 'axis'.
+Either input 'split' or the attribute 'num_outputs' should be specified, but not both.
+If the attribute 'num_outputs' is specified, then the tensor is split into equal sized parts.
+If the tensor is not evenly splittable into `num_outputs`, the last chunk will be smaller.
+If the input 'split' is specified, it indicates the sizes of each output in the split.

Version History#