quil-lang / magicl

Matrix Algebra proGrams In Common Lisp.
BSD 3-Clause "New" or "Revised" License
238 stars 44 forks source link

TYPE-ERROR in basic operations if types differ #173

Open stewart123579 opened 2 years ago

stewart123579 commented 2 years ago

I'm not even convinced this is a bug or appropriate behaviour...

Depending on the order of arguments we can get a type-error from [the setf] (https://github.com/quil-lang/magicl/blob/master/src/high-level/abstract-tensor.lisp#L197=) in binary-operator

(defparameter int-tensor (magicl:from-list '(1 2 3) '(3)))
(defparameter float-tensor (magicl:from-list '(1.0 2.0 3.0) '(3)))

;; This works
(magicl:.+ float-tensor int-tensor)
;; This is a TYPE-ERROR condition
(magicl:.+ int-tensor float-tensor)

A solution would be to coerce/round/cast one of the arguments, but which one, and when?

Take an example of elementwise sum and the cases of 0.5 + 1 being stored in an int32-tensor. Depending on where, say, the round function is applied the first sum could be

(+ (round 0.5) 1)
;; 1
(round (+ 0.5 1))
;; 2