Skip to content

fix(datasets): decouple datasets feature from std_rand - #499

Open
ShryukGrandhi wants to merge 1 commit into
smartcorelib:mainfrom
ShryukGrandhi:fix/issue-416-no-std-step-3-decouple-datasets-feature
Open

ShryukGrandhi wants to merge 1 commit into
smartcorelib:mainfrom
ShryukGrandhi:fix/issue-416-no-std-step-3-decouple-datasets-feature

Conversation

@ShryukGrandhi

Copy link
Copy Markdown
Contributor

Fixes #416

Checklist

  • My branch is up-to-date with main branch.
  • Everything works and tested on latest stable Rust.
  • Coverage and Linting have been applied

Current behaviour

The datasets feature enables std_rand. The embedded toy datasets (iris, boston, digits, ...) do not use an RNG. But the generators in dataset/generator.rs (make_blobs, make_circles, make_moons) call rand::rng(), which exists only with rand/thread_rng. If you remove std_rand from datasets, cargo build --no-default-features --features datasets fails with cannot find function rng in crate rand. The test helper readers/io_testing.rs also calls rand::rng() to make temporary file names, so cargo test --features datasets cannot compile without std_rand.

New expected behaviour

  • Cargo.toml: datasets = ["serde"].
  • The generators get their RNG from rand_custom::get_rng_impl(None), like the other modules in the crate. With std_rand, the RNG takes its seed from OS entropy, so the output stays random as before. Without std_rand, the RNG is SmallRng with a fixed seed (or getrandom with js), so the output is the same for each call.
  • TemporaryTextFile (test-only) makes its file name from the process id and an atomic counter. It does not need an OS RNG.
  • New test test_generators_without_std_rand_are_reproducible. It runs only when std_rand and js are off, and it checks that the generators compile and give reproducible output in that configuration.

Change logs

Changed

  • The datasets feature no longer enables std_rand. If you want non-deterministic generator output, enable std_rand together with datasets. This is in CHANGELOG.md.

Testing

  • cargo build --no-default-features --features datasets (failed before the fix, passes now)
  • cargo test, cargo test --features datasets, cargo test --features datasets,std_rand, cargo test --all-features: all pass
  • cargo fmt --all -- --check, cargo clippy --all-features -- -Drust-2018-idioms -Dwarnings: clean

)

Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>
@ShryukGrandhi
ShryukGrandhi requested a review from Mec-iS as a code owner October 22, 2026 18:17
@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.58%. Comparing base (9eaae9e) to head (5f661ed).
⚠️ Report is 204 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #499       +/-   ##
===========================================
+ Coverage   43.97%   85.58%   +41.60%     
===========================================
  Files          85       96       +11     
  Lines        7281     9373     +2092     
===========================================
+ Hits         3202     8022     +4820     
+ Misses       4079     1351     -2728     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no-std Step 3: decouple datasets feature from std_rand in Cargo.toml

1 participant