Repository: coreylowman/dfdx (language: rust)

Issue:
`dfdx/examples/04-gradients.rs` crashes
Here's part of the trace:

```
The application panicked (crashed).
Message:  called `Option::unwrap()` on a `None` value
Location: /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dfdx-0.12.1/src/tensor/gradients.rs:104

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 9 frames hidden ⋮
  10: core::panicking::panic::h0ead933cb8f56d66
      at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:117
  11: dfdx::tensor::gradients::Gradients<E,D>::get::h50d098d0f731a918
```

The problem appears to be that `a` gets grads but `weight` doesn't.


Discussion / hints:

Fix patch:
diff --git a/examples/04-gradients.rs b/examples/04-gradients.rs
index b7357a18c..9ce2b2615 100644
--- a/examples/04-gradients.rs
+++ b/examples/04-gradients.rs
@@ -38,9 +38,9 @@ fn main() {
 
     // now you can extract gradients for specific tensors
     // by querying with them
-    let weight_grad: [[f32; 2]; 4] = gradients.get(&weight).array();
-    dbg!(weight_grad);
-
     let a_grad: [[f32; 4]; 3] = gradients.get(&a).array();
     dbg!(a_grad);
+
+    // NOTE: this will panic, because we didn't allocate gradients for `weight`
+    // let weight_grad: [[f32; 2]; 4] = gradients.get(&weight).array();
 }


Test patch: