multiply function
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
Implementation
// SCALAR (0D) OPERATIONS
////////////////////////////////////////////////////////////////////////////////
Tensor<Scalar> multiply(Tensor<Scalar> a, Tensor<Scalar> b) {
Scalar outValue = a.value * b.value;
Tensor<Scalar> out = Tensor<Scalar>(outValue);
out.creator = Node(
[a, b],
() {
a.grad += out.grad * b.value;
b.grad += out.grad * a.value;
},
opName: 'multiply_scalar', // <-- Changed for clarity and to fix the bug
cost: 1,
);
return out;
}