[Haskell-cafe] "sum" in hmatrix and blas?
Xiao-Yong Jin
xj2106 at columbia.edu
Sat Jun 7 18:45:01 EDT 2008
Hi, probably I am just being dumb, but what is the most
efficient way to do a sum of every elements in a Vector of
either hmatrix or blas? I know there is sum of absolute
values from BLAS. So what about I want a plain "sum"?
I can only think of the following two ways.
1. Using Data.List.foldl', so it is
> sum' = foldl' (+) 0 . toList
in hmatrix or
> sum' = foldl' (+) 0 . elems
in blas.
2. Using <.>, so it is
> sum' v = constant 1 (dim v) <.> v
in hmatrix or
> sum' v = constant (dim v) 1 <.> v
in blas.
Which one is better? I guess it probably depends on the
internal implementation of BLAS, but I am actually thinking
in some thing similar to
> t += *v++;
Any delightful idea to convert my mind from a C shaped one
to a Haskell shaped one?
Best,
Xiao-Yong
--
c/* __o/*
<\ * (__
*/\ <
More information about the Haskell-Cafe
mailing list