diff options
author | Reiner Pope <reiner.pope@gmail.com> | 2012-01-07 11:47:06 +1100 |
---|---|---|
committer | Reiner Pope <reiner.pope@gmail.com> | 2012-01-07 11:47:06 +1100 |
commit | fdf8d8778d52cf14aec493ef5ab18d363b900ed7 (patch) | |
tree | ca761c585a7a5287eae45a673f10f58931c8353a /lib/Data/Packed/ST.hs | |
parent | 4029bf2f48c7e0564fe23de8dc74409d1206ca0d (diff) |
Make Matrix a product type
Diffstat (limited to 'lib/Data/Packed/ST.hs')
-rw-r--r-- | lib/Data/Packed/ST.hs | 11 |
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 #-} |
115 | ioReadM :: Storable t => Matrix t -> Int -> Int -> IO t | 115 | ioReadM :: Storable t => Matrix t -> Int -> Int -> IO t |
116 | ioReadM (MC _ nc cv) r c = ioReadV cv (r*nc+c) | 116 | ioReadM (Matrix _ nc cv RowMajor) r c = ioReadV cv (r*nc+c) |
117 | ioReadM (MF nr _ fv) r c = ioReadV fv (c*nr+r) | 117 | ioReadM (Matrix nr _ fv ColumnMajor) r c = ioReadV fv (c*nr+r) |
118 | 118 | ||
119 | {-# INLINE ioWriteM #-} | 119 | {-# INLINE ioWriteM #-} |
120 | ioWriteM :: Storable t => Matrix t -> Int -> Int -> t -> IO () | 120 | ioWriteM :: Storable t => Matrix t -> Int -> Int -> t -> IO () |
121 | ioWriteM (MC _ nc cv) r c val = ioWriteV cv (r*nc+c) val | 121 | ioWriteM (Matrix _ nc cv RowMajor) r c val = ioWriteV cv (r*nc+c) val |
122 | ioWriteM (MF nr _ fv) r c val = ioWriteV fv (c*nr+r) val | 122 | ioWriteM (Matrix nr _ fv ColumnMajor) r c val = ioWriteV fv (c*nr+r) val |
123 | 123 | ||
124 | newtype STMatrix s t = STMatrix (Matrix t) | 124 | newtype STMatrix s t = STMatrix (Matrix t) |
125 | 125 | ||
@@ -153,8 +153,7 @@ unsafeFreezeMatrix (STMatrix x) = unsafeIOToST . return $ x | |||
153 | freezeMatrix :: (Storable t) => STMatrix s1 t -> ST s2 (Matrix t) | 153 | freezeMatrix :: (Storable t) => STMatrix s1 t -> ST s2 (Matrix t) |
154 | freezeMatrix m = liftSTMatrix id m | 154 | freezeMatrix m = liftSTMatrix id m |
155 | 155 | ||
156 | cloneMatrix (MC r c d) = cloneVector d >>= return . MC r c | 156 | cloneMatrix (Matrix r c d o) = cloneVector d >>= return . (\d' -> Matrix r c d' o) |
157 | cloneMatrix (MF r c d) = cloneVector d >>= return . MF r c | ||
158 | 157 | ||
159 | {-# INLINE safeIndexM #-} | 158 | {-# INLINE safeIndexM #-} |
160 | safeIndexM f (STMatrix m) r c | 159 | safeIndexM f (STMatrix m) r c |