Compress#
Domain:
ai.onnxSince version: 11
Selects slices from an input tensor along a given axis value passed.
In case axis is not provided, input is flattened before elements being selected. Positive value means counting dimensions from the front. Negative value means counting dimensions from the back. Compress behaves like numpy.compress: https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html
Inputs
input (T): Tensor of rank r >= 1.
condition (T1): Rank 1 tensor of booleans to indicate which slices or data elements to be selected. Its length can be less than the input length along the axis or the flattened input size if axis is not specified. In such cases data slices or elements exceeding the condition length are discarded.
Outputs
output (T): Tensor of rank r if axis is specified. Otherwise output is a Tensor of rank 1.
Attributes
axis (int): (Optional) Axis along which to take slices. If not specified, input is flattened before elements being selected. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
Type Constraints
T: Constrain input and output types to all tensor types. Allowed types: 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).
T1: Constrain to boolean tensors. Allowed types: tensor(bool).
Examples#
test_cc_compress_0
Node:
Compress(input, condition) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(3, 2), dtype=float32
[[1., 2.],
[3., 4.],
[5., 6.]]
condition: shape=(3,), dtype=bool
[False, True, True]
Outputs:
output: shape=(2, 2), dtype=float32
[[3., 4.],
[5., 6.]]
test_cc_compress_1
Node:
Compress(input, condition) -> (output)
Attributes:
axis = 1
Inputs:
input: shape=(3, 2), dtype=float32
[[1., 2.],
[3., 4.],
[5., 6.]]
condition: shape=(2,), dtype=bool
[False, True]
Outputs:
output: shape=(3, 1), dtype=float32
[[2.],
[4.],
[6.]]
test_cc_compress_axis0
Node:
Compress(input, condition) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(3, 2), dtype=float32
[[1., 2.],
[3., 4.],
[5., 6.]]
condition: shape=(3,), dtype=bool
[ True, False, True]
Outputs:
output: shape=(2, 2), dtype=float32
[[1., 2.],
[5., 6.]]
test_cc_compress_axis1
Node:
Compress(input, condition) -> (output)
Attributes:
axis = 1
Inputs:
input: shape=(3, 2), dtype=float32
[[1., 2.],
[3., 4.],
[5., 6.]]
condition: shape=(2,), dtype=bool
[False, True]
Outputs:
output: shape=(3, 1), dtype=float32
[[2.],
[4.],
[6.]]
test_cc_compress_default_axis
Node:
Compress(input, condition) -> (output)
Inputs:
input: shape=(3, 2), dtype=float32
[[1., 2.],
[3., 4.],
[5., 6.]]
condition: shape=(5,), dtype=bool
[False, True, False, False, True]
Outputs:
output: shape=(2,), dtype=float32
[2., 5.]
test_cc_compress_empty_shape_axis0_all_false
Node:
Compress(input, condition) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(3, 2), dtype=float32
[[1., 2.],
[3., 4.],
[5., 6.]]
condition: shape=(3,), dtype=bool
[False, False, False]
Outputs:
output: shape=(0, 2), dtype=float32
[]
test_cc_compress_empty_shape_input_zero_dim
Node:
Compress(input, condition) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(0, 2), dtype=float32
[]
condition: shape=(0,), dtype=bool
[]
Outputs:
output: shape=(0, 2), dtype=float32
[]
test_cc_compress_empty_shape_no_axis_all_false
Node:
Compress(input, condition) -> (output)
Inputs:
input: shape=(3, 2), dtype=float32
[[1., 2.],
[3., 4.],
[5., 6.]]
condition: shape=(6,), dtype=bool
[False, False, False, False, False, False]
Outputs:
output: shape=(0,), dtype=float32
[]
test_cc_compress_int64
Node:
Compress(input, condition) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(3,), dtype=int64
[10, 20, 30]
condition: shape=(3,), dtype=bool
[False, True, True]
Outputs:
output: shape=(2,), dtype=int64
[20, 30]
test_cc_compress_negative_axis
Node:
Compress(input, condition) -> (output)
Attributes:
axis = -1
Inputs:
input: shape=(2, 3), dtype=float32
[[1., 2., 3.],
[4., 5., 6.]]
condition: shape=(3,), dtype=bool
[ True, False, True]
Outputs:
output: shape=(2, 2), dtype=float32
[[1., 3.],
[4., 6.]]
test_cc_compress_no_axis
Node:
Compress(input, condition) -> (output)
Inputs:
input: shape=(3, 2), dtype=float32
[[1., 2.],
[3., 4.],
[5., 6.]]
condition: shape=(6,), dtype=bool
[ True, False, True, True, False, False]
Outputs:
output: shape=(3,), dtype=float32
[1., 3., 4.]
test_cc_compress_short_condition
Node:
Compress(input, condition) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(4, 2), dtype=float32
[[1., 2.],
[3., 4.],
[5., 6.],
[7., 8.]]
condition: shape=(2,), dtype=bool
[ True, False]
Outputs:
output: shape=(1, 2), dtype=float32
[[1., 2.]]
Differences with previous version (9)#
SchemaDiff: Compress (domain 'ai.onnx')
old version: 9
new version: 11
breaking: no
Documentation:
line similarity: 0.77 (+2/-1 lines)
--- Compress v9
+++ Compress v11
@@ -2,5 +2,6 @@
Selects slices from an input tensor along a given axis value passed.
In case axis is not provided, input is flattened before elements being selected.
-
+Positive value means counting dimensions from the front.
+Negative value means counting dimensions from the back.
Compress behaves like numpy.compress: https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html