usecrate::Tensor;pubtraitBackwardOp: std::fmt::Debug + Send + Sync {fnbackward(&self, grad:&Tensor);}// Simple engine for now
pubfnbackward(tensor:&Tensor, grad:&Tensor){// DFS with visited set to avoid infinite loops if cycles exist (though usually DAG)
// But for correct gradient accumulation in DAG, we need topological sort.
// Here we just do recursive call.
// To avoid re-computation, we should use a proper engine.
// For now, let's just delegate to the Op.
ifletSome(op)=&tensor.inner.op {
op.backward(grad);}}