Skip to content

Commit

Permalink
clarify clip with min>max
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Eichenberger <[email protected]>
  • Loading branch information
AlexandreEichenberger committed Sep 26, 2024
1 parent d14634e commit f7b0d02
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15167,6 +15167,8 @@ This version of the operator has been available since version 13 of the default
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'.

#### Version

Expand Down
13 changes: 13 additions & 0 deletions docs/Operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -4549,6 +4549,8 @@ expect(node, inputs=[x, shape], outputs=[y], name="test_center_crop_pad_pad")
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'.

#### Version

Expand Down Expand Up @@ -4634,6 +4636,17 @@ expect(
outputs=[y],
name="test_clip_splitbounds",
)

x = np.array([-2, 0, 6]).astype(np.float32)
y = np.array([1, 1, 1]).astype(np.float32)
min_val = np.float32(2)
max_val = np.float32(1)
expect(
node,
inputs=[x, min_val, max_val],
outputs=[y],
name="test_clip_min_greater_than_max",
)
```

</details>
Expand Down
11 changes: 11 additions & 0 deletions docs/TestCoverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3283,6 +3283,17 @@ expect(
outputs=[y],
name="test_clip_splitbounds",
)

x = np.array([-2, 0, 6]).astype(np.float32)
y = np.array([1, 1, 1]).astype(np.float32)
min_val = np.float32(2)
max_val = np.float32(1)
expect(
node,
inputs=[x, min_val, max_val],
outputs=[y],
name="test_clip_min_greater_than_max",
)
```

</details>
Expand Down
11 changes: 11 additions & 0 deletions onnx/backend/test/case/node/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ def export() -> None:
name="test_clip_splitbounds",
)

x = np.array([-2, 0, 6]).astype(np.float32)
y = np.array([1, 1, 1]).astype(np.float32)
min_val = np.float32(2)
max_val = np.float32(1)
expect(
node,
inputs=[x, min_val, max_val],
outputs=[y],
name="test_clip_min_greater_than_max",
)

@staticmethod
def export_clip_default() -> None:
node = onnx.helper.make_node(
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions onnx/defs/math/defs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,8 @@ static const char* Clip_ver13_doc = R"DOC(
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'.
)DOC";

bool BuildContextDependentFunctionBodyClip(
Expand Down

0 comments on commit f7b0d02

Please sign in to comment.