More QOL changes, binary op for constants.

This commit is contained in:
laurent
2023-06-21 08:59:08 +01:00
parent 0839954770
commit f319583530
2 changed files with 22 additions and 6 deletions

View File

@ -4,7 +4,7 @@ use candle::{Device, Tensor};
#[test]
fn simple_grad() -> Result<()> {
let x = Tensor::var(&[3f32, 1., 4.], Device::Cpu)?;
let y = x.mul(&x)?.add(&x.affine(5., 0.)?)?.affine(1., 4.)?;
let y = (((&x * &x)? + &x * 5f64)? + 4f64)?;
let grads = y.backward()?;
let grad_x = grads.get(&x.id()).context("no grad for x")?;
assert_eq!(x.to_vec1::<f32>()?, [3., 1., 4.]);