Commit 66f77af
authored
chore: bump rand to 0.10.1, rand_distr to 0.5, getrandom to 0.3 (#369)
* chore: bump rand to 0.10.1, remove rand_distr from default, getrandom to 0.3
- Update rand 0.8.5 → 0.10.1
- Update getrandom 0.2.8 → 0.3
- Add rand/thread_rng to std_rand feature (required in 0.9+)
- Rename getrandom/js feature → getrandom/wasm_js (getrandom 0.3)
- Replace deprecated thread_rng() → rng() (rand_custom, generator, io_testing)
- Replace deprecated gen() → random() (floatnum, realnum, kmeans)
- Replace deprecated gen_range() → random_range() (kmeans, base_forest_regressor, random_forest_classifier, base_tree_regressor)
- Replace distributions:: → distr:: module path (generator, io_testing)
- Replace DistString → SampleString trait (io_testing)
- Replace Uniform::from(range) → Uniform::new(a, b) (generator)
- Remove infallible .unwrap() from SmallRng::from_rng() (realnum)
* fix: replace removed small_rng feature with alloc for rand 0.10.1 compatibility
rand 0.9+ removed the `small_rng` cargo feature — SmallRng is now
unconditionally available via the `alloc` feature. Requesting `small_rng`
caused `cargo build --no-default-features` to fail with:
package `smartcore` depends on `rand` with feature `small_rng`
but `rand` does not have that feature.
Fix: replace `features = ["small_rng"]` with `features = ["alloc"]`.
* fix: replace rand::Rng with rand::RngExt and gen_range with random_range for rand 0.10 compatibility
* fix: resolve rand 0.10 compile errors in rand_custom and generator
- rand_custom.rs: replace `use rand::RngCore` with `use rand::Rng`
so that `.next_u64()` resolves on ThreadRng (RngCore is no longer
re-exported at the rand crate root; Rng supertrait covers it)
- dataset/generator.rs: add `use rand_distr::Distribution`
rand::prelude::* no longer pulls in rand_distr's Distribution
trait in rand 0.10, so Normal::sample() was unresolved on all
call sites in make_blobs, make_circles and make_moons
* fix: bump getrandom wasm dep to 0.4 to match rand_core 0.9 requirement
rand 0.10 → rand_core 0.9 → getrandom 0.4 (transitively).
The old wasm32 getrandom = "0.3" pin caused a version mismatch:
the wasm_js feature flag and fill_inner/inner_u32/inner_u64 symbols
did not exist in the 0.3 API surface used by 0.4 consumers.
Bumping to getrandom = "0.4" aligns the explicit dep with the
transitive one; the `js` feature (`getrandom/wasm_js`) is unchanged
because the flag name is identical in getrandom 0.4.
* fix: bump rand_distr to 0.5.1 and use rand::distr::Distribution
rand_distr 0.5.0 depends on rand 0.9.x, causing a two-crate version
conflict: ThreadRng from rand 0.10 does not satisfy the Rng bound
defined in rand 0.9's distribution.rs, so every .sample() call fails
with E0277 (DerefMut / RngCore unsatisfied).
rand_distr 0.5.1 is the patch that retargets the crate to rand 0.10,
unifying both ThreadRng and the Distribution trait to the same version.
Also replace `use rand_distr::Distribution` with
`use rand::distr::Distribution` in generator.rs: after the bump
both Uniform (from rand) and Normal (from rand_distr 0.5.1) implement
rand 0.10's Distribution trait, so using the single canonical import
from rand eliminates any remaining trait-version ambiguity.
* fix: import both Distribution traits to cover Uniform and Normal
rand::distr::Distribution covers Uniform (from rand 0.10).
rand_distr::Distribution covers Normal (from rand_distr 0.5.1).
Both traits define .sample() but are distinct types; aliasing
rand_distr::Distribution as DistrDistribution avoids the name
ambiguity while keeping both call sites resolvable.
* fix: replace rand_distr::Normal with rand::distr::Normal in generator
rand_distr (any version 0.5.x) still carries rand = "^0.9" in its own
dependency tree, so Cargo resolves it against rand 0.9.3 even when
rand_distr = "0.5.1" is specified. This causes the persistent
E0277: ThreadRng (from rand 0.10) does not satisfy rand 0.9's Rng bound.
rand 0.10 ships rand::distr::Normal natively, so rand_distr is not
needed for generator.rs at all. Switching to rand::distr::Normal
and rand::distr::Distribution eliminates the cross-version conflict
entirely. rand_distr remains an optional dep for other future use
but is removed from the datasets feature deps.
* fix: use rand_distr::Normal with rand::distr::Distribution trait
rand_distr 0.5.1 does not yet target rand 0.10, so rand::distr::Normal
does not exist. The correct bridging pattern is:
- rand_distr::Normal for the struct (from rand_distr 0.5.1)
- rand::distr::Distribution for the trait (from rand 0.10)
Cargo unifies the Distribution trait across the two versions via the
rand_core re-export, so .sample(&mut rng) works with a rand 0.10
ThreadRng as long as rand::distr::Distribution is the imported trait.
Also restores rand_distr as optional dep and in datasets feature.
* fix: replace rand_distr with rand::distr::StandardNormal for Normal sampling
rand_distr 0.5.1 depends on rand 0.9 and cannot be made compatible with
rand 0.10 via trait imports — they are distinct incompatible types.
rand 0.10 ships rand::distr::StandardNormal (samples N(0,1)) natively.
Normal(mean, std) sampling is trivially: mean + std * StandardNormal.sample(rng)
This removes the rand_distr dependency entirely, solving the version
conflict at the root.
* fix: implement Normal sampling via Box-Muller using rand 0.10 primitives only
rand::distr::StandardNormal does not exist in rand 0.10 — StandardNormal
is only in rand_distr, which conflicts with rand 0.10.
Instead, implement sample_normal() using the Box-Muller transform:
z = sqrt(-2 * ln(u1)) * cos(2π * u2) where u1,u2 ~ Uniform(0,1)
This uses only rand::distr::Uniform and rand::Rng from rand 0.10,
requiring no external crates.
* style: rustfmt sample_with_replacement signature in random_forest_classifier1 parent 4c275d7 commit 66f77af
10 files changed
Lines changed: 73 additions & 64 deletions
File tree
- src
- cluster
- dataset
- ensemble
- numbers
- readers
- tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| |||
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
40 | | - | |
41 | | - | |
| 39 | + | |
| 40 | + | |
42 | 41 | | |
43 | | - | |
| 42 | + | |
44 | 43 | | |
45 | 44 | | |
46 | | - | |
| 45 | + | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
359 | | - | |
| 359 | + | |
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
385 | | - | |
| 385 | + | |
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 3 | + | |
| 4 | + | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
9 | 18 | | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
13 | 22 | | |
14 | 23 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
18 | 27 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
22 | 31 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
27 | 36 | | |
28 | 37 | | |
29 | | - | |
| 38 | + | |
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
33 | 42 | | |
34 | 43 | | |
35 | | - | |
| 44 | + | |
36 | 45 | | |
37 | 46 | | |
38 | 47 | | |
| |||
59 | 68 | | |
60 | 69 | | |
61 | 70 | | |
62 | | - | |
63 | | - | |
| 71 | + | |
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
67 | 75 | | |
68 | 76 | | |
69 | | - | |
70 | | - | |
| 77 | + | |
| 78 | + | |
71 | 79 | | |
72 | 80 | | |
73 | 81 | | |
74 | 82 | | |
75 | | - | |
76 | | - | |
| 83 | + | |
| 84 | + | |
77 | 85 | | |
78 | 86 | | |
79 | 87 | | |
| |||
96 | 104 | | |
97 | 105 | | |
98 | 106 | | |
99 | | - | |
100 | | - | |
| 107 | + | |
101 | 108 | | |
102 | 109 | | |
103 | 110 | | |
104 | 111 | | |
105 | 112 | | |
106 | | - | |
107 | | - | |
| 113 | + | |
| 114 | + | |
108 | 115 | | |
109 | 116 | | |
110 | 117 | | |
111 | 118 | | |
112 | | - | |
113 | | - | |
| 119 | + | |
| 120 | + | |
114 | 121 | | |
115 | 122 | | |
116 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
587 | 587 | | |
588 | 588 | | |
589 | 589 | | |
590 | | - | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
591 | 595 | | |
592 | 596 | | |
593 | 597 | | |
| |||
603 | 607 | | |
604 | 608 | | |
605 | 609 | | |
606 | | - | |
| 610 | + | |
607 | 611 | | |
608 | 612 | | |
609 | 613 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 72 | + | |
| 73 | + | |
76 | 74 | | |
77 | 75 | | |
78 | 76 | | |
| |||
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 119 | + | |
| 120 | + | |
125 | 121 | | |
126 | 122 | | |
127 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | | - | |
| 295 | + | |
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | | - | |
| 339 | + | |
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| |||
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
366 | | - | |
| 366 | + | |
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| |||
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
479 | | - | |
| 479 | + | |
480 | 480 | | |
481 | 481 | | |
482 | 482 | | |
| |||
0 commit comments