statrs-dev / statrs

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

Efficient access to private data #244

Open YeungOnion opened 3 weeks ago

YeungOnion commented 3 weeks ago

I don't quite know if this is the proper place for this, but is there a way to make certain guarantees that unsafe code external to the crate can depend upon? I use this code a lot for code that is supposed to be relatively high performance, but it's relatively difficult to extract information from the struct safely and efficiently so that I can manipulate it with unsafe code.

As a simple example, is there a way to add some kind of InfallibleDistribution trait which is basically the Distribution trait but for distributions that have the relevant statistics always defined regardless of their parameters? Currently, I'm using unwrap_unchecked() on the std_dev() output of the Normal distribution, but that's not technically guaranteed by the API to always be sound, even though the standard deviation of any Normal distribution is obviously always defined.

Originally posted by @alimf17 in https://github.com/statrs-dev/statrs/issues/206#issuecomment-2156693721


Feel free to change the title on this issue