You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
#[pyfunction]fnmy_mean(ar:ArrayLike1<f64>) -> PyResult<f64>{let res = ar
.as_array().mean().ok_or(PyValueError::new_err("Empty array"))?;Ok(res)}
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:
The text was updated successfully, but these errors were encountered: