diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-06-18 07:41:31 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-06-18 07:41:31 +0200 |
commit | 7163e8027574d2a02e1f852a84d9252c51ade573 (patch) | |
tree | f029cdf6badd73d201bab8a70831fc6ef13cc3ad /packages/base/src/Data/Packed/Matrix.hs | |
parent | 1cfc81ba6a318b593598a9a038adaa73009f6530 (diff) |
to/from ByteString
Diffstat (limited to 'packages/base/src/Data/Packed/Matrix.hs')
-rw-r--r-- | packages/base/src/Data/Packed/Matrix.hs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/packages/base/src/Data/Packed/Matrix.hs b/packages/base/src/Data/Packed/Matrix.hs index 2420c94..6445ce4 100644 --- a/packages/base/src/Data/Packed/Matrix.hs +++ b/packages/base/src/Data/Packed/Matrix.hs | |||
@@ -1,6 +1,7 @@ | |||
1 | {-# LANGUAGE TypeFamilies #-} | 1 | {-# LANGUAGE TypeFamilies #-} |
2 | {-# LANGUAGE FlexibleContexts #-} | 2 | {-# LANGUAGE FlexibleContexts #-} |
3 | {-# LANGUAGE FlexibleInstances #-} | 3 | {-# LANGUAGE FlexibleInstances #-} |
4 | {-# LANGUAGE UndecidableInstances #-} | ||
4 | {-# LANGUAGE MultiParamTypeClasses #-} | 5 | {-# LANGUAGE MultiParamTypeClasses #-} |
5 | {-# LANGUAGE CPP #-} | 6 | {-# LANGUAGE CPP #-} |
6 | 7 | ||
@@ -53,20 +54,15 @@ import Control.Monad(liftM) | |||
53 | #ifdef BINARY | 54 | #ifdef BINARY |
54 | 55 | ||
55 | import Data.Binary | 56 | import Data.Binary |
56 | import Control.Monad(replicateM) | ||
57 | 57 | ||
58 | instance (Binary a, Element a, Storable a) => Binary (Matrix a) where | 58 | instance (Binary (Vector a), Element a) => Binary (Matrix a) where |
59 | put m = do | 59 | put m = do |
60 | let r = rows m | 60 | put (cols m) |
61 | let c = cols m | 61 | put (flatten m) |
62 | put r | ||
63 | put c | ||
64 | mapM_ (\i -> mapM_ (\j -> put $ m @@> (i,j)) [0..(c-1)]) [0..(r-1)] | ||
65 | get = do | 62 | get = do |
66 | r <- get | ||
67 | c <- get | 63 | c <- get |
68 | xs <- replicateM r $ replicateM c get | 64 | v <- get |
69 | return $ fromLists xs | 65 | return (reshape c v) |
70 | 66 | ||
71 | #endif | 67 | #endif |
72 | 68 | ||