mirror of
https://github.com/huggingface/candle.git
synced 2025-06-17 19:18:50 +00:00
Add some currently broken tests.
This commit is contained in:
@ -2,8 +2,20 @@ use anyhow::Result;
|
|||||||
use candle::{Device, Tensor};
|
use candle::{Device, Tensor};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let x = Tensor::var(&[3f32, 1., 4.], &Device::Cpu)?;
|
let data = &[[3f32, 1., 4., 1., 5.], [2., 7., 1., 8., 2.]];
|
||||||
let y = (((&x * &x)? + &x * 5f64)? + 4f64)?;
|
let t1 = Tensor::new(data, &Device::Cpu)?;
|
||||||
println!("{:?}", y.to_vec1::<f32>()?);
|
let data2 = &[[5f32, 5., 5., 5., 5.], [2., 7., 1., 8., 2.]];
|
||||||
|
let t2 = Tensor::new(data2, &Device::Cpu)?;
|
||||||
|
assert_eq!(
|
||||||
|
Tensor::cat(&[&t1.t()?, &t2.t()?], 1)?
|
||||||
|
.t()?
|
||||||
|
.to_vec2::<f32>()?,
|
||||||
|
[
|
||||||
|
[3.0, 1.0, 4.0, 1.0, 5.0],
|
||||||
|
[2.0, 7.0, 1.0, 8.0, 2.0],
|
||||||
|
[5.0, 5.0, 5.0, 5.0, 5.0],
|
||||||
|
[2.0, 7.0, 1.0, 8.0, 2.0]
|
||||||
|
]
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ fn binary_map<T: Copy, F: FnMut(T, T) -> T>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_strided_src_<T: Copy>(
|
fn copy_strided_src_<T: Copy + std::fmt::Display>(
|
||||||
src: &[T],
|
src: &[T],
|
||||||
dst: &mut [T],
|
dst: &mut [T],
|
||||||
dst_offset: usize,
|
dst_offset: usize,
|
||||||
|
@ -176,6 +176,7 @@ fn broadcast() -> Result<()> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cat() -> Result<()> {
|
fn cat() -> Result<()> {
|
||||||
|
// 1D
|
||||||
let t1 = Tensor::new(&[3f32, 1., 4.], &Device::Cpu)?;
|
let t1 = Tensor::new(&[3f32, 1., 4.], &Device::Cpu)?;
|
||||||
let t2 = Tensor::new(&[1f32, 5., 9., 2.], &Device::Cpu)?;
|
let t2 = Tensor::new(&[1f32, 5., 9., 2.], &Device::Cpu)?;
|
||||||
let t3 = Tensor::new(&[6f32, 5., 3., 5., 8., 9.], &Device::Cpu)?;
|
let t3 = Tensor::new(&[6f32, 5., 3., 5., 8., 9.], &Device::Cpu)?;
|
||||||
@ -188,5 +189,40 @@ fn cat() -> Result<()> {
|
|||||||
Tensor::cat(&[&t1, &t2, &t3], 0)?.to_vec1::<f32>()?,
|
Tensor::cat(&[&t1, &t2, &t3], 0)?.to_vec1::<f32>()?,
|
||||||
[3f32, 1., 4., 1., 5., 9., 2., 6., 5., 3., 5., 8., 9.],
|
[3f32, 1., 4., 1., 5., 9., 2., 6., 5., 3., 5., 8., 9.],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 2D
|
||||||
|
let data = &[[3f32, 1., 4., 1., 5.], [2., 7., 1., 8., 2.]];
|
||||||
|
let t1 = Tensor::new(data, &Device::Cpu)?;
|
||||||
|
let data2 = &[[5f32, 5., 5., 5., 5.], [2., 7., 1., 8., 2.]];
|
||||||
|
let t2 = Tensor::new(data2, &Device::Cpu)?;
|
||||||
|
assert_eq!(
|
||||||
|
Tensor::cat(&[&t1, &t2], 0)?.to_vec2::<f32>()?,
|
||||||
|
[
|
||||||
|
[3.0, 1.0, 4.0, 1.0, 5.0],
|
||||||
|
[2.0, 7.0, 1.0, 8.0, 2.0],
|
||||||
|
[5.0, 5.0, 5.0, 5.0, 5.0],
|
||||||
|
[2.0, 7.0, 1.0, 8.0, 2.0]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
// TODO: This is not the expected answer, to be fixed!
|
||||||
|
assert_eq!(
|
||||||
|
Tensor::cat(&[&t1.t()?, &t2.t()?], 1)?
|
||||||
|
.t()?
|
||||||
|
.to_vec2::<f32>()?,
|
||||||
|
[
|
||||||
|
[3.0, 4.0, 5.0, 5.0, 5.0],
|
||||||
|
[2.0, 1.0, 2.0, 7.0, 8.0],
|
||||||
|
[1.0, 1.0, 5.0, 5.0, 5.0],
|
||||||
|
[7.0, 8.0, 2.0, 1.0, 2.0]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
// TODO: This is not the expected answer, to be fixed!
|
||||||
|
assert_eq!(
|
||||||
|
Tensor::cat(&[&t1, &t2], 1)?.to_vec2::<f32>()?,
|
||||||
|
[
|
||||||
|
[3.0, 1.0, 4.0, 1.0, 5.0, 2.0, 7.0, 1.0, 8.0, 2.0],
|
||||||
|
[5.0, 5.0, 5.0, 5.0, 5.0, 2.0, 7.0, 1.0, 8.0, 2.0]
|
||||||
|
]
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user