gorgonia / tensor

package tensor provides efficient and generic n-dimensional arrays in Go that are useful for machine learning and deep learning purposes
Apache License 2.0
359 stars 49 forks source link

Fix scalar operations (fix for #52) #54

Closed bezineb5 closed 4 years ago

bezineb5 commented 4 years ago

This is a fix for issue #52 I investigated further and found that the generated methods (MulScalar) work as expected. However, the problem lies in this comment: // MulScalar performs t × s elementwise. The leftTensor parameter indicates if the tensor is the left operand. **Only scalar types are accepted in s.** But the Mul method (in api_arith.go) was not taking that into account when the 2 parameters are tensors (including "scalar tensors"), and was sending a non-scalar tensor to the "s" parameter. The swapping of parameter is correctly done in other branches, when doing a Mul with non-tensor arguments.

For the other operations, the case of scalar tensors was not taken into account.

I hope this helps and clarifies, Thanks!

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.2%) to 72.986% when pulling 1265ce698a07f997b01b28459f42b0b3b78050cb on bezineb5:fix-scalar-ops into ea8ef1f6e3b11e8476fb8ac81ae37fe6f749fc18 on gorgonia:master.