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

Flumpy doesn't handle non-owning-data numpy arrays #406

Closed
ndevenish opened this issue Jul 15, 2021 · 0 comments · Fixed by #416
Closed

Flumpy doesn't handle non-owning-data numpy arrays #406

ndevenish opened this issue Jul 15, 2021 · 0 comments · Fixed by #416
Assignees

Comments

@ndevenish
Copy link
Collaborator

data = numpy.zeros(100)
>>> data[:] is data
False
>>> data[:].flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False
  UPDATEIFCOPY : False

>>> flumpy.from_numpy(data)
<scitbx_array_family_flex_ext.double object at 0x7f50b463da50>
>>> flumpy.from_numpy(data[:])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'obj'

This is because it assumes that if array.base exists, it is pointing to a memoryview object (e.g. something you previously converted). This isn't the case for standard slices of numpy arrays.

@ndevenish ndevenish self-assigned this Jul 15, 2021
@ndevenish ndevenish changed the title Numpy doesn't handle non-owning-data numpy arrays Flumpy doesn't handle non-owning-data numpy arrays Jul 20, 2021
ndevenish added a commit to ndevenish/dxtbx that referenced this issue Aug 9, 2021
This could happen in cases where you are converting e.g. a contiguous slice of
your original array - flumpy previously needlessly assumed that if an array
didn't own it's own data, that the array base came from flex.

Fixes cctbx#406
ndevenish added a commit that referenced this issue Aug 10, 2021
This could happen in cases where you are converting e.g. a contiguous slice of
your original array - flumpy previously needlessly assumed that if an array
didn't own it's own data, that the array base came from flex.

Fixes #406.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant