From 611ff4782c261a6c6e52fe7ed0c122a0eac22691 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sun, 26 Sep 2010 17:05:09 +0000 Subject: fix imports, examples --- examples/parallel.hs | 2 +- examples/pca1.hs | 2 +- examples/pca2.hs | 2 +- examples/vector-map.hs | 74 -------------------------------------------------- examples/vector.hs | 5 ++-- 5 files changed, 5 insertions(+), 80 deletions(-) delete mode 100644 examples/vector-map.hs (limited to 'examples') diff --git a/examples/parallel.hs b/examples/parallel.hs index c82114f..566b729 100644 --- a/examples/parallel.hs +++ b/examples/parallel.hs @@ -1,6 +1,6 @@ -- $ runhaskell parallel.hs 2000 -import System(getArgs) +import System.Environment(getArgs) import Numeric.LinearAlgebra import Control.Parallel.Strategies import System.Time diff --git a/examples/pca1.hs b/examples/pca1.hs index 58b5577..a11eba9 100644 --- a/examples/pca1.hs +++ b/examples/pca1.hs @@ -2,7 +2,7 @@ import Numeric.LinearAlgebra import System.Directory(doesFileExist) -import System(system) +import System.Process(system) import Control.Monad(when) type Vec = Vector Double diff --git a/examples/pca2.hs b/examples/pca2.hs index c38857c..e7ea95f 100644 --- a/examples/pca2.hs +++ b/examples/pca2.hs @@ -3,7 +3,7 @@ import Numeric.LinearAlgebra import Graphics.Plot import System.Directory(doesFileExist) -import System(system) +import System.Process(system) import Control.Monad(when) type Vec = Vector Double diff --git a/examples/vector-map.hs b/examples/vector-map.hs deleted file mode 100644 index 7796cc0..0000000 --- a/examples/vector-map.hs +++ /dev/null @@ -1,74 +0,0 @@ --- use of vectorMapM --- - -------------------------------------------- - -import Data.Packed.Vector -import Numeric.LinearAlgebra.Interface - -import Control.Monad.State - -------------------------------------------- - --- an instance of MonadIO, a monad transformer -type VectorMonadT = StateT Int IO - -v :: Vector Int -v = fromList $ take 10 [0..] - -test1 :: Vector Int -> IO (Vector Int) -test1 = do - mapVectorM (\x -> do - putStr $ (show x) ++ " " - return (x + 1)) - --- we can have an arbitrary monad AND do IO -addInitialM :: Vector Int -> VectorMonadT () -addInitialM = mapVectorM_ (\x -> do - i <- get - liftIO $ putStr $ (show $ x + i) ++ " " - put $ x + i - ) - --- sum the values of the even indiced elements -sumEvens :: Vector Int -> Int -sumEvens = foldVectorWithIndex (\x a b -> if x `mod` 2 == 0 then a + b else b) 0 - --- sum and print running total of evens -sumEvensAndPrint :: Vector Int -> VectorMonadT () -sumEvensAndPrint = mapVectorWithIndexM_ (\ i x -> do - when (i `mod` 2 == 0) (do - v <- get - put $ v + x - v' <- get - liftIO $ putStr $ (show v') ++ " " - return ()) - return () - ) - -indexPlusSum :: Vector Int -> VectorMonadT () -indexPlusSum v' = do - v <- mapVectorWithIndexM (\i x -> do - s <- get - let inc = x+s - liftIO $ putStr $ show (i,inc) ++ " " - put inc - return inc) v' - liftIO $ do - putStrLn "" - putStrLn $ show v - -------------------------------------------- - -main = do - v' <- test1 v - putStrLn "" - putStrLn $ show v' - evalStateT (addInitialM v) 0 - putStrLn "" - putStrLn $ show (sumEvens v) - evalStateT (sumEvensAndPrint v) 0 - putStrLn "" - evalStateT (indexPlusSum v) 0 - return () - diff --git a/examples/vector.hs b/examples/vector.hs index eda9290..f531cbd 100644 --- a/examples/vector.hs +++ b/examples/vector.hs @@ -14,7 +14,7 @@ fromVector :: Storable t => V.Vector t -> H.Vector t fromVector v = unsafeFromForeignPtr p i n where (p,i,n) = V.unsafeToForeignPtr v -toVector :: H.Vector t -> V.Vector t +toVector :: Storable t => H.Vector t -> V.Vector t toVector v = V.unsafeFromForeignPtr p i n where (p,i,n) = unsafeToForeignPtr v @@ -22,11 +22,10 @@ toVector v = V.unsafeFromForeignPtr p i n where v = V.slice 5 10 (V.fromList [1 .. 10::Double] V.++ V.replicate 10 7) -w = subVector 2 3 (linspace 10 (0,2)) +w = subVector 2 3 (linspace 5 (0,1)) :: Vector Double main = do print v print $ fromVector v print w print $ toVector w - -- cgit v1.2.3