From fc6e8a553c99f50768b49c8612f800edef790d93 Mon Sep 17 00:00:00 2001 From: Vivian McPhail Date: Thu, 1 Jul 2010 09:09:41 +0000 Subject: chunkified-binary-vector --- lib/Data/Packed/Vector.hs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'lib/Data/Packed') diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs index 66aa71d..7264528 100644 --- a/lib/Data/Packed/Vector.hs +++ b/lib/Data/Packed/Vector.hs @@ -36,15 +36,32 @@ import Control.Monad(replicateM) ------------------------------------------------------------------- +-- a 64K cache, with a Double taking 13 bytes in Bytestring, +-- implies a chunk size of 5041 +chunk :: Int +chunk = 5000 + +chunks :: Int -> [Int] +chunks d = let c = d `div` chunk + in ((d-c*chunk):(replicate c chunk)) + +putVector v = do + let d = dim v + mapM_ (\i -> put $ v @> i) [0..(d-1)] + +getVector d = do + xs <- replicateM d get + return $! fromList xs + instance (Binary a, Storable a) => Binary (Vector a) where put v = do let d = dim v put d - mapM_ (\i -> put $ v @> i) [0..(d-1)] + mapM_ putVector $! takesV (chunks d) v get = do d <- get - xs <- replicateM d get - return $ fromList xs + vs <- mapM getVector $ chunks d + return $! join vs ------------------------------------------------------------------- -- cgit v1.2.3