mirror of
https://github.com/huggingface/candle.git
synced 2025-06-17 11:08:52 +00:00
Cosmetic change to the backprop test.
This commit is contained in:
@ -5,9 +5,7 @@ use candle::{Device, Tensor};
|
|||||||
fn simple_grad() -> Result<()> {
|
fn simple_grad() -> Result<()> {
|
||||||
let x = Tensor::var(&[3f32, 1., 4.], Device::Cpu)?;
|
let x = Tensor::var(&[3f32, 1., 4.], Device::Cpu)?;
|
||||||
let five = Tensor::new(&[5f32, 5., 5.], Device::Cpu)?;
|
let five = Tensor::new(&[5f32, 5., 5.], Device::Cpu)?;
|
||||||
let x_times_five = x.mul(&five)?;
|
let y = x.mul(&x)?.add(&x.mul(&five)?)?.add(&five)?;
|
||||||
let x2 = x.mul(&x)?;
|
|
||||||
let y = x2.add(&x_times_five)?.add(&five)?;
|
|
||||||
let grads = y.backward()?;
|
let grads = y.backward()?;
|
||||||
let grad_x = grads.get(&x.id()).context("no grad for x")?;
|
let grad_x = grads.get(&x.id()).context("no grad for x")?;
|
||||||
assert_eq!(x.to_vec1::<f32>()?, [3., 1., 4.]);
|
assert_eq!(x.to_vec1::<f32>()?, [3., 1., 4.]);
|
||||||
|
Reference in New Issue
Block a user