statrs-dev / statrs

Statistical computation library for Rust
https://docs.rs/statrs/latest/statrs/
MIT License
546 stars 78 forks source link

Adding Feature Flags and optional dependency? #196

Open abstractqqq opened 7 months ago

abstractqqq commented 7 months ago

Hi,

This is an amazing package with high quality code. However, I find it hard to include it in my work for the following reasons:

  1. I am trying to slim down my binary and if more statistical distributions are needed, I want to add them incrementally by adding more features.
  2. For my purpose, I almost never need multivariable distributions. I am already depending on Faer crate for linear algebra and I do not want another package for the same stuff. Again, I think nalgebra should be an optional dependency.

I am using statrs's code right now, which I copied. I am creditting the project. I mostly only need survival functions so I stripped down the code.

You can find my project here: https://github.com/abstractqqq/polars_ds_extension

YeungOnion commented 2 months ago

I'd consider multivariate as a feature; nalgebra is a big compile compared to the rest of statrs, @henryjac thoughts?

@abstractqqq Are there not other options than per distribution features for slimming down binary size for your cdylib? I don't know much about it, but is there not a way to ensure your API can't expose certain parts of statrs in a way that rustc can figure out what doesn't need to be built into the binary?

Additionally, as I have minimal exposure to building a library to call from C, I'd deeply appreciate reading suggestions for my learning.

abstractqqq commented 2 months ago

Thank you for responding. I am also not an expert in compilation. Still, I think nalgebra is only used in multivariate case and so multivariate can be behind a feature flag... Coming from Python, the pain of depending on both tensorflow and pytorch is just too much... It would be great if there is a "NumPy" in Rust and then it can be added as a dependency without question. But right now I think for higher dimension matrix and linear algebra, Faer is doing better than nalgebra...

YeungOnion commented 2 months ago

FYI, PyO3 is a great project, and they have bindings for the numpy C API

As far as a decision on feature flag, I'm interested, but I want to get some other's perspectives as well.