diff --git a/Cargo.lock.MSRV b/Cargo.lock.MSRV index 4958be1d..f3c01b09 100644 --- a/Cargo.lock.MSRV +++ b/Cargo.lock.MSRV @@ -19,15 +19,15 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anyhow" -version = "1.0.87" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "approx" @@ -40,9 +40,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bumpalo" @@ -52,9 +52,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.18.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" +checksum = "8b37c88a63ffd85d15b406896cc343916d7cf57838a847b3a6f2ca5d39a5695a" [[package]] name = "byteorder" @@ -103,18 +103,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.17" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.17" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" dependencies = [ "anstyle", "clap_lex", @@ -122,9 +122,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" [[package]] name = "criterion" @@ -248,30 +248,31 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "a865e038f7f6ed956f788f0d7d60c541fff74c7bd74272c5d4cf15c63743e705" dependencies = [ + "once_cell", "wasm-bindgen", ] [[package]] name = "libc" -version = "0.2.158" +version = "0.2.167" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" [[package]] name = "libm" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "log" @@ -297,9 +298,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "nalgebra" -version = "0.32.6" +version = "0.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5c17de023a86f59ed79891b2e5d5a94c705dbe904a5b5c9c952ea6221b03e4" +checksum = "26aecdf64b707efd1310e3544d709c5c0ac61c13756046aaaba41be5c4f66a3b" dependencies = [ "approx", "matrixmultiply", @@ -324,6 +325,16 @@ dependencies = [ "syn", ] +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-complex" version = "0.4.6" @@ -348,6 +359,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ + "num-bigint", "num-integer", "num-traits", ] @@ -364,9 +376,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "oorandom" @@ -419,9 +431,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -503,9 +515,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -515,9 +527,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -526,9 +538,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "ryu" @@ -556,18 +568,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", @@ -576,9 +588,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", @@ -588,9 +600,9 @@ dependencies = [ [[package]] name = "simba" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "061507c94fc6ab4ba1c9a0305018408e312e17c041eb63bef8aa726fa33aceae" +checksum = "b3a386a501cd104797982c15ae17aafe8b9261315b5d07e3ec803f2ea26be0fa" dependencies = [ "approx", "num-complex", @@ -613,9 +625,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -640,9 +652,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "walkdir" @@ -662,9 +674,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "d15e63b4482863c109d70a7b8706c1e364eb6ea449b201a76c5b89cedcec2d5c" dependencies = [ "cfg-if", "once_cell", @@ -673,9 +685,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "8d36ef12e3aaca16ddd3f67922bc63e48e953f126de60bd33ccc0101ef9998cd" dependencies = [ "bumpalo", "log", @@ -688,9 +700,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "705440e08b42d3e4b36de7d66c944be628d579796b8090bfa3471478a2260051" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -698,9 +710,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "98c9ae5a76e46f4deecd0f0255cc223cfa18dc9b261213b8aa0c7b36f61b3f1d" dependencies = [ "proc-macro2", "quote", @@ -711,15 +723,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "6ee99da9c5ba11bd675621338ef6fa52296b76b83305e9b6e5c77d4c286d6d49" [[package]] name = "web-sys" -version = "0.3.70" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "a98bc3c33f0fe7e59ad7cd041b89034fa82a7c2d4365ca538dda6cdaf513863c" dependencies = [ "js-sys", "wasm-bindgen", @@ -727,9 +739,9 @@ dependencies = [ [[package]] name = "wide" -version = "0.7.28" +version = "0.7.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b828f995bf1e9622031f8009f8481a85406ce1f4d4588ff746d872043e855690" +checksum = "58e6db2670d2be78525979e9a5f9c69d296fd7d670549fe9ebf70f8708cb5019" dependencies = [ "bytemuck", "safe_arch", diff --git a/Cargo.toml b/Cargo.toml index 7c27e034..faca884c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" include = ["CHANGELOG.md", "LICENSE.md", "src/", "tests/"] # When changing MSRV: Also update the README -rust-version = "1.61.0" +rust-version = "1.65.0" [lib] name = "statrs" @@ -38,7 +38,7 @@ version = "0.8" optional = true [dependencies.nalgebra] -version = "0.32" +version = "0.33" optional = true default-features = false features = ["std"] @@ -48,7 +48,7 @@ criterion = "0.5" anyhow = "1.0" [dev-dependencies.nalgebra] -version = "0.32" +version = "0.33" default-features = false features = ["macros"] diff --git a/README.md b/README.md index b1ac1396..f3800a3f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ ![tests][actions-test-badge] [![MIT licensed][license-badge]](./LICENSE.md) [![Crate][crates-badge]][crates-url] -[![docs.rs](https://img.shields.io/docsrs/statrs)][docs-url] +[![docs.rs][docsrs-badge]][docs-url] +[![codecov-statrs][codecov-badge]][codecov-url] +![Crates.io MSRV][crates-msrv-badge] [actions-test-badge]: https://github.com/statrs-dev/statrs/actions/workflows/test.yml/badge.svg [crates-badge]: https://img.shields.io/crates/v/statrs.svg @@ -13,6 +15,7 @@ [docs-url]: https://docs.rs/statrs/*/statrs [codecov-badge]: https://codecov.io/gh/statrs-dev/statrs/graph/badge.svg?token=XtMSMYXvIf [codecov-url]: https://codecov.io/gh/statrs-dev/statrs +[crates-msrv-badge]: https://img.shields.io/crates/msrv/statrs Statrs provides a host of statistical utilities for Rust scientific computing. @@ -50,7 +53,7 @@ If you'd like to modify where the data is downloaded, you can use the environmen ## Minimum supported Rust version (MSRV) -This crate requires a Rust version of 1.61.0 or higher. Increases in MSRV will be considered a semver non-breaking API change and require a version increase (PATCH until 1.0.0, MINOR after 1.0.0). +This crate requires a Rust version of 1.65.0 or higher. Increases in MSRV will be considered a semver non-breaking API change and require a version increase (PATCH until 1.0.0, MINOR after 1.0.0). ## Contributing @@ -58,10 +61,14 @@ Thanks for your help to improve the project! **No contribution is too small and all contributions are valued.** Suggestions if you don't know where to start, -- documentation is a great place to start, as you'll be able to identify the value of existing documentation better than its authors. -- tests are valuable in demonstrating correct behavior, you can review test coverage on the [CodeCov Report][codecov-url]*, not live until [#229](https://github.com/statrs-dev/statrs/pull/229) merged. +- [documentation][docs-url] is a great place to start, as you'll be able to identify the value of existing documentation better than its authors. +- tests are valuable in demonstrating correct behavior, you can review test coverage on the [CodeCov Report][codecov-url] - check out some of the issues marked [help wanted](https://github.com/statrs-dev/statrs/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22). -- look at what's not included from Math.NET's [Distributions](https://github.com/mathnet/mathnet-numerics/tree/master/src/Numerics/Distributions), [Statistics](https://github.com/mathnet/mathnet-numerics/tree/master/src/Numerics/Statistics), or related. +- look at features in other tools you'd like to see in statrs + - Math.NET's + - [Distributions](https://github.com/mathnet/mathnet-numerics/tree/master/src/Numerics/Distributions) + - [Statistics](https://github.com/mathnet/mathnet-numerics/tree/master/src/Numerics/Statistics) + - scipy.stats ### How to contribute @@ -84,12 +91,13 @@ cargo fmt ``` Add `--check` to view the diff without making file changes. -Our CI will `fmt`, but less chores in commit history are appreciated. +Our CI will check format without making changes. After commiting your code: -``` -git push -u origin +```shell +git push -u # with `git` +gh pr create --head # with GitHub's cli ``` Then submit a PR, preferably referencing the relevant issue, if it exists. diff --git a/src/distribution/dirichlet.rs b/src/distribution/dirichlet.rs index 5e08d0a4..aabcc9cb 100644 --- a/src/distribution/dirichlet.rs +++ b/src/distribution/dirichlet.rs @@ -25,7 +25,7 @@ use std::f64; pub struct Dirichlet where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { alpha: OVector, } @@ -111,7 +111,7 @@ impl Dirichlet { impl Dirichlet where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { /// Constructs a new distribution with the given vector for `alpha` /// Does not clone the vector it takes ownership of @@ -184,7 +184,7 @@ where impl std::fmt::Display for Dirichlet where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "Dir({}, {})", self.alpha.len(), &self.alpha) @@ -196,7 +196,7 @@ where impl ::rand::distributions::Distribution> for Dirichlet where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { fn sample(&self, rng: &mut R) -> OVector { let mut sum = 0.0; @@ -215,7 +215,7 @@ where impl MeanN> for Dirichlet where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { /// Returns the means of the dirichlet distribution /// @@ -237,7 +237,7 @@ impl VarianceN> for Dirichlet where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the variances of the dirichlet distribution /// @@ -267,12 +267,12 @@ where } } -impl<'a, D> Continuous<&'a OVector, f64> for Dirichlet +impl Continuous<&OVector, f64> for Dirichlet where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator, D>, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator, D>, { /// Calculates the probabiliy density function for the dirichlet /// distribution @@ -375,7 +375,7 @@ mod tests { fn try_create(alpha: OVector) -> Dirichlet where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { let mvn = Dirichlet::new_from_nalgebra(alpha); assert!(mvn.is_ok()); @@ -385,7 +385,7 @@ mod tests { fn bad_create_case(alpha: OVector) where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { let dd = Dirichlet::new_from_nalgebra(alpha); assert!(dd.is_err()); @@ -396,7 +396,7 @@ mod tests { T: Debug + Display + approx::RelativeEq, F: FnOnce(Dirichlet) -> T, D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { let dd = try_create(alpha); let x = eval(dd); diff --git a/src/distribution/discrete_uniform.rs b/src/distribution/discrete_uniform.rs index a9760808..b610b735 100644 --- a/src/distribution/discrete_uniform.rs +++ b/src/distribution/discrete_uniform.rs @@ -15,7 +15,7 @@ use crate::statistics::*; /// assert_eq!(n.mean().unwrap(), 2.5); /// assert_eq!(n.pmf(3), 1.0 / 6.0); /// ``` -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub struct DiscreteUniform { min: i64, max: i64, diff --git a/src/distribution/internal.rs b/src/distribution/internal.rs index 9075669e..13435d44 100644 --- a/src/distribution/internal.rs +++ b/src/distribution/internal.rs @@ -24,15 +24,11 @@ pub fn integral_bisection_search( loop { let mid = (lb.clone() + ub.clone()) / two.clone(); if !(f(&lb)..=f(&ub)).contains(&f(&mid)) { - // if f found not monotone on the interval - return None; + return None; // f found not monotone on interval } else if f(&lb) == z { return Some(lb); - } else if f(&ub) == z { - return Some(ub); - } else if (lb.clone() + K::one()) == ub { - // no more elements to search - return Some(ub); + } else if f(&ub) == z || (lb.clone() + K::one()) == ub { + return Some(ub); // found or no more integers between } else if f(&mid) >= z { ub = mid; } else { diff --git a/src/distribution/multinomial.rs b/src/distribution/multinomial.rs index 0794d352..f5b88945 100644 --- a/src/distribution/multinomial.rs +++ b/src/distribution/multinomial.rs @@ -23,7 +23,7 @@ use nalgebra::{DVector, Dim, Dyn, OMatrix, OVector}; pub struct Multinomial where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { /// normalized probabilities for each species p: OVector, @@ -93,7 +93,7 @@ impl Multinomial { impl Multinomial where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { pub fn new_from_nalgebra(mut p: OVector, n: u64) -> Result { if p.len() < 2 { @@ -152,7 +152,7 @@ where impl std::fmt::Display for Multinomial where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "Multinom({:#?},{})", self.p, self.n) @@ -164,8 +164,8 @@ where impl ::rand::distributions::Distribution> for Multinomial where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { fn sample(&self, rng: &mut R) -> OVector { sample_generic(self, rng) @@ -177,7 +177,7 @@ where impl ::rand::distributions::Distribution> for Multinomial where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { fn sample(&self, rng: &mut R) -> OVector { sample_generic(self, rng) @@ -188,8 +188,7 @@ where fn sample_generic(dist: &Multinomial, rng: &mut R) -> OVector where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, R: ::rand::Rng + ?Sized, T: ::num_traits::Num + ::nalgebra::Scalar + ::std::ops::AddAssign, { @@ -207,7 +206,7 @@ where impl MeanN> for Multinomial where D: Dim, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { /// Returns the mean of the multinomial distribution /// @@ -230,7 +229,7 @@ impl VarianceN> for Multinomial where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the variance of the multinomial distribution /// @@ -281,11 +280,10 @@ where // } // } -impl<'a, D> Discrete<&'a OVector, f64> for Multinomial +impl Discrete<&OVector, f64> for Multinomial where D: Dim, - nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { /// Calculates the probability mass function for the multinomial /// distribution @@ -372,7 +370,7 @@ mod tests { fn try_create(p: OVector, n: u64) -> Multinomial where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { let mvn = Multinomial::new_from_nalgebra(p, n); assert!(mvn.is_ok()); @@ -382,7 +380,7 @@ mod tests { fn bad_create_case(p: OVector, n: u64) -> MultinomialError where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { let dd = Multinomial::new_from_nalgebra(p, n); assert!(dd.is_err()); @@ -394,7 +392,7 @@ mod tests { T: Debug + Display + approx::RelativeEq, F: FnOnce(Multinomial) -> T, D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator, { let dd = try_create(p, n); let x = eval(dd); diff --git a/src/distribution/multivariate_normal.rs b/src/distribution/multivariate_normal.rs index 6eb3b777..29767385 100644 --- a/src/distribution/multivariate_normal.rs +++ b/src/distribution/multivariate_normal.rs @@ -14,9 +14,8 @@ pub(super) fn density_normalization_and_exponential( ) -> Option<(f64, f64)> where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator<(usize, usize), D>, + nalgebra::DefaultAllocator: + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { Some(( density_distribution_pdf_const(mu, cov)?, @@ -35,7 +34,7 @@ fn density_distribution_exponential( where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { if x.shape_generic().0 != precision.shape_generic().0 || x.shape_generic().0 != mu.shape_generic().0 @@ -55,9 +54,9 @@ where fn density_distribution_pdf_const(mu: &OVector, cov: &OMatrix) -> Option where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator<(usize, usize), D>, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator, { if cov.shape_generic().0 != mu.shape_generic().0 || !cov.is_square() { return None; @@ -90,7 +89,7 @@ pub struct MultivariateNormal where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { cov_chol_decomp: OMatrix, mu: OVector, @@ -156,9 +155,9 @@ impl MultivariateNormal { impl MultivariateNormal where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator<(usize, usize), D>, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator, { /// Constructs a new multivariate normal distribution with a mean of `mean` /// and covariance matrix `cov` using `nalgebra` `OVector` and `OMatrix` @@ -231,7 +230,7 @@ impl std::fmt::Display for MultivariateNormal where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "N({}, {})", &self.mu, &self.cov) @@ -244,7 +243,7 @@ impl ::rand::distributions::Distribution> for MultivariateNor where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Samples from the multivariate normal distribution /// @@ -256,7 +255,6 @@ where /// where `L` is the Cholesky decomposition of the covariance matrix, /// `Z` is a vector of normally distributed random variables, and /// `μ` is the mean vector - fn sample(&self, rng: &mut R) -> OVector { let d = crate::distribution::Normal::new(0., 1.).unwrap(); let z = OVector::from_distribution_generic(self.mu.shape_generic().0, Const::<1>, &d, rng); @@ -268,7 +266,7 @@ impl Min> for MultivariateNormal where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the minimum value in the domain of the /// multivariate normal distribution represented by a real vector @@ -281,7 +279,7 @@ impl Max> for MultivariateNormal where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the maximum value in the domain of the /// multivariate normal distribution represented by a real vector @@ -294,7 +292,7 @@ impl MeanN> for MultivariateNormal where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the mean of the normal distribution /// @@ -310,7 +308,7 @@ impl VarianceN> for MultivariateNormal where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the covariance matrix of the multivariate normal distribution fn variance(&self) -> Option> { @@ -322,7 +320,7 @@ impl Mode> for MultivariateNormal where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the mode of the multivariate normal distribution /// @@ -338,11 +336,11 @@ where } } -impl<'a, D> Continuous<&'a OVector, f64> for MultivariateNormal +impl Continuous<&OVector, f64> for MultivariateNormal where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Calculates the probability density function for the multivariate /// normal distribution at `x` @@ -387,9 +385,9 @@ mod tests { fn try_create(mean: OVector, covariance: OMatrix) -> MultivariateNormal where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator<(usize, usize), D>, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator, { let mvn = MultivariateNormal::new_from_nalgebra(mean, covariance); assert!(mvn.is_ok()); @@ -399,9 +397,9 @@ mod tests { fn create_case(mean: OVector, covariance: OMatrix) where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator<(usize, usize), D>, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator, { let mvn = try_create(mean.clone(), covariance.clone()); assert_eq!(mean, mvn.mean().unwrap()); @@ -411,9 +409,9 @@ mod tests { fn bad_create_case(mean: OVector, covariance: OMatrix) where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator<(usize, usize), D>, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator, { let mvn = MultivariateNormal::new_from_nalgebra(mean, covariance); assert!(mvn.is_err()); @@ -425,9 +423,9 @@ mod tests { T: Debug + PartialEq, F: FnOnce(MultivariateNormal) -> T, D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator<(usize, usize), D>, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator, { let mvn = try_create(mean, covariance); let x = eval(mvn); @@ -439,9 +437,9 @@ mod tests { ) where F: FnOnce(MultivariateNormal) -> f64, D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator<(usize, usize), D>, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator, { let mvn = try_create(mean, covariance); let x = eval(mvn); diff --git a/src/distribution/multivariate_students_t.rs b/src/distribution/multivariate_students_t.rs index 919e3ebf..a1b78551 100644 --- a/src/distribution/multivariate_students_t.rs +++ b/src/distribution/multivariate_students_t.rs @@ -26,7 +26,7 @@ pub struct MultivariateStudent where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { scale_chol_decomp: OMatrix, location: OVector, @@ -110,9 +110,9 @@ impl MultivariateStudent { impl MultivariateStudent where D: DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator<(usize, usize), D>, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator, { pub fn new_from_nalgebra( location: OVector, @@ -202,7 +202,7 @@ impl ::rand::distributions::Distribution> for MultivariateStu where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Samples from the multivariate student distribution /// @@ -233,7 +233,7 @@ impl Min> for MultivariateStudent where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the minimum value in the domain of the /// multivariate normal distribution represented by a real vector @@ -250,7 +250,7 @@ impl Max> for MultivariateStudent where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the minimum value in the domain of the /// multivariate normal distribution represented by a real vector @@ -263,7 +263,7 @@ impl MeanN> for MultivariateStudent where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the mean of the student distribution. /// @@ -284,7 +284,7 @@ impl VarianceN> for MultivariateStudent where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the covariance matrix of the multivariate student distribution. /// @@ -309,7 +309,7 @@ impl Mode> for MultivariateStudent where D: Dim, nalgebra::DefaultAllocator: - nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, + nalgebra::allocator::Allocator + nalgebra::allocator::Allocator, { /// Returns the mode of the multivariate student distribution. /// @@ -325,12 +325,12 @@ where } } -impl<'a, D> Continuous<&'a OVector, f64> for MultivariateStudent +impl Continuous<&OVector, f64> for MultivariateStudent where D: Dim + DimMin, - nalgebra::DefaultAllocator: nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator - + nalgebra::allocator::Allocator<(usize, usize), D>, + nalgebra::DefaultAllocator: nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator + + nalgebra::allocator::Allocator, { /// Calculates the probability density function for the multivariate. /// student distribution at `x`. @@ -348,7 +348,7 @@ where /// - `inv(Σ)` is the precision matrix, /// - `det(Σ)` is the determinant of the scale matrix, and /// - `k` is the dimension of the distribution. - fn pdf(&self, x: &'a OVector) -> f64 { + fn pdf(&self, x: &OVector) -> f64 { if self.freedom.is_infinite() { use super::multivariate_normal::density_normalization_and_exponential; let (pdf_const, exp_arg) = density_normalization_and_exponential( @@ -369,7 +369,7 @@ where /// Calculates the log probability density function for the multivariate /// student distribution at `x`. Equivalent to pdf(x).ln(). - fn ln_pdf(&self, x: &'a OVector) -> f64 { + fn ln_pdf(&self, x: &OVector) -> f64 { if self.freedom.is_infinite() { use super::multivariate_normal::density_normalization_and_exponential; let (pdf_const, exp_arg) = density_normalization_and_exponential(