Skip to content
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 support #165

Open
h4x3rotab opened this issue Mar 29, 2022 · 2 comments · May be fixed by #314
Open

no_std support #165

h4x3rotab opened this issue Mar 29, 2022 · 2 comments · May be fixed by #314

Comments

@h4x3rotab
Copy link

It would be nice if we can add no_std support for at least the parts don't need rng. It's a good idea to define a rng trait and allow the user to pass it to the library.

@vks
Copy link
Contributor

vks commented Mar 29, 2022

Rand works fine without std. Floating point math however needs std, unless libm is used.

@FreezyLemon
Copy link
Contributor

rand and nalgebra offer multiple features for this:

  • std
  • alloc
  • libm (only nalgebra)

AFAICT, std/alloc features are the norm across the ecosystem and it probably makes sense to adopt this too.

One disadvantage is that #[cfg] will appear more often and can increase mental load for contributors. Local testing will also become more difficult, but that's probably a price worth paying for good no_std support. Good documentation (for contributors and users) would also help.

Just some notes, I've played around with it and might go for a PR:

  • std effectively includes alloc and libm
  • feature std can depend on alloc but not libm (dependency mess)
  • every feature activates same feature in dependency "std" = ["nalgebra?/std", ...], default should include std
  • libm only really makes sense when in no_std (compile_error! via cfg prob. too much?)
  • Categorical, Empirical need alloc
  • Multivariates (Dirichlet, MVN, MVS, Multinomial)
    • require libm or std (float operations in nalgebra, e.g. Complex<f32>)
    • alloc or std add heap allocation (DVector, DMatrix, nalgebra::Dyn) support
  • some code can be rewritten to avoid allocations (avoid feature-gating stuff that doesn't 100% need it)
  • i don't think there's anything in the entire library that needs std. no_std + alloc + libm is probably good enough for everything? At least so far

@FreezyLemon FreezyLemon linked a pull request Dec 6, 2024 that will close this issue
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 a pull request may close this issue.

3 participants