From afe07cfebba4c0c67f42f1af3b2606058cc58c30 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 31 Jan 2025 22:48:57 +0100 Subject: [PATCH 1/2] Bump rand for sprs --- sprs/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sprs/Cargo.toml b/sprs/Cargo.toml index 452bc976..c48280ac 100644 --- a/sprs/Cargo.toml +++ b/sprs/Cargo.toml @@ -37,7 +37,7 @@ tempfile = "3.1.0" bincode = "1.2.0" tobj = "4.0" image = { version = "0.25.2", default-features = false, features = ["png"] } -rand = { version = "0.8", default-features = false, features = ["small_rng"] } +rand = { version = "0.9", default-features = false, features = ["small_rng"] } [[bench]] name = "suite" From a5ff25b71f8b7d83ace3864ba4c5cf6a1c82b3ed Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 31 Jan 2025 23:10:19 +0100 Subject: [PATCH 2/2] Update rand deps --- sprs-rand/Cargo.toml | 6 +++--- sprs-rand/src/lib.rs | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sprs-rand/Cargo.toml b/sprs-rand/Cargo.toml index 2379028f..34b7299f 100644 --- a/sprs-rand/Cargo.toml +++ b/sprs-rand/Cargo.toml @@ -9,7 +9,7 @@ license.workspace = true edition.workspace = true [dependencies] -rand = "0.8.5" -rand_distr = "0.4.3" -rand_pcg = "0.3.1" +rand = "0.9.0" +rand_distr = "0.5.0" +rand_pcg = "0.9.0" sprs = { version = "0.11.0", path = "../sprs" } diff --git a/sprs-rand/src/lib.rs b/sprs-rand/src/lib.rs index d0a42983..c081cdd0 100644 --- a/sprs-rand/src/lib.rs +++ b/sprs-rand/src/lib.rs @@ -1,6 +1,6 @@ //! Random sparse matrix generation -use crate::rand::distributions::Distribution; +use crate::rand::distr::Distribution; use crate::rand::Rng; use crate::rand::SeedableRng; use sprs::indexing::SpIndex; @@ -40,7 +40,7 @@ where let mut data = Vec::with_capacity(exp_nnz); // sample row indices for _ in 0..exp_nnz { - indices.push(I::from_usize(rng.gen_range(0..shape.0))); + indices.push(I::from_usize(rng.random_range(0..shape.0))); // Note: there won't be any correspondence between the data // sampled here and the row sampled before, but this does not matter // as we are sampling. @@ -65,7 +65,7 @@ where let end = indptr[row + 1].index(); for _ in start..end { loop { - let col = I::from_usize(rng.gen_range(0..shape.1)); + let col = I::from_usize(rng.random_range(0..shape.1)); let loc = indices[start..].binary_search(&col); match loc { Ok(_) => { @@ -87,21 +87,21 @@ where /// Convenient wrapper for the common case of sampling a matrix with standard /// normal distribution of the nnz values, using a lightweight rng. pub fn rand_csr_std(shape: (usize, usize), density: f64) -> CsMat { - let mut rng = rand_pcg::Pcg64Mcg::from_entropy(); + let mut rng = rand_pcg::Pcg64Mcg::from_rng(&mut rand::rng()); rand_csr(&mut rng, crate::rand_distr::StandardNormal, shape, density) } #[cfg(test)] mod tests { - use rand::distributions::Standard; + use rand::distr::StandardUniform; use rand::SeedableRng; use sprs::CsMat; #[test] fn empty_random_mat() { - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); let empty: CsMat = - super::rand_csr(&mut rng, Standard, (0, 0), 0.3); + super::rand_csr(&mut rng, StandardUniform, (0, 0), 0.3); assert_eq!(empty.nnz(), 0); } @@ -109,12 +109,12 @@ mod tests { fn random_csr() { let mut rng = rand::rngs::StdRng::seed_from_u64(1234); let mat: CsMat = - super::rand_csr(&mut rng, Standard, (100, 70), 0.3); + super::rand_csr(&mut rng, StandardUniform, (100, 70), 0.3); assert!(mat.density() > 0.25); assert!(mat.density() < 0.35); let mat: CsMat = - super::rand_csr(&mut rng, Standard, (1, 10000), 0.3); + super::rand_csr(&mut rng, StandardUniform, (1, 10000), 0.3); assert!(mat.density() > 0.28); assert!(mat.density() < 0.32); }