Add support for safely creating universal functions in Rust#400
Add support for safely creating universal functions in Rust#400adamreichold wants to merge 1 commit intomainfrom
Conversation
|
@mhostetter Would you be interested and able to test this branch? Would the functionality available here suffice to handle your use case? EDIT: The |
5658032 to
2276b54
Compare
kngwyu
left a comment
There was a problem hiding this comment.
Looks quite solid as an initial implementation! I'll review again after you complete the PR.
I can try, but I fear my knowledge is too limited to be effective. I've only done an example or two with Py03 and To summarize my goals in words... Write a NumPy ufunc in Rust. This function takes |
I think to test this branch, you would only need to change your numpy = "0.20"by numpy = { git = "https://github.com/PyO3/rust-numpy.git", branch = "ufunc" }
To my understanding, universal functions always take 1-dimensional vectors as inputs (so they have a chance of vectorizing the inner-most loop) and take their outputs explicitly. So if your modulus is basically fixed, you could inject by capturing it in the closure that defines your ufunc, e.g. let m = ...;
let add_mod_m = move |[x, y]: [ArrayView1<'_, u64>; 2], [z]: [ArrayViewMut1<'_, u64>; 1]| {
azip!((x in x, y in y, z in z) *z = (*x + *y) % m);
});
let add_mod_m = numpy::ufunc::from_func(py, CString::new("add_mod_m").unwrap(), numpy::ufunc::Identity::Zero, add_mod_m);
module.add("add_mod_m", add_mod_m).unwrap();If you want to vary |
This does not support polymorphic universal functions, but the numbers of inputs and outputs are arbitrary.
Closes #399