HNumeric 0.5.0.0 → 0.5.0.1
raw patch · 2 files changed
+27/−12 lines, 2 filesdep +parallel-ioPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: parallel-io
API changes (from Hackage documentation)
- HNum.CSV: writeCSV :: (Writable f, Show a) => String -> f a -> IO ()
+ HNum.CSV: writeCSV :: (Writable f, Eq a, Show a) => String -> f a -> IO ()
Files
- HNumeric.cabal +4/−2
- src/HNum/CSV.hs +23/−10
HNumeric.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 9cfd5649e8b6b63aa2edca51c427be56f671256d05794ce8eaed484e456a0e1c+-- hash: 62eb6bbecdbe6d14a3bf69b24ef47ea07356eb3456c97b5f52e6b74ce6d3ffe0 name: HNumeric-version: 0.5.0.0+version: 0.5.0.1 synopsis: Haskell Numeric Library with pure functionality, R & MATLAB Syntax. description: Please see the README on GitHub at <https://github.com/Axect/HNumeric#readme> category: HNum, library, Numeric, LinearAlgebra, Statistics, bsd3@@ -41,6 +41,7 @@ base >=4.7 && <5 , math-functions , parallel+ , parallel-io , random default-language: Haskell2010 @@ -57,5 +58,6 @@ , base >=4.7 && <5 , math-functions , parallel+ , parallel-io , random default-language: Haskell2010
src/HNum/CSV.hs view
@@ -11,6 +11,9 @@ import HNum.Vector import Data.List ( intercalate ) import Control.Parallel+import Control.Concurrent.ParallelIO+import qualified Control.Concurrent.ParallelIO.Local+ as Local ----------------------------------------------- -- Declaration@@ -20,7 +23,7 @@ -- | DataFrame structure to write csv data DataFrame a = DataFrame { header :: Header- , dat :: Matrix a+ , dat :: Matrix a -- ^ Row Based } deriving (Show, Eq) -- | dataframe constructor@@ -36,10 +39,10 @@ -- | Extract Vector in DataFrame (#) :: Eq a => DataFrame a -> String -> Vector a df # hd | hd `notElem` header df = error "No specific header in dataFrame"- | otherwise = vec $ bd !! i+ | otherwise = i `par` bd `pseq` vec $ bd !! i where i = hd `fd` header df- bd = matForm $ transpose $ dat df+ bd = matForm $ dat df instance Functor DataFrame where fmap f df = df { dat = fmap f (dat df) }@@ -57,7 +60,7 @@ -- | Object to String (Different to Show) toString :: Show a => f a -> String -- | Write as CSV- writeCSV :: Show a => String -> f a -> IO ()+ writeCSV :: (Eq a, Show a) => String -> f a -> IO () instance Writable Vector where toString v = intercalate "\n" (toList $ show <$> v)@@ -70,12 +73,22 @@ writeCSV title m = writeFile title (toString m) instance Writable DataFrame where- toString (DataFrame h m) = h' `par` t' `pseq` m' `pseq` h' ++ "\n" ++ m'- where h' = intercalate "," h- t' = transpose m- m' = toString t'- writeCSV title df = df' `seq` writeFile title df'- where df' = toString df+ toString = undefined+ writeCSV parentPath df =+ let childPath = header df+ vecValue = [df # heads | heads <- childPath]+ strValue = [toString vecs | vecs <- vecValue]+ candidate = [heads ++ "\n" ++ strs | heads <- childPath, strs <- strValue]+ commands = [writeFile (parentPath ++ "/" ++ heads ++ ".csv") cds | heads <- childPath, cds <- candidate]+ in childPath+ `pseq` vecValue+ `pseq` strValue+ `pseq` candidate+ `pseq` commands+ `pseq` do+ Local.withPool 4 $ \pool -> Local.parallel_ pool commands++ ----------------------------------------------- -- Read from CSV