mikera / core.matrix

core.matrix : Multi-dimensional array programming API for Clojure
Other
700 stars 113 forks source link

Exception when `mmul`ing `fill`ed ndarrays #336

Open cguenthner opened 5 years ago

cguenthner commented 5 years ago

I'm trying to understand the following behavior of the ndarray implementation and am not sure if there's a bug or if I'm misunderstanding something. If I create a new array using fill! and multiply it by its transpose, I get the expected result. If I create a new array using fill and multiply it by its transpose, I get an exception. I don't observe this behavior with the vectorz or persistent-vector implementations.

(m/set-current-implementation :ndarray)

(def a (m/fill! (m/new-array [2 3]) 1))
(m/mmul a (m/transpose a)) ; => #object[clojure.core.matrix.impl.ndarray_object.NDArray 0x1b4f7b03 [[3.0 3.0] [3.0 3.0]]]

(def b (m/fill (m/new-array [2 3]) 1))
(m/add b b) ; => [[2 2 2] [2 2 2]]
(m/mmul b (m/transpose b))
; => Unhandled java.lang.IllegalArgumentException
;    No implementation of method: :set-2d! of protocol: #'clojure.core.matrix.protocols/PIndexedSettingMutable
;    found for class: clojure.lang.PersistentVector