-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dense-linear-algebra: Getting stream fusion to work across Matrix
's
#60
Comments
Interestingly, this fuses: testRewrite3 :: Matrix -> Double
testRewrite3 (Matrix r c v) = U.sum . flip (\(r,c,v) j -> U.generate r (\i -> v `U.unsafeIndex` (j + i * c))) 0 $ (r,c,v) |
It seems that pattern matching is the cause? testRewrite4 :: Matrix -> Double
testRewrite4 m = U.sum . flip (\m1 j -> U.generate (rows m1) (\i -> (_vector m1) `U.unsafeIndex` (j + i * (cols m1)))) 0 $ m |
Bottom line: column :: Matrix -> Int -> Vector Double
column (Matrix r c v) j= U.generate r (\i -> v `U.unsafeIndex` (j + i * c))
{-# INLINE column #-}
column2 :: Matrix -> Int -> Vector Double
column2 m j = U.generate (rows m) (\i -> (_vector m) `U.unsafeIndex` (j + i * (cols m)))
{-# INLINE column2 #-}
testRewrite0 :: Matrix -> Double
testRewrite0 a = (U.sum . flip column2 0) a
testRewrite1 :: Matrix -> Double
testRewrite1 a = (U.sum . flip column 0) a
However, the fusion is depending on the |
The results are actually a bit disappointing, I'll keep digging |
Back to it! Turns out GHC makes wonders with rewrite rules/inlining. So throwing in for example:
works amazing. It gives us some nice stuff: Say I have matrices A,B, and C = A*B. I would expect to hit a point of diminishing return though, so that's to be explored |
The current problem is as follows:
(U.sum . flip M.column 0) a
does not fuse. It seems to boil down to:note: the
flip
isn't important, it's just by convenience, since this is from https://github.com/Magalame/fastest-matricesSo the thing that seems to happen is that stream fusion cannot "go through"
Matrix
's, I'm not sure exactly whyThe text was updated successfully, but these errors were encountered: