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

Adds into_pyarray to faer Mat #482

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

wgurecky
Copy link

@wgurecky wgurecky commented Mar 10, 2025

Interoperability with faer (https://github.com/sarah-quinones/faer-rs) Mats.

Related faer-ext PR for numpy-to-faer direction: sarah-quinones/faer-ext#6 . For bi-directional interoperability of faer with python/numpy. @sarah-quinones

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Needs CI fixing please

PyArray::from_raw_parts(
py,
dims,
strides.as_ptr(),
Copy link
Member

Choose a reason for hiding this comment

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

@ngoldbaum does PyArray_NewFromDescr copy the strides array or just store the pointer? This looks like a potential use-after-free 🤔

(We already have the same pattern in the other into_pyarray functions in this file, which makes me think it's probably fine? Either that or there's a nasty bug in rust-numpy already...)

Copy link
Contributor

Choose a reason for hiding this comment

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

There's an explicit copy if strides are passed in:

https://github.com/numpy/numpy/blob/a651643fc9b5699a6dc6f3c85ba499c1f52ce3aa/numpy/_core/src/multiarray/ctors.c#L801-L816

There's another code path that handles structured dtypes with subarrays but it looks like that copies the strides too.

There's a comment here worrying about unaligned input strides:

https://github.com/numpy/numpy/blob/a651643fc9b5699a6dc6f3c85ba499c1f52ce3aa/numpy/_core/src/multiarray/ctors.c#L911-L916

But also I have no idea why an unaligned stride array would ever be a problem.

@davidhewitt davidhewitt mentioned this pull request Mar 13, 2025
@davidhewitt
Copy link
Member

Looks like this has hit a build issue with faer.

@wgurecky
Copy link
Author

wgurecky commented Mar 14, 2025

Looks like this has hit a build issue with faer.

yes, on windows x86 :/ . I don't have a good way to test on windows locally. Looks like a small change is needed in the faer-traits crate.

@wgurecky
Copy link
Author

Looks like this has hit a build issue with faer.

Updated to the latest faer version which contains a fix for this build issue.

There is a second issue, however. faer requires msrv of 1.84.0. If this is an issue, might have to either conditionally allow this optional faer feature, or, consider implementing IntoPyArray for faer Mats in faer itself

@wgurecky wgurecky requested a review from davidhewitt March 19, 2025 04:40
@davidhewitt
Copy link
Member

There still seem to be issues with Windows here.

If this is an issue, might have to either conditionally allow this optional faer feature, or, consider implementing IntoPyArray for faer Mats in faer itself

Given the seeming complexity with the CI on this end, this may be simpler (esp if faer has already implemented the reverse conversion over there).

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.

3 participants