From fdf8d8778d52cf14aec493ef5ab18d363b900ed7 Mon Sep 17 00:00:00 2001 From: Reiner Pope Date: Sat, 7 Jan 2012 11:47:06 +1100 Subject: Make Matrix a product type --- lib/Data/Packed/ST.hs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/Data/Packed/ST.hs') 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 {-# INLINE ioReadM #-} ioReadM :: Storable t => Matrix t -> Int -> Int -> IO t -ioReadM (MC _ nc cv) r c = ioReadV cv (r*nc+c) -ioReadM (MF nr _ fv) r c = ioReadV fv (c*nr+r) +ioReadM (Matrix _ nc cv RowMajor) r c = ioReadV cv (r*nc+c) +ioReadM (Matrix nr _ fv ColumnMajor) r c = ioReadV fv (c*nr+r) {-# INLINE ioWriteM #-} ioWriteM :: Storable t => Matrix t -> Int -> Int -> t -> IO () -ioWriteM (MC _ nc cv) r c val = ioWriteV cv (r*nc+c) val -ioWriteM (MF nr _ fv) r c val = ioWriteV fv (c*nr+r) val +ioWriteM (Matrix _ nc cv RowMajor) r c val = ioWriteV cv (r*nc+c) val +ioWriteM (Matrix nr _ fv ColumnMajor) r c val = ioWriteV fv (c*nr+r) val newtype STMatrix s t = STMatrix (Matrix t) @@ -153,8 +153,7 @@ unsafeFreezeMatrix (STMatrix x) = unsafeIOToST . return $ x freezeMatrix :: (Storable t) => STMatrix s1 t -> ST s2 (Matrix t) freezeMatrix m = liftSTMatrix id m -cloneMatrix (MC r c d) = cloneVector d >>= return . MC r c -cloneMatrix (MF r c d) = cloneVector d >>= return . MF r c +cloneMatrix (Matrix r c d o) = cloneVector d >>= return . (\d' -> Matrix r c d' o) {-# INLINE safeIndexM #-} safeIndexM f (STMatrix m) r c -- cgit v1.2.3