Skip to content

fix: import rand distributions from ndarray_rand::rand_distr to fix E0277 trait-bound#55

Merged
hyperpolymath merged 2 commits into
mainfrom
fix/use-ndarray-rand-distr-namespace
May 14, 2026
Merged

fix: import rand distributions from ndarray_rand::rand_distr to fix E0277 trait-bound#55
hyperpolymath merged 2 commits into
mainfrom
fix/use-ndarray-rand-distr-namespace

Conversation

@hyperpolymath
Copy link
Copy Markdown
Owner

Why

Both crates/esn/src/lib.rs and crates/lsm/src/lib.rs import Normal, Uniform, Bernoulli from the top-level rand_distr crate, then pass those distribution instances to:

  • Array2::random_using(...) from ndarray_rand::RandomExt, which requires ndarray_rand::rand_distr::Distribution
  • rng.sample(...) which works fine with either

ndarray-rand re-exports its own pinned version of rand_distr and the RandomExt::random_using trait bound is over that re-exported Distribution. When the top-level rand_distr version drifts (Dependabot bump), it stops being the same type as ndarray_rand::rand_distr::Distribution and the trait bound fails:

error[E0277]: the trait bound `rand_distr::Normal<{float}>: ndarray_rand::rand_distr::Distribution<_>` is not satisfied

…on every Dependabot PR that touched the rand family.

Fix

Import distributions through ndarray_rand::rand_distr so the version always matches the trait bound. No runtime / behaviour change.

Tested

Static: rg confirms Normal/Uniform/Bernoulli are only used through rng.sample() and Array2::random_using(), both of which accept the ndarray_rand::rand_distr versions.

After this lands, the workspace's top-level rand_distr dep may be unused — left in place to avoid scope creep; can drop in a follow-up if cargo-udeps flags it.

hyperpolymath and others added 2 commits May 14, 2026 14:54
…and_distr

ndarray-rand's RandomExt expects distributions from ndarray_rand::rand_distr (its own re-export of rand_distr), not from the top-level rand_distr crate, because ndarray-rand pins its own internal version. With the top-level import the build fails with E0277:

    the trait bound rand_distr::Normal<{float}>: ndarray_rand::rand_distr::Distribution<_> is not satisfied

import from ndarray_rand::rand_distr to keep the version aligned.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…and_distr

ndarray-rand's RandomExt expects distributions from ndarray_rand::rand_distr (its own re-export of rand_distr), not from the top-level rand_distr crate, because ndarray-rand pins its own internal version. With the top-level import the build fails with E0277:

    the trait bound rand_distr::Normal<{float}>: ndarray_rand::rand_distr::Distribution<_> is not satisfied

import from ndarray_rand::rand_distr to keep the version aligned.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@hyperpolymath hyperpolymath merged commit b33a5fd into main May 14, 2026
9 of 10 checks passed
@hyperpolymath hyperpolymath deleted the fix/use-ndarray-rand-distr-namespace branch May 14, 2026 13:54
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.

1 participant