> ... use Array (Int,Int) Double, as it accesses its elements in O(1).
thanks for the comments.
I don't need O(dim^0) element access -
I need O(dim^reasonable) addition and multiplication.
Modelling a matrix as [[Element]] should be nearly fine
(for sequential execution), I think these are quadratic/cubic:
a * b = zipWith (zipWith (+)) a b
a * b = for a $ \ row ->
for ( transpose b ) $ \ col ->
sum $ zipWith (*) row col
The only problem with this code is that 'transpose b'
(assuming the compiler lifts it to outer scope)
allocates memory that later becomes garbage,
but not immediately, since it is needed several times.
( in the above, for = flip map ,
which is missing from the standard libs?
by analogy to forM = flip mapM )
Best regards, J.W.
Haskell-Cafe mailing list