Subdependency features: PyArray/ndarray/rayon

I'm struggling to understand how the dependency system works, specifically for optional features with subdependencies. Previously, I've done tests with ndarray and rayon for parallelisation, which has worked well. To do that, I've added in my Cargo.toml:

[dependencies.ndarray]
version = "0.15.6"
features = ["rayon"]

I'm now trying to interface with Python using PyO3 and I'm gradually making progress. I'm using the numpy crate, which re-exports ndarray, giving me access to the basic features of ndarray. My question is, how do I also get access to the parallel features of ndarray whilst using the numpy crate's version of ndarray rather than specifying that as a separate dependency?

Ideally, numpy would have its own feature that enables ndarray's feature. But when that's not available, you have to add ndarray as your own dependency like you did before. Just make sure the version numbers are compatible.

There's a pull request that adds that functionality, but digging further it was removed later on. From the examples, I've taken the same dependencies as in the Cargo.toml.

My understanding is that this should be giving me access to the ndarray::parallel features, but I'm getting compilation errors that they're not available.

I started from scratch by taking a direct copy of the parallel example and editing it from there, and got it to work. I can't figure out what the functional difference is though, which is annoying, but at least I got it working.

1 Like