summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-11-23 13:25:42 +0000
committerAlberto Ruiz <aruiz@um.es>2007-11-23 13:25:42 +0000
commit30fdf02aff2ac1c4da2bb9292fc08cc8330580d0 (patch)
tree82b062214626c20922959c82581decb3df2ba5ec /lib/Data/Packed/Matrix.hs
parent48139eb50c9052406839ee8375e378374e973207 (diff)
removed many -Wall warnings
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 7b6bf29..62d28b1 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -33,10 +33,7 @@ module Data.Packed.Matrix (
33) where 33) where
34 34
35import Data.Packed.Internal 35import Data.Packed.Internal
36import Foreign(Storable)
37import Complex
38import Data.Packed.Vector 36import Data.Packed.Vector
39import Numeric(showGFloat)
40import Data.List(transpose,intersperse) 37import Data.List(transpose,intersperse)
41import Data.Array 38import Data.Array
42 39
@@ -89,8 +86,8 @@ diagRect s r c
89 | dim s < min r c = error "diagRect" 86 | dim s < min r c = error "diagRect"
90 | r == c = diag s 87 | r == c = diag s
91 | r < c = trans $ diagRect s c r 88 | r < c = trans $ diagRect s c r
92 | r > c = joinVert [diag s , zeros (r-c,c)] 89 | otherwise = joinVert [diag s , zeros (r-c,c)]
93 where zeros (r,c) = reshape c $ constantD 0 (r*c) 90 where zeros (r',c') = reshape c' $ constantD 0 (r'*c')
94 91
95-- | extracts the diagonal from a rectangular matrix 92-- | extracts the diagonal from a rectangular matrix
96takeDiag :: (Element t) => Matrix t -> Vector t 93takeDiag :: (Element t) => Matrix t -> Vector t
@@ -123,16 +120,16 @@ r >< c = f where
123 120
124-- | Creates a matrix with the first n rows of another matrix 121-- | Creates a matrix with the first n rows of another matrix
125takeRows :: Element t => Int -> Matrix t -> Matrix t 122takeRows :: Element t => Int -> Matrix t -> Matrix t
126takeRows n mat = subMatrix (0,0) (n, cols mat) mat 123takeRows n mt = subMatrix (0,0) (n, cols mt) mt
127-- | Creates a copy of a matrix without the first n rows 124-- | Creates a copy of a matrix without the first n rows
128dropRows :: Element t => Int -> Matrix t -> Matrix t 125dropRows :: Element t => Int -> Matrix t -> Matrix t
129dropRows n mat = subMatrix (n,0) (rows mat - n, cols mat) mat 126dropRows n mt = subMatrix (n,0) (rows mt - n, cols mt) mt
130-- |Creates a matrix with the first n columns of another matrix 127-- |Creates a matrix with the first n columns of another matrix
131takeColumns :: Element t => Int -> Matrix t -> Matrix t 128takeColumns :: Element t => Int -> Matrix t -> Matrix t
132takeColumns n mat = subMatrix (0,0) (rows mat, n) mat 129takeColumns n mt = subMatrix (0,0) (rows mt, n) mt
133-- | Creates a copy of a matrix without the first n columns 130-- | Creates a copy of a matrix without the first n columns
134dropColumns :: Element t => Int -> Matrix t -> Matrix t 131dropColumns :: Element t => Int -> Matrix t -> Matrix t
135dropColumns n mat = subMatrix (0,n) (rows mat, cols mat - n) mat 132dropColumns n mt = subMatrix (0,n) (rows mt, cols mt - n) mt
136 133
137---------------------------------------------------------------- 134----------------------------------------------------------------
138 135
@@ -164,6 +161,7 @@ fromArray2D m = (r><c) (elems m)
164 c = c1-c0+1 161 c = c1-c0+1
165 162
166------------------------------------------------------ 163------------------------------------------------------
164{-
167-- shows a Double with n digits after the decimal point 165-- shows a Double with n digits after the decimal point
168shf :: (RealFloat a) => Int -> a -> String 166shf :: (RealFloat a) => Int -> a -> String
169shf dec n | abs n < 1e-10 = "0." 167shf dec n | abs n < 1e-10 = "0."
@@ -177,6 +175,8 @@ shfc n z@ (a:+b)
177 | b > 0 = shf n a ++"+"++shf n b ++"i" 175 | b > 0 = shf n a ++"+"++shf n b ++"i"
178 | otherwise = shf n a ++shf n b ++"i" 176 | otherwise = shf n a ++shf n b ++"i"
179 177
178-}
179
180dsp' :: String -> [[String]] -> String 180dsp' :: String -> [[String]] -> String
181dsp' sep as = unlines . map unwords' $ transpose mtp where 181dsp' sep as = unlines . map unwords' $ transpose mtp where
182 mt = transpose as 182 mt = transpose as
@@ -196,6 +196,7 @@ this function the user can easily define any desired display function:
196format :: (Element t) => String -> (t -> String) -> Matrix t -> String 196format :: (Element t) => String -> (t -> String) -> Matrix t -> String
197format sep f m = dsp' sep . map (map f) . toLists $ m 197format sep f m = dsp' sep . map (map f) . toLists $ m
198 198
199{-
199disp m f = putStrLn $ "matrix ("++show (rows m) ++"x"++ show (cols m) ++")\n"++format " | " f m 200disp m f = putStrLn $ "matrix ("++show (rows m) ++"x"++ show (cols m) ++")\n"++format " | " f m
200 201
201dispR :: Int -> Matrix Double -> IO () 202dispR :: Int -> Matrix Double -> IO ()
@@ -203,6 +204,7 @@ dispR d m = disp m (shf d)
203 204
204dispC :: Int -> Matrix (Complex Double) -> IO () 205dispC :: Int -> Matrix (Complex Double) -> IO ()
205dispC d m = disp m (shfc d) 206dispC d m = disp m (shfc d)
207-}
206 208
207-- | creates a matrix from a table of numbers. 209-- | creates a matrix from a table of numbers.
208readMatrix :: String -> Matrix Double 210readMatrix :: String -> Matrix Double
@@ -211,7 +213,7 @@ readMatrix = fromLists . map (map read). map words . filter (not.null) . lines
211-- | rearranges the rows of a matrix according to the order given in a list of integers. 213-- | rearranges the rows of a matrix according to the order given in a list of integers.
212extractRows :: Element t => [Int] -> Matrix t -> Matrix t 214extractRows :: Element t => [Int] -> Matrix t -> Matrix t
213extractRows l m = fromRows $ extract (toRows $ m) l 215extractRows l m = fromRows $ extract (toRows $ m) l
214 where extract l is = [l!!i |i<-is] 216 where extract l' is = [l'!!i |i<-is]
215 217
216{- | creates matrix by repetition of a matrix a given number of rows and columns 218{- | creates matrix by repetition of a matrix a given number of rows and columns
217 219