-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor ivy.clip
function
#21997
Refactor ivy.clip
function
#21997
Changes from 24 commits
8529e70
1b42810
ffc1c03
58e4f87
b52439b
fa78c2a
4826b34
f32e749
767a185
6a56f2e
889c2c3
889eb54
9e91d49
6123ab0
27bd292
8998658
679e6af
8b56aa6
435fed7
783bfb3
07916c6
fde68c1
a4317f1
8a64392
5eb5aeb
3822b5a
00ade6f
f677a05
69d79fe
1202347
eb1c4a3
7536469
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
"""Collection of tests for manipulation functions.""" | ||
|
||
# global | ||
|
||
import numpy as np | ||
from hypothesis import strategies as st, assume | ||
|
||
|
@@ -340,10 +339,18 @@ def _basic_min_x_max(draw): | |
available_dtypes=helpers.get_dtypes("numeric"), | ||
) | ||
) | ||
min_val = draw(helpers.array_values(dtype=dtype[0], shape=())) | ||
min_val = draw( | ||
st.one_of(st.just(None), helpers.array_values(dtype=dtype[0], shape=())) | ||
) | ||
NripeshN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
max_val = draw( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we update |
||
helpers.array_values(dtype=dtype[0], shape=()).filter(lambda x: x > min_val) | ||
st.one_of(st.just(None), helpers.array_values(dtype=dtype[0], shape=())) | ||
) | ||
if min_val is None and max_val is None: | ||
generate_max = draw(st.booleans()) | ||
if generate_max: | ||
max_val = draw(helpers.array_values(dtype=dtype[0], shape=())) | ||
else: | ||
min_val = draw(helpers.array_values(dtype=dtype[0], shape=())) | ||
return [dtype], (value[0], min_val, max_val) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I follow why we need an else case here since
x_min is not None and x_max is not None and x_min > x_max
case (i.enot cond
) can be handled bytf.experimental.numpy.clip
as well, right? Maybe I'm missing something here..Also, it looks like the frontend tests are failing because of
cond
with the following error:This is because
x_min
andx_max
can also be arrays.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, sorry missed the fact that they could be arrays too, I think
.any
should be able to resolve this.tf.experimental.numpy.clip
also followstf.clip_by_value
behaviour whenx_min>x_max
, which we discussed in the above comments. I think the only difference is numpy namespace and the fact that it can acceptNone
. You can verify this from the following code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's interesting. I expected
tf.experimental.numpy.clip
to behave exactly the same asnp.clip
.