Skip to content

Add #![no_std] support#314

Merged
YeungOnion merged 6 commits intostatrs-dev:masterfrom
FreezyLemon:no_std-support
Apr 8, 2025
Merged

Add #![no_std] support#314
YeungOnion merged 6 commits intostatrs-dev:masterfrom
FreezyLemon:no_std-support

Conversation

@FreezyLemon
Copy link
Contributor

@FreezyLemon FreezyLemon commented Dec 6, 2024

Closes #165.

Standard library types that exist in libcore are usually just reexported through std::, so changing from e.g. std::f64 to core::f64 results in no change in behavior.

There are a few things to note:

  • All nalgebra-dependent features require std at the moment. I'm not sure OVector/OMatrix can be used without std because of Dyn, but nalgebra does support no_std and SVector/SMatrix should work without libstd. Out of scope here though.
  • Some other features also require libstd, so they're disabled in no_std. E.g. all functions that have a Vec parameter/return type like OrderStatistics::ranks.
  • core::error::Error exists, but was only recently stabilized in 1.81.0. I decided to not use this yet and instead not implement the Error trait in no_std.
  • Tests have worse error messages in no_std. I don't know how to this type of string formatting without String, so I just dropped it. Dev machines should usually have it available anyways.

- `std::fmt` -> `core::fmt`
- `std::f64` -> `core::f64`
- misc.
- Gate some API that needs `Vec` behind the "std" feature
- Add no_std stub for `make_param_text`
`core::error` needs an MSRV of 1.81,
which is a bit too new for this crate
@codecov
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 41.09589% with 43 lines in your changes missing coverage. Please review.

Project coverage is 93.81%. Comparing base (a8fe65c) to head (2553589).
Report is 35 commits behind head on master.

Files with missing lines Patch % Lines
src/distribution/internal.rs 0.00% 5 Missing ⚠️
src/generate.rs 16.66% 5 Missing ⚠️
src/distribution/bernoulli.rs 0.00% 1 Missing ⚠️
src/distribution/beta.rs 0.00% 1 Missing ⚠️
src/distribution/binomial.rs 0.00% 1 Missing ⚠️
src/distribution/categorical.rs 0.00% 1 Missing ⚠️
src/distribution/cauchy.rs 0.00% 1 Missing ⚠️
src/distribution/chi.rs 0.00% 1 Missing ⚠️
src/distribution/chi_squared.rs 0.00% 1 Missing ⚠️
src/distribution/dirac.rs 0.00% 1 Missing ⚠️
... and 25 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #314      +/-   ##
==========================================
- Coverage   93.81%   93.81%   -0.01%     
==========================================
  Files          53       53              
  Lines       11996    12005       +9     
==========================================
+ Hits        11254    11262       +8     
- Misses        742      743       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@YeungOnion
Copy link
Contributor

I forgot why I didn't merge this earlier, but I also see a few items we can add for future development,

  • empirical as an immutable distribution (I've already been considering this since it's the only distribution with this behavior), an array would be sorted in place, then a second array would be buffered to the same size and filled with the values and cumulative counts.
  • OrderStatistic could have an API that outputs iterables instead of explicit Vec, this also means that if I only wanted to know where in a sorted list the first k items in an unsorted list appears, I could have the benefit of only obtaining the rank of the first three values, while worst case is unchanged, I think typical case would improve meaningfully for larger datasets.

Thanks for doing this, I think since I took a while with this there may be more changes required and then we'll have to update PRs.

@YeungOnion YeungOnion merged commit a2b17af into statrs-dev:master Apr 8, 2025
@FreezyLemon
Copy link
Contributor Author

Quite a few things were added between when I opened this and now.. this probably should've been updated before merging, as e.g. no-default-features is now broken on master. I'll try to fix those and open a new PR.

@FreezyLemon FreezyLemon deleted the no_std-support branch April 9, 2025 09:32
@FreezyLemon FreezyLemon mentioned this pull request Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no_std support

2 participants