-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no_std for ndarray #708
Comments
I guess the
|
We need formulation of the tangible benefits when it comes to usage of ndarray in no_std context. Not just interest, what it enables. Also to make a feature highlight so that we don't miss this ndarray is already plenty useful outside of dynamically allocated arrays. Using There are examples where we use slices of arrays:
And hopefully other places. I think it's cool - you can have arrayviews of any storage you have - and a very big set of tools is available with that, all the traversal methods, arithmetic operators like A point of precision is that we don't need to talk about stack-allocated, but inline storage. Just like ArrayVec, it's not a "stack allocated" vector. It has its storage inline, and Rust allows you to decide what to do with it. If you have a struct like this: |
Fwiw, adding (optional)
So once those things are resolved, adding I do think |
@bluss It looks like all the road blocks are now out of the way to make this possible. If nobody else volunteers to do this then I can do it. |
Nobody has answered my question of what the benefit of doing it is 😅 |
@bluss The Rust CV project is interested on many levels in being able to run computer vision algorithms on embedded chips within robots. We currently have two crates (akaze and ndarray-vision) which utilize ndarray to perform some basic array routines. We are looking to get no_std support to support embedded Rust for robotics and aviation. This is why some of us are looking to get ndarray to support no_std, as we are unable to use it in crates that run on embedded, and we also cannot run some crates now that were significantly easier to write with ndarray to embedded. By adding no_std support to ndarray we would be able to use it extensively in Rust CV for many types of problems, but primarily image processing and optimizers that are needed for the feature extraction and 3d reconstruction processes in vSLAM, SfM, and camera calibration. We currently use nalgebra pretty heavily, but there are some scenarios where ndarray is a better fit for the problem due to its slicing operations, negative strides, etc. |
Thanks for filling in. If possible, I've always favoured the "extern crate core as std" solution, since it makes the code across the crate the easiest to read and causes the least amount of churn, not sure if it's applicable here. |
I hadn't thought to do that, but perhaps we can make that work. I think there are some minor differences though, but I will keep that in mind. I take it that you are okay with adding no_std support then, so I will start working on that 👍. |
Arrayvec does it like that. Of course everything that's not in core (so between std and core) needs to be handled separately. https://docs.rs/arrayvec/0.5.2/src/arrayvec/lib.rs.html#34-35 |
(Hope it helps)
Other places can be solved by replacing "std" with "core". like this and this |
@bluss I'd be interested in implementing this. I haven't seen |
@jplatte We might all want to sync up this weekend. It looks like we have three people interested in contributing to this PR. It might be that less people actually do it, but we may as well just quickly chat about it. @SparrowLii has already started looking at it. |
For some reason, github has opened a discussion feature so I enabled it- here: #860 I don't necessarily want discussions to be here on github - they can be anywhere :) Over there I've mentioned the two more specific places I know - matrix and discord, are there more? |
Right, I thought they shared their findings here so somebody else can do the grunt work. If somebody else wants to do that, that's fine by me 👍🏼 |
@jplatte There's a prelude still, the core prelude. I like using "core as std". In #708 (comment) @vadixidav was the first person to say they wanted to do it. |
I am totally on board with @jplatte working on it if you want to do that. If not, I offered myself up to do it, which I can work on tomorrow. I will check out the discussion board thing, haven't used that feature before. |
Have joined the sci-and-ai channel and matrix. I personally think "use core as std" is cool, but it may make people confused about the difference between core and std, especially for beginners |
So, I left some extensive commentary in @bluss you may need to weigh in on whether a breaking release is justified or not. I have explained what the workarounds would be to make a non-breaking release below. Nonetheless, downstream users with Here are my findings:
|
matrixmultiply should definitely be conditionally using std (enable std when ndarray enables it). And yes, it is a breaking change because we're going to change what ndarray does with its no-default-features. |
@bluss I just want to clarify that you are okay with making a new breaking release. Is that fine? If so, it seems we can proceed without too much more discussion. |
I think it is reasonable to switch to FloatCore in order to achieve no_std, because this is the meaning of FLoatCore. If we want to use the Float feature without activating std, we can use libm crate. |
I just want to leave a brief comment, not necessarily a judgement about the actual float trait
This argument doesn't really ring true to me. The main feature of ndarray will continue to be that we use it with std. Having optional no_std is going to be one of the minor features. It's not a super important feature. That means that we need a float trait that maximizes our utility. |
This change needs to wait for a breaking release anyway. We should proceed quickly to that - we have breaking changes tagged with the 0.15 milestone already. |
Yeah I agree with @bluss regarding Searching through the code |
it looked very quick so I did a slight draft of float changes: #861 It will break tests because the --no-default-features is set. Also, if the other no_std changes are going to be massive I'd prefer to keep things to smaller easier to review PRs instead of one massive change - just for ease of review |
Yes, a breaking change is ok since it's needed for this, so that was a bit implicit I guess. Will you clarify what you want here? I'm expecting that we're going for no_std + alloc (And not a pure "just core" configuration). |
so because others mentioned the As for my PR it's just an attempt to break up the changes for |
I think no_std + alloc is the right way to go. If we want, we can also add an alloc feature right now that ndarray cannot build without. This would allow us to add a no-alloc version in the future. |
Since I replaced the replaceable "std" in the ndarray with "core", should I submit a pr? |
@SparrowLii that sounds good |
This pr enables ndarray to be used in the no_std environment, and maintains most of the functions. Fixes #708. The `geomspace` `linspace` `logspace` `range` `var_axis` and `std_axis` methods are only available when `std` is enabled at current. And 'blas''rayon''serde' features are not available without std too.
Using std gives us the following features:
std::arch
and target feature detection for seamless simdHaving optional
no_std
support would give us these tangible benefits:I have created this issue so that the pros and cons of
no_std
can be explained. As of this writing, usingno_std
does not seem to be attractive.As usual, all new features are to be used because of what gain they give us, not to score points. Formulate goal & gain before implementing.
The text was updated successfully, but these errors were encountered: