Skip to content
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

Error in broadcasting stride_tricks array #6491

Closed
matthew-brett opened this issue Oct 16, 2015 · 3 comments

Comments

@matthew-brett
Copy link
Contributor

commented Oct 16, 2015

We hit a new test failure when testing against numpy 1.10.1 : nipy/nibabel#358

The test failure boils down to this:

import numpy as np

shape = (2,)
strides = [0]
tricky_scalar = np.lib.stride_tricks.as_strided(np.array(0), shape, strides)
other = np.zeros((1,))
first, second = np.broadcast_arrays(tricky_scalar, other)

On Linux (not OSX) I get the following error, for numpy 1.10.1:

Traceback (most recent call last):
  File "broadcast_bug.py", line 7, in <module>
    first, second = np.broadcast_arrays(tricky_scalar, other)
  File "/home/mb312/.virtualenvs/test/local/lib/python2.7/site-packages/numpy/lib/stride_tricks.py", line 200, in broadcast_arrays
    for array in args]
  File "/home/mb312/.virtualenvs/test/local/lib/python2.7/site-packages/numpy/lib/stride_tricks.py", line 70, in _broadcast_to
    result.flags.writeable = True
ValueError: cannot set WRITEABLE flag to True of this array

There is no error for the same code on numpy 1.9.3.

I think this is the same issue, arising in scipy: scipy/scipy#5374 (comment)

matthew-brett added a commit to nipy/nibabel that referenced this issue Oct 17, 2015
MRG: stride_tricks produces unbroadcastable array

A probable bug in numpy 1.10.1 causes an error when trying to broadcast an array constructed using stride tricks. 

See : numpy/numpy#6491 for a full description.

To work round, set the stride_tricks array as read-only, so that numpy does not try and set the output to writeable - that is the step that appears to cause the error.
@charris charris added this to the 1.10.2 release milestone Oct 17, 2015
@shoyer

This comment has been minimized.

Copy link
Member

commented Oct 17, 2015

Hmm. I wrote the offending line of code, so I can take a look at this.

@charris charris added 06 - Regression and removed 00 - Bug labels Oct 20, 2015
@shoyer shoyer self-assigned this Oct 22, 2015
@charris

This comment has been minimized.

Copy link
Member

commented Oct 24, 2015

@shoyer Any progress?

@shoyer

This comment has been minimized.

Copy link
Member

commented Oct 24, 2015

just put up a patch in #6556

@charris charris referenced this issue Oct 24, 2015
grlee77 pushed a commit to grlee77/nibabel that referenced this issue Mar 15, 2016
MRG: stride_tricks produces unbroadcastable array

A probable bug in numpy 1.10.1 causes an error when trying to broadcast an array constructed using stride tricks. 

See : numpy/numpy#6491 for a full description.

To work round, set the stride_tricks array as read-only, so that numpy does not try and set the output to writeable - that is the step that appears to cause the error.
QuLogic added a commit to QuLogic/biggus that referenced this issue Jul 3, 2016
cpelley added a commit to cpelley/biggus that referenced this issue Nov 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.