dimforge / dimforge/nalgebra

from_distribution behaviour with rand 0.6

Open
#528 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

edit: I just realized that the deps for nalgebra say `rand ^0.5`, so I guess it was to be expected. Still, I'm puzzled by the error.

The following code compiles with `rand 0.5`

```Rust
use rand::prelude::*;
use rand::distributions::StandardNormal;

let mut rng = rand::thread_rng();
let dist = StandardNormal;
let x : DVector = DVector::::from_distribution(4,&dist,&mut rng);
println!("{:}",x);
```

but raises an error with `rand 0.6`

```
error[E0277]: the trait bound `rand::distributions::normal::StandardNormal: rand::distributions::Distribution` is not satisfied
let x : DVector = DVector::::from_distribution(4,&dist,&mut rng);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `rand::distributions::Distribution` is not implemented for `rand::distributions::normal::StandardNormal`
= note: required by `nalgebra::base::construction::>::Buffer>>::from_distribution`
```

Other use of `Distribution` trait seem to compile fine with `rand 0.6`, so I imagine the problem comes from nalgebra compatibility with 0.6:
```Rust
fn f, R: Rng>(dist: D, r: &mut R) -> f64 {
dist.sample(r)
}
let mut rng = rand::thread_rng();
let v = f(StandardNormal, &mut rng);
println!("{}",v);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.