module StdArrays where --import Data.Array.Unboxed import Data.Array matMult :: Array (Int,Int) Double -> Array (Int,Int) Double -> Array (Int,Int) Double matMult x y = array resultBounds [((i,j), sum [x!(i,k) * y!(k,j) | k <- range (lj,uj)]) | i <- range (li,ui), j <- range (lj',uj') ] where ((li,lj),(ui,uj)) = bounds x ((li',lj'),(ui',uj')) = bounds y resultBounds | (lj,uj)==(li',ui') = ((li,lj'),(ui,uj')) | otherwise = error "matMult: incompatible bounds" matMult' x y = accumArray (+) 0 resultBounds [((i,j), x!(i,k) * y!(k,j)) | i <- range (li,ui), j <- range (lj',uj'), k <- range (lj,uj) ] where ((li,lj),(ui,uj)) = bounds x ((li',lj'),(ui',uj')) = bounds y resultBounds | (lj,uj)==(li',ui') = ((li,lj'),(ui,uj')) | otherwise = error "matMult: incompatible bounds"