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

Vectors cannot be constructed from non-c-contiguous numpy arrays #205

Closed
avdstaaij opened this issue Jan 19, 2023 · 2 comments · Fixed by #206
Closed

Vectors cannot be constructed from non-c-contiguous numpy arrays #205

avdstaaij opened this issue Jan 19, 2023 · 2 comments · Fixed by #206
Assignees
Labels

Comments

@avdstaaij
Copy link

If a numpy array is not C_CONTIGUOUS, attempting to construct a vector from it raises a TypeError.

To reproduce:

a = np.array([[1,1],[2,2]])
a = np.transpose(a)
v = ivec2(a[0])

This is highly confusing, since in the example above, a[0] looks perfectly eligible:

>>> a = np.array([1,2])
>>> a
array([1, 2])
>>> ivec2(a)
ivec2( 1, 2 )

>>> a = np.array([[1,1],[2,2]])
>>> a = np.transpose(a)
>>> a[0]
array([1, 2])
>>> ivec2(a[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: invalid argument type(s) for vec()

Finding the root of this issue was... not easy. 😅

@Zuzu-Typ Zuzu-Typ added the bug label Jan 19, 2023
@Zuzu-Typ Zuzu-Typ self-assigned this Jan 19, 2023
@Zuzu-Typ
Copy link
Owner

Hmm.. I'm not sure if I'm correct, but I believe the issue is that the given array is not contiguous at all.
If I'm not mistaken, for a 1-dimensional array, a C-contiguous array is also an F-contiguous array and vice-versa.

Since the given vector contains data that is not stored at consecutive memory addresses, the data is not contiguous.
At least that's what I'm assuming.

PyGLM should support buffer data that isn't contiguous, which it currently doesn't.

I'll check if my assumptions are correct the next time I have access to a computer.

@avdstaaij
Copy link
Author

Hmm.. I'm not sure if I'm correct, but I believe the issue is that the given array is not contiguous at all. If I'm not mistaken, for a 1-dimensional array, a C-contiguous array is also an F-contiguous array and vice-versa.

Ah, you're right. I was inspecting the transposed 2D array, which is F-contiguous but not C-contiguous. A row from that array is indeed neither C-contiguous nor F-contiguous.

Zuzu-Typ added a commit that referenced this issue Jan 21, 2023
+ Added support for non-contiguous buffers
+ Streamlined non-F-contiguous buffer retrieval
+ Should fix #205
Zuzu-Typ added a commit that referenced this issue Jan 21, 2023
+ Added support for non-contiguous buffers
+ Streamlined non-F-contiguous buffer retrieval
+ Should fix #205
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants