Fix randn cpu (#382)

* Change distributions

Standard generates in [0, 1), Normal is correct.

* Add test

Not sure if this is the best place to put  the test

* Remove unnecessary use
This commit is contained in:
Lei
2023-08-10 00:33:44 -04:00
committed by GitHub
parent 25ec2d9f6b
commit 3bbc08a8df
4 changed files with 40 additions and 10 deletions

View File

@ -9,6 +9,23 @@ fn zeros(device: &Device) -> Result<()> {
Ok(())
}
fn randn_hasneg(device: &Device) -> Result<()> {
let s = 200;
let t = Tensor::randn(
0f32,
1f32, s
as usize,
&Device::Cpu
)?
.to_vec1::<f32>()?;
for i in t {
if i < 0. {
return Ok(())
}
}
panic!("randn failed to generate a negative number")
}
fn add_mul(device: &Device) -> Result<()> {
let tensor = Tensor::new(&[3f32, 1., 4.], device)?;
let dim1 = tensor.dims1()?;
@ -849,6 +866,7 @@ fn broadcasting(device: &Device) -> Result<()> {
}
test_device!(zeros, zeros_cpu, zeros_gpu);
test_device!(randn_hasneg, randn_hasneg_cpu, randn_hasneg_gpu);
test_device!(add_mul, add_mul_cpu, add_mul_gpu);
test_device!(tensor_2d, tensor_2d_cpu, tensor_2d_gpu);
test_device!(narrow, narrow_cpu, narrow_gpu);