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

Fix IntoPyArray for arrays of which the starting pointer is not equal… #194

Merged
merged 1 commit into from
Jul 10, 2021

Conversation

kngwyu
Copy link
Member

@kngwyu kngwyu commented Jul 10, 2021

Fix #182

@kngwyu kngwyu merged commit 8bc9535 into main Jul 10, 2021
unsafe { PyArray::from_boxed_slice(py, dim, strides.as_ptr(), boxed) }
let (strides, dim) = (self.npy_strides(), self.raw_dim());
let orig_ptr = self.as_ptr();
let is_empty_or_size0 = self.is_empty() || std::mem::size_of::<Self>() == 0;
Copy link

@bluss bluss Jul 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kngwyu I think this size_of should be for the element, size_of::<A> (Self will never be size zero).

@jturner314 and me are maintainers of rust-ndarray and don't mind reviewing changes such as these, when we have time. I'm sorry that this use case is a bit tricky, due to missing low-level APIs - talking with us about what you need could be a good way to improve ndarray for the use cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your kind comments. I'll fix this later.

what you need could be a good way to improve ndarray for the use cases.

I guess @jturner314 already opened rust-ndarray/ndarray#994?
What we need is Box<[T]> and the pointer to the first element of the array. The pointer is used as void* data in https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_NewFromDescr

@messense messense deleted the intopyarray-pointer-fix branch July 11, 2021 10:42
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 this pull request may close these issues.

IntoPyArray for Array is broken when the first element is not at the start of the allocation
2 participants