mirror of
https://github.com/huggingface/candle.git
synced 2025-06-16 10:38:54 +00:00
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:
@ -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);
|
||||
|
Reference in New Issue
Block a user