[Haskell-cafe] Haskell, C and Matrix Multiplication
Blake Rain
blake.rain at gmail.com
Mon Jan 17 11:38:30 CET 2011
On Mon, 2011-01-17 at 10:13 +0000, Pedro Vasconcelos wrote:
> On Mon, 17 Jan 2011 07:45:04 +0000
> Blake Rain <blake.rain at gmail.com> wrote:
>
> > So, after drinking some coffee and having a smoke, I started the
> > Haskell version:
> >
> > [foldl (+) 0 $ zipWith (*) x y | x <- m1, y <- transpose m2]
> >
>
> I don't think this is correct; it's type is
>
> (Num a) => [[a]] -> [[a]] -> [a]
>
> rather than the expected
>
> (Num a) => [[a]] -> [[a]] -> [[a]]
>
> How about:
>
> mult m1 m2 = [[foldl (+) 0 $ zipWith (*) x y | y<-transpose m2] | x<-m1]
So sorry, I meant:
mult :: (Num a) => [[a]] -> [[a]] -> [a]
mult m1 m2 = [foldl (+) 0 $ zipWith (*) x y | x <- m1, y <- transpose
m2]
Lack of sleep.
>
> Regarding performance: did you make sure you're forcing the
> evaluation of the result matrix?
I thought I was. It's printing the results as expected. Could be I'm
just imagining I am and suffering a delusion or misunderstanding.
>
> Regards,
>
> Pedro
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list