Closed 124C41p closed 1 year ago
Since you already posted code, why not turn this into a pull request? (The approach itself is reasonable as far I can see.)
Ok, I'll try. It might take some time however to figure out the general case (say ArrayLike<T, D>
) as I am not an expert in any of the involved libraries.
Take your time. If you get stuck, you can open a draft pull request with what you have even if it does not build. I will try to help out with open issues then.
When writing a Python function processing numpy arrays, it is often a common practice to accept any "array like" input, and convert it into a numpy array if necessary. For example, the following function processes a float64-array (and it does not allocate memory if such an array is given), but also works for integer lists, or something like that:
I would like to do the same thing in rust with PyO3. The following function should accept anything which can be reasonably converted into a one dimensional f64-array, but should not allocate memory if the "correct" type is plugged in:
Technically, it could be achieved like that: