Clip#
Domain:
ai.onnxSince version: 13
Clip operator limits the given input within an interval. The interval is specified by the inputs ‘min’ and ‘max’. They default to numeric_limits::lowest() and numeric_limits::max(), respectively. When ‘min’ is greater than ‘max’, the clip operator sets all the ‘input’ values to the value of ‘max’. Thus, this is equivalent to ‘Min(max, Max(input, min))’.
Inputs
input (T): Input tensor whose elements to be clipped
min (T): Minimum value, under which element is replaced by min. It must be a scalar(tensor of empty shape).
max (T): Maximum value, above which element is replaced by max. It must be a scalar(tensor of empty shape).
Outputs
output (T): Output tensor with clipped input elements
Type Constraints
T: Constrain input and output types to all numeric tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).
Examples#
test_cc_clip
Node:
Clip(x, min, max) -> (y)
Inputs:
x: shape=(5,), dtype=float32
[-2. , -0.5, 0. , 0.5, 2. ]
min: shape=(), dtype=float32
-1.
max: shape=(), dtype=float32
1.
Outputs:
y: shape=(5,), dtype=float32
[-1. , -0.5, 0. , 0.5, 1. ]
test_clip
Node:
Clip(x, min, max) -> (y)
Inputs:
x: shape=(3, 4, 5), dtype=float32
[[[ 1.4243481 , -0.61890423, -0.5907667 , 1.4329695 , 0.5837956 ],
[-1.3854368 , 1.2791865 , 0.32735094, 0.6038593 , 0.24222691],
[-0.89236253, -1.1303798 , -0.09180629, -0.12591071, -1.2615176 ],
[-0.55638343, -0.747256 , -0.59118223, -0.9279915 , -0.73401135]],
[[ 1.1054384 , -0.69560546, -2.1534553 , 0.11396561, -0.8268097 ],
[ 1.2137318 , -0.22223468, 0.32949635, -0.21049212, 1.3518724 ],
[ 0.01262847, 0.6841954 , -1.2623075 , 0.20052178, -1.1255072 ],
[-0.6395738 , 1.5355366 , -1.1466801 , -0.42676184, -0.74427605]],
[[-1.5989435 , 2.3646672 , -1.0641551 , 0.90345967, -0.24993172],
[-1.784248 , -0.47239977, 0.09873669, -0.36464727, 0.6651279 ],
[-1.01641 , -0.39525023, 0.45574856, -0.3439513 , -0.5487247 ],
[ 0.06280329, -0.14411083, -1.1603392 , 0.49200374, -0.16951095]]]
min: shape=(), dtype=float32
-1.
max: shape=(), dtype=float32
1.
Outputs:
y: shape=(3, 4, 5), dtype=float32
[[[ 1. , -0.61890423, -0.5907667 , 1. , 0.5837956 ],
[-1. , 1. , 0.32735094, 0.6038593 , 0.24222691],
[-0.89236253, -1. , -0.09180629, -0.12591071, -1. ],
[-0.55638343, -0.747256 , -0.59118223, -0.9279915 , -0.73401135]],
[[ 1. , -0.69560546, -1. , 0.11396561, -0.8268097 ],
[ 1. , -0.22223468, 0.32949635, -0.21049212, 1. ],
[ 0.01262847, 0.6841954 , -1. , 0.20052178, -1. ],
[-0.6395738 , 1. , -1. , -0.42676184, -0.74427605]],
[[-1. , 1. , -1. , 0.90345967, -0.24993172],
[-1. , -0.47239977, 0.09873669, -0.36464727, 0.6651279 ],
[-1. , -0.39525023, 0.45574856, -0.3439513 , -0.5487247 ],
[ 0.06280329, -0.14411083, -1. , 0.49200374, -0.16951095]]]
test_clip_default_inbounds
Node:
Clip(x) -> (y)
Inputs:
x: shape=(3,), dtype=float32
[-1., 0., 1.]
Outputs:
y: shape=(3,), dtype=float32
[-1., 0., 1.]
test_clip_default_max
Node:
Clip(x, "", max) -> (y)
Inputs:
x: shape=(3, 4, 5), dtype=float32
[[[ 0.16602525, 0.11929144, 0.5103543 , -0.07833039, -0.2179262 ],
[-0.35897505, -0.9920161 , 1.1369699 , 0.15822072, -0.66695 ],
[ 0.1640578 , 0.5148549 , 0.692694 , 1.2886952 , -2.3116457 ],
[-0.3991889 , -1.763249 , -0.46325874, 1.1941477 , 0.1423654 ]],
[[-0.7589299 , 1.5638951 , -1.3538998 , -0.78615636, -0.7008719 ],
[-0.49739143, 1.2461402 , -0.824719 , -1.2749853 , -0.44074798],
[ 1.8726983 , -1.2862704 , 0.38438547, 1.782237 , -0.76287836],
[-0.53627247, -2.1623473 , 0.3568203 , 0.67731917, -0.40523142]],
[[ 2.2794771 , -1.7118682 , 0.17869362, -0.12453986, 0.51542616],
[-0.34672984, -0.04749961, -1.1327435 , 0.7626039 , -0.18739803],
[-0.31375307, -1.0803736 , 0.05428931, 0.53482765, -0.33528003],
[-1.5306095 , -0.61205 , -1.8999155 , 1.1543474 , -0.30809247]]]
max: shape=(), dtype=float32
0.
Outputs:
y: shape=(3, 4, 5), dtype=float32
[[[ 0. , 0. , 0. , -0.07833039, -0.2179262 ],
[-0.35897505, -0.9920161 , 0. , 0. , -0.66695 ],
[ 0. , 0. , 0. , 0. , -2.3116457 ],
[-0.3991889 , -1.763249 , -0.46325874, 0. , 0. ]],
[[-0.7589299 , 0. , -1.3538998 , -0.78615636, -0.7008719 ],
[-0.49739143, 0. , -0.824719 , -1.2749853 , -0.44074798],
[ 0. , -1.2862704 , 0. , 0. , -0.76287836],
[-0.53627247, -2.1623473 , 0. , 0. , -0.40523142]],
[[ 0. , -1.7118682 , 0. , -0.12453986, 0. ],
[-0.34672984, -0.04749961, -1.1327435 , 0. , -0.18739803],
[-0.31375307, -1.0803736 , 0. , 0. , -0.33528003],
[-1.5306095 , -0.61205 , -1.8999155 , 0. , -0.30809247]]]
test_clip_default_min
Node:
Clip(x, min) -> (y)
Inputs:
x: shape=(3, 4, 5), dtype=float32
[[[ 0.5802847 , -1.4953256 , 0.42665341, 0.16854794, -0.7854995 ],
[-0.3418555 , -0.1149836 , 0.95487213, 1.3025413 , 0.5168173 ],
[-0.6690302 , 0.806894 , -0.2736855 , -0.47230572, 1.3611885 ],
[-1.6060044 , -1.2981083 , 0.58045334, -0.13972436, -0.35279942]],
[[ 0.63143295, -0.770354 , 0.3310645 , 0.32500747, -0.91997206],
[-0.51626676, -0.31889752, -1.4302723 , 0.6759698 , -0.7796309 ],
[-0.5247361 , -0.12912966, -0.40980053, -0.36663505, 0.8133978 ],
[-0.12241841, 1.2133354 , 1.0200249 , 1.4152457 , 0.62612057]],
[[ 2.0329802 , -0.90274274, 1.2706685 , -0.04628804, -1.3271873 ],
[ 0.2806637 , -0.9965783 , -0.57684577, 1.7659245 , -0.6384131 ],
[ 0.14784828, 0.08228748, 0.4838705 , 0.6750839 , -1.2548709 ],
[ 0.79701257, -0.5844758 , 0.3095379 , 1.2291852 , 2.0687242 ]]]
min: shape=(), dtype=float32
0.
Outputs:
y: shape=(3, 4, 5), dtype=float32
[[[0.5802847 , 0. , 0.42665341, 0.16854794, 0. ],
[0. , 0. , 0.95487213, 1.3025413 , 0.5168173 ],
[0. , 0.806894 , 0. , 0. , 1.3611885 ],
[0. , 0. , 0.58045334, 0. , 0. ]],
[[0.63143295, 0. , 0.3310645 , 0.32500747, 0. ],
[0. , 0. , 0. , 0.6759698 , 0. ],
[0. , 0. , 0. , 0. , 0.8133978 ],
[0. , 1.2133354 , 1.0200249 , 1.4152457 , 0.62612057]],
[[2.0329802 , 0. , 1.2706685 , 0. , 0. ],
[0.2806637 , 0. , 0. , 1.7659245 , 0. ],
[0.14784828, 0.08228748, 0.4838705 , 0.6750839 , 0. ],
[0.79701257, 0. , 0.3095379 , 1.2291852 , 2.0687242 ]]]
test_clip_example
Node:
Clip(x, min, max) -> (y)
Inputs:
x: shape=(3,), dtype=float32
[-2., 0., 2.]
min: shape=(), dtype=float32
-1.
max: shape=(), dtype=float32
1.
Outputs:
y: shape=(3,), dtype=float32
[-1., 0., 1.]
test_clip_inbounds
Node:
Clip(x, min, max) -> (y)
Inputs:
x: shape=(3,), dtype=float32
[-1., 0., 1.]
min: shape=(), dtype=float32
-5.
max: shape=(), dtype=float32
5.
Outputs:
y: shape=(3,), dtype=float32
[-1., 0., 1.]
test_clip_min_greater_than_max
Node:
Clip(x, min, max) -> (y)
Inputs:
x: shape=(3,), dtype=float32
[-2., 0., 6.]
min: shape=(), dtype=float32
2.
max: shape=(), dtype=float32
1.
Outputs:
y: shape=(3,), dtype=float32
[1., 1., 1.]
test_clip_outbounds
Node:
Clip(x, min, max) -> (y)
Inputs:
x: shape=(3,), dtype=float32
[-6., 0., 6.]
min: shape=(), dtype=float32
-5.
max: shape=(), dtype=float32
5.
Outputs:
y: shape=(3,), dtype=float32
[-5., 0., 5.]
test_clip_splitbounds
Node:
Clip(x, min, max) -> (y)
Inputs:
x: shape=(3,), dtype=float32
[-1., 0., 6.]
min: shape=(), dtype=float32
-5.
max: shape=(), dtype=float32
5.
Outputs:
y: shape=(3,), dtype=float32
[-1., 0., 5.]
Differences with previous version (12)#
SchemaDiff: Clip (domain 'ai.onnx')
old version: 12
new version: 13
breaking: no
Type constraints:
changed ‘T’: added types: [‘tensor(bfloat16)’]
Documentation:
line similarity: 0.80 (+2/-0 lines)
--- Clip v12
+++ Clip v13
@@ -2,3 +2,5 @@
Clip operator limits the given input within an interval. The interval is
specified by the inputs 'min' and 'max'. They default to
numeric_limits::lowest() and numeric_limits::max(), respectively.
+When 'min' is greater than 'max', the clip operator sets all the 'input' values to
+the value of 'max'. Thus, this is equivalent to 'Min(max, Max(input, min))'.