summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/ST.hs
diff options
context:
space:
mode:
authorReiner Pope <reiner.pope@gmail.com>2012-01-07 11:47:06 +1100
committerReiner Pope <reiner.pope@gmail.com>2012-01-07 11:47:06 +1100
commitfdf8d8778d52cf14aec493ef5ab18d363b900ed7 (patch)
treeca761c585a7a5287eae45a673f10f58931c8353a /lib/Data/Packed/ST.hs
parent4029bf2f48c7e0564fe23de8dc74409d1206ca0d (diff)
Make Matrix a product type
Diffstat (limited to 'lib/Data/Packed/ST.hs')
-rw-r--r--lib/Data/Packed/ST.hs11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/Data/Packed/ST.hs b/lib/Data/Packed/ST.hs
index 00f5e78..c96a209 100644
--- a/lib/Data/Packed/ST.hs
+++ b/lib/Data/Packed/ST.hs
@@ -113,13 +113,13 @@ newVector x n = do
113 113
114{-# INLINE ioReadM #-} 114{-# INLINE ioReadM #-}
115ioReadM :: Storable t => Matrix t -> Int -> Int -> IO t 115ioReadM :: Storable t => Matrix t -> Int -> Int -> IO t
116ioReadM (MC _ nc cv) r c = ioReadV cv (r*nc+c) 116ioReadM (Matrix _ nc cv RowMajor) r c = ioReadV cv (r*nc+c)
117ioReadM (MF nr _ fv) r c = ioReadV fv (c*nr+r) 117ioReadM (Matrix nr _ fv ColumnMajor) r c = ioReadV fv (c*nr+r)
118 118
119{-# INLINE ioWriteM #-} 119{-# INLINE ioWriteM #-}
120ioWriteM :: Storable t => Matrix t -> Int -> Int -> t -> IO () 120ioWriteM :: Storable t => Matrix t -> Int -> Int -> t -> IO ()
121ioWriteM (MC _ nc cv) r c val = ioWriteV cv (r*nc+c) val 121ioWriteM (Matrix _ nc cv RowMajor) r c val = ioWriteV cv (r*nc+c) val
122ioWriteM (MF nr _ fv) r c val = ioWriteV fv (c*nr+r) val 122ioWriteM (Matrix nr _ fv ColumnMajor) r c val = ioWriteV fv (c*nr+r) val
123 123
124newtype STMatrix s t = STMatrix (Matrix t) 124newtype STMatrix s t = STMatrix (Matrix t)
125 125
@@ -153,8 +153,7 @@ unsafeFreezeMatrix (STMatrix x) = unsafeIOToST . return $ x
153freezeMatrix :: (Storable t) => STMatrix s1 t -> ST s2 (Matrix t) 153freezeMatrix :: (Storable t) => STMatrix s1 t -> ST s2 (Matrix t)
154freezeMatrix m = liftSTMatrix id m 154freezeMatrix m = liftSTMatrix id m
155 155
156cloneMatrix (MC r c d) = cloneVector d >>= return . MC r c 156cloneMatrix (Matrix r c d o) = cloneVector d >>= return . (\d' -> Matrix r c d' o)
157cloneMatrix (MF r c d) = cloneVector d >>= return . MF r c
158 157
159{-# INLINE safeIndexM #-} 158{-# INLINE safeIndexM #-}
160safeIndexM f (STMatrix m) r c 159safeIndexM f (STMatrix m) r c