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
BUG: seeing uninitialized memory in ufuncs #25953
Comments
Where is tricky: it does not touch memory where the condition is falsy. So you are seeing uninitialized memory. See the documentation of the where argument. This comes up often enough that maybe we should add a warning if |
I appreciate this clarification, and I understand the underlying problem you laid out. However, it is unclear why the memory is initialized in the second run.
The behavior still differs between runs. Seemingly, one time, it is initialized with whatever is in the memory, and the second time, it zeros. After my initial question, I thought it was the same memory, but after this example, it seemingly zeros. However, using "out" with correctly initialized outputs solved my issue. But I don't know if this behavior is intended. A warning should remind the user once to initialize the output efficiently. Thank you best regards |
I just ran into this same issue, it was maddening. I narrowed it down to two cases: Unusual Behavior ExampleThe first and last elements of the resulting "c" array are unitialized memory and will just contain whatever values happen to be in RAM at the moment:
Fixed ExampleIf I initialize the array first, I get what I expected (when the condition is False, just use the element from the first array instead of adding both):
|
Describe the issue:
I do not know what happens, but I see different behavior when I repeat the same operation. I don't know exactly if this is a bug, but if it is, it could be serious because the behavior is undefined for very basic functionality in my eyes. Please close this if I am just wrong or if my usage is wrong. In this case, an assertion could solve my issue.
Reproduce the code example:
Error message:
Lines 12 and 22 yield different results for the exact same operation.
Python and NumPy Versions:
1.21.6
3.10.5 (main, Jul 22 2022, 17:09:35) [GCC 9.4.0]
Runtime Environment:
I used the www.phython.org online python 3.10 interpreter for verification.
Context for the issue:
I found undefined behavior in a larger project and it took me a week to trace the bug because, in my case, this is a very basic functionality. I faced the wrong results in testing a functionality unrelated to this behavior; I accidentally created that case and had no idea that such behavior could possibly occur.
The text was updated successfully, but these errors were encountered: