
20 Apr
2006
20 Apr
'06
6:10 p.m.
Hello Bulat, Bulat Ziganshin wrote:
the fastest way to calculate dot product is:
dot :: STUArray s Int Double -> STUArray s Int Double -> ST s Double dot x y = do let (l,r) = bounds x cycle sum i | sum `seq` i>r = return sum cycle sum i = do xi <- readArray x i yi <- readArray y i cycle (sum+xi*yi) (i+1) cycle 0 l
That is a nice implementation. In fact, creating uninitialized arrays with newArray_ and then setting all its elements to some value using a function similar to this one is dramatically faster than creating initialized arrays with newArray. Gunnar.