PyO3 / rust-numpy

PyO3-based Rust bindings of the NumPy C-API
BSD 2-Clause "Simplified" License
1.11k stars 106 forks source link

Add `permute` and `transpose` methods for changing the order of axes of a `PyArray` #428

Closed adamreichold closed 5 months ago

adamreichold commented 5 months ago

Closes #424

adamreichold commented 5 months ago

I think we don't necessarily need to provide new APIs in a gil-ref variant, but given that these two can easily forward, I also don't see a problem with doing so.

Indeed, I thought about leaving them out, but since this will probably go out as a patch release and it does not really cost us anything, I added it anyway.

adamreichold commented 5 months ago

@akern40 I would be glad to get your feedback of whether this resolves your issue, but I also think that this is generally useful enough to merge based on @Icxolu's review.

akern40 commented 5 months ago

Thank you for the support! This lets me achieve what I was originally looking for; it still creates an extra object on the Python side, but that should be a view of the original NumPy array and therefore achieves the kind of cheap transfer I needed (I checked this in code, as well). Plus, it has the advantage of being more general than my initial suggestion. Thanks again!