
(m - es)^2/es
let res = listMatrix (shape m) [ (o-e)^2 / e | o <- colElems m | e <- colElems es ] where colElems = concatMap elems . cols res
Hi Cetin, This is probably the easiest way: listMatrix (2,2) [0.6163270413689804,0.600918865334756,0.33217626255600896,0.3238718559921087 ] This will create 2 temporary arrays. Alternatively, listMatrix (2,2) [0.6163270413689804,0.600918865334756,0.33217626255600896,0.3238718559921087 ] In a later version of the library, "colElems" will probably be built- in. This version has the disadvantage that it doesn't use BLAS calls. If you *really* want to get tricky and eliminate temporary arrays:
runSTMatrix $ do res <- newCopyMatrix m subMatrix res es modifyWith (^2) res divMatrix res es return res
Now, to get the sum:
sumAbs $ vectorFromMatrix res 1.8732940252518542
or
sum $ elems res 1.8732940252518542
The first version will usually be more efficient, since it calls the BLAS1 function "dasum". Patrick
participants (1)
-
Patrick Perry