-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
BUG: Issue 5354 - Fixed segmentation fault when clipping complex arrays #5386
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
Conversation
This one looks better already:) |
@maniteja123 this segfaults on linux as well, so I assume you tested it and the fix works for you? If so, can you add the example of gh-5385 as a regression test? You can put it in |
And like I commented on the other PR, just delete these two lines instead of commenting them out. |
Side note: C++ style ( |
cf4a998
to
33e1f1b
Compare
@rgommers Thanks for the advice. I have deleted the files and pushed it to the branch. Also, from next time I will make sure to follow the coding style guidelines. I was confused whether to delete the lines or not, so I commented them. |
I have tested it by changing the file in inplace build and tested the example used in the issue #5354 to check whether seg fault is occurring or not . I have looked at the test_regressiontest.py file, but I am not particularly sure how to define the test functions and then assert statements. I have read the https://github.com/numpy/numpy/blob/master/doc/TESTS.rst.txt#writing-your-own-tests file, but how should I use the assert statements for the example in #5354 ? |
You don't have to use an assert in this case. Just literally use the example that crashes now. If the issue is fixed the test will then pass, if not the whole test suite will crash. |
I assume this TravisCI failure is unrelated? |
Indeed looks unrelated. I've restarted the test. |
Oh, then I will just add the corresponding program in a function and run numpy.test() ? |
@argriffing So, should I add testing ex 8000 ample to the test_multiarray.py file ? Also it looks like all PR related checks are added to test_regression.py file. |
@maniteja123 I was wrong in that comment I'd deleted. There was a function in that file called |
Ran 5679 tests in 899.856s OK (KNOWNFAIL=5, SKIP=8) This is the result I got after running numpy.test() |
@maniteja123 you please push that change with the regression test. |
And I'll have a look at what's going on with that |
@rgommers I have pushed the change to the branch. I am not sure if this is what was expected output and also the test suite is correctly written. Please do have a look :) |
@@ -2103,6 +2103,17 @@ def __eq__(self, other): | |||
assert_equal(np.int32(10) == x, "OK") | |||
assert_equal(np.array([10]) == x, "OK") | |||
|
|||
def test_fft(self): | |||
#PR 5386 |
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.
Nitpick: needs a space after #
and I'd refer to the bug report. So:
# Check segfault reported in gh-5354 doesn't occur anymore.
Looks like a minor thing:
You cannot mix tabs and spaces within Python files, it has to be spaces-only. You can replace them now by hand, but you should also look at setting up your text editor or IDE so it always replaces tabs with 4 spaces for all Python files. Any good editor will have an option to do this. |
The
However for this PR it says:
So somehow TravisCI is mixing up two builds. |
Looks like |
@rgommers Regarding travis build error, is there any chance of me using the inplace build causing the trouble there ? Also where do I get to learn these commenting styles in the discussions on github like embedding links to source code (in particular, some lines in github repo ), highlighting key points or putting code snippets ? |
Nice find. The earlier pip version bump also caused some complications if I remember correctly. |
the regression test can be removed the self.clip functions are wrapper functions around the real array clip used for the testing here, they do not have the same interface with default arguments, setting None explicitly is correct here then. |
I gave a as np.ones(10, dtype=np.complex)
(mismatch 100.0%) |
how does the test look like? |
|
I understand that it is a wrapper function. np.clip(a, a.min()) is raising a TypeError while a.clip(a.min()) isn't. But what I am not able to understand is why it is returning a ndarray of object type, while it works fine with |
self.clip uses a different method to clip which apparently does not work with None |
Oh, I see https://github.com/numpy/numpy/blob/master/numpy/core/tests/test_numeric.py#L1078 , which is a slow clip. I didn't think of that :) |
Now, with a predefined example, the test suite is running fine. I will remove the regression test and push a commit to the branch |
I have pushed the commit and the travis build also is successful :). On a side note, would it be preferable to make the defined slow clip function to take care of the cases when |
@maniteja123 another comment about style issues: almost every line contains a PEP8 violation:
You can run https://pypi.python.org/pypi/pep8 over your code and make sure it's clean. Note that it will report many other things in numpy which are there from long ago - but we try to not add new style problems.... |
m = a.min() | ||
M = None | ||
ac = self.fastclip(a, m, M) | ||
act = np.array([ 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j]) |
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.
This line isn't needed, act == a
.
@maniteja123 if you're comfortable with git, you may want to try to squash all commits ( |
I think content-wise this can go in. |
0e605e9
to
ffb8a1b
Compare
Sorry, I was out of station yesterday. I have taken care of PEP8 issues (I was unaware of the new rules, I just followed the previous guidelines ), also changed the comment for the regression test, mentioned the issue number 5354 and squashed the commits. I am not that acquainted with git, but am trying to get habituated to using git. |
a = np.ones(10, dtype=np.complex) | ||
m = a.min() | ||
M = None | ||
ac = self.fastclip(a, m, M) |
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 still think we should have the symmetrical test here as well, i.e. test both fastclip(a, a.min(), None)
and fastclip(a, None, a.max())
.
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.
Makes sense.
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 have added two symmetric tests as suggested by @jaimefrio . I have also pushed the changes.
…c regression test
ffb8a1b
to
61f3b10
Compare
BUG: Issue 5354 - Fixed segmentation fault when clipping complex arrays
Thanks, @maniteja123, in it goes. |
Thanks @rgommers @jaimefrio @juliantaylor @argriffing, for the help and guidance. It was really good to learn a lot and contribute to numpy :) |
@maniteja123 no problem. Keep them coming! |
One last piece of gith
A44D
ub wisdom, @maniteja123: I closed issue #5354 manually, but had the commit message included something like |
@jaimefrio, thanks for the advise. It is a nice way of handling issues related to PR. I would take care to follow the convention next time :-) |
BUG:An attempt to fix Issue #5354 .
The NULL dereference before checking whether the pointer is a NULL pointer is causing a segmentation fault. I am not sure whether the output coming now is the right one. Please do clarify anything else is wrong except the segmentation fault.
F_min
(-256+0j)
F.clip(F_min)
array([[ 8.29056000e+06 +0.j , 2.56000000e+02+358.28772462j,
-2.56000000e+02 +0.j , ...,
2.56000000e+02+861.73946261j, -2.56000000e+02 +0.j ,
2.56000000e+02-358.28772462j],
[ 0.00000000e+00 +0.j , 0.00000000e+00 +0.j ,
0.00000000e+00 +0.j , ...,
0.00000000e+00 +0.j , 0.00000000e+00 +0.j ,
0.00000000e+00 +0.j ],
[ 0.00000000e+00 +0.j , 0.00000000e+00 +0.j ,
0.00000000e+00 +0.j , ...,
0.00000000e+00 +0.j , 0.00000000e+00 +0.j ,
0.00000000e+00 +0.j ],
...,
[ 0.00000000e+00 +0.j , 0.00000000e+00 +0.j ,
0.00000000e+00 +0.j , ...,
0.00000000e+00 +0.j , 0.00000000e+00 +0.j ,
0.00000000e+00 +0.j ],
[ 0.00000000e+00 +0.j , 0.00000000e+00 +0.j ,
0.00000000e+00 +0.j , ...,
0.00000000e+00 +0.j , 0.00000000e+00 +0.j ,
0.00000000e+00 +0.j ],
[ 0.00000000e+00 +0.j , 0.00000000e+00 +0.j ,
0.00000000e+00 +0.j , ...,
0.00000000e+00 +0.j , 0.00000000e+00 +0.j ,
0.00000000e+00 +0.j ]])