uncomplicate / neanderthal

Fast Clojure Matrix Library
http://neanderthal.uncomplicate.org
Eclipse Public License 1.0
1.07k stars 56 forks source link

Like the sum function, is there a prod function? #52

Closed lungsi closed 5 years ago

lungsi commented 5 years ago

As sum function

(sum x)
;;Sums values of entries of a vector or matrix x.
(sum (dv -1 2 -3)) => -2.0

Is there a function for product of values of entries of a vector?

blueberry commented 5 years ago

No, because for large vectors or matrices, that product will likely overflow unless all elements are close to 1.0. If you need it anyway, you can use (fold * x) or (fold (double-fn *) x) (but, again, depending of the contents it might not be numerically stable).