mirror of
https://github.com/huggingface/candle.git
synced 2025-06-16 10:38:54 +00:00
Get the addition/multiplication to work.
This commit is contained in:
@ -1,15 +1,26 @@
|
||||
use candle::{DType, Device, Result, Tensor};
|
||||
|
||||
#[test]
|
||||
fn add() -> Result<()> {
|
||||
fn zeros() -> Result<()> {
|
||||
let tensor = Tensor::zeros((5, 2), DType::F32, Device::Cpu);
|
||||
let (dim1, dim2) = tensor.shape().r2()?;
|
||||
assert_eq!(dim1, 5);
|
||||
assert_eq!(dim2, 2);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_mul() -> Result<()> {
|
||||
let tensor = Tensor::new([3f32, 1., 4.].as_slice(), Device::Cpu)?;
|
||||
let dim1 = tensor.shape().r1()?;
|
||||
assert_eq!(dim1, 3);
|
||||
let content: Vec<f32> = tensor.to_vec1()?;
|
||||
assert_eq!(content, [3., 1., 4.]);
|
||||
let tensor = Tensor::add(&tensor, &tensor)?;
|
||||
let content: Vec<f32> = tensor.to_vec1()?;
|
||||
assert_eq!(content, [6., 2., 8.]);
|
||||
let tensor = Tensor::mul(&tensor, &tensor)?;
|
||||
let content: Vec<f32> = tensor.to_vec1()?;
|
||||
assert_eq!(content, [36., 4., 64.]);
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user