use crate::rotta_rs_module::{ arrayy::Arrayy, BackwardLabel, NodeType, Tensor };
pub fn dot(a: &Tensor, b: &Tensor) -> Tensor {
let output = a.value().dot(&b.value());
let tensor = Tensor::from_arrayy(output);
tensor.update_parent(vec![a.node.clone(), b.node.clone()]);
tensor.node.lock().as_mut().unwrap().label = Some(
BackwardLabel::Dot(a.node.clone(), b.node.clone())
);
tensor
}
pub fn d_dot(a: &NodeType, b: &NodeType, grad: &Arrayy) {
let mut a = a.lock().unwrap();
let mut b = b.lock().unwrap();
if a.requires_grad {
let d_a = &b.value * grad;
a.add_grad(d_a);
}
if b.requires_grad {
let d_b = &a.value * grad;
b.add_grad(d_b);
}
}