X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FFixedMatrix.hs;h=7b34fee0b5ec2798e77b3671c960048f4261df0c;hb=d2577173a6814c09a58217b5974215bc616b8c9e;hp=1c904f26b7e14516bbadd1a1216bab19cb1dd761;hpb=18ba466ff51b36d47d719f1b22b55572ab634c15;p=numerical-analysis.git diff --git a/src/FixedMatrix.hs b/src/FixedMatrix.hs index 1c904f2..7b34fee 100644 --- a/src/FixedMatrix.hs +++ b/src/FixedMatrix.hs @@ -18,16 +18,16 @@ type Mat4 a = Mat Vec4D Vec4D a -- | Convert a matrix to a nested list. toList :: (V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> [[a]] -toList m = Prelude.map FV.toList (FV.toList m) +toList m = Prelude.map V.toList (V.toList m) -- | Create a matrix from a nested list. fromList :: (V.Vector v (Vn w a), V.Vector w a) => [[a]] -> Mat v w a -fromList vs = FV.fromList $ Prelude.map FV.fromList vs +fromList vs = V.fromList $ Prelude.map V.fromList vs -- | Unsafe indexing. (!) :: (V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> (Int, Int) -> a -(!) m (i, j) = (row m i) FV.! j +(!) m (i, j) = (row m i) V.! j -- | Safe indexing. (!?) :: (V.Vector v (Vn w a), V.Vector w a) => Mat v w a @@ -35,19 +35,18 @@ fromList vs = FV.fromList $ Prelude.map FV.fromList vs -> Maybe a (!?) m (i, j) | i < 0 || j < 0 = Nothing - | i > FV.length m = Nothing - | otherwise = if j > FV.length (row m j) + | i > V.length m = Nothing + | otherwise = if j > V.length (row m j) then Nothing - else Just $ (row m j) FV.! j + else Just $ (row m j) V.! j --- | The number of rows in the matrix. Implementation stolen from --- Data.Vector.Fixed.Length. +-- | The number of rows in the matrix. nrows :: forall v w a. (V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> Int -nrows _ = arity (undefined :: V.Dim v) +nrows = V.length -- | The number of columns in the first row of the --- matrix. Implementation stolen from +-- matrix. Implementation stolen from Data.Vector.Fixed.length. ncols :: forall v w a. (V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> Int ncols _ = arity (undefined :: V.Dim w) @@ -55,7 +54,7 @@ ncols _ = arity (undefined :: V.Dim w) row :: (V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> Int -> Vn w a -row m i = m FV.! i +row m i = m V.! i -- | Return the @j@th column of @m@. Unsafe. @@ -63,9 +62,9 @@ column :: (V.Vector v a, V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> Int -> Vn v a column m j = - FV.map (element j) m + V.map (element j) m where - element = flip (FV.!) + element = flip (V.!) -- | Transose @m@; switch it's columns and its rows. This is a dirty @@ -77,7 +76,7 @@ transpose :: (V.Vector v (Vn w a), V.Vector w a) => Mat v w a -> Mat w v a -transpose m = FV.fromList column_list +transpose m = V.fromList column_list where column_list = [ column m i | i <- [0..(ncols m)-1] ] @@ -105,7 +104,7 @@ construct :: forall v w a. construct lambda = rows where -- The arity trick is used in Data.Vector.Fixed.length. - imax = (arity (undefined :: V.Dim w)) - 1 + imax = (arity (undefined :: V.Dim v)) - 1 jmax = (arity (undefined :: V.Dim w)) - 1 - row' i = FV.fromList [ lambda i j | j <- [0..jmax] ] - rows = FV.fromList [ row' i | i <- [0..imax] ] + row' i = V.fromList [ lambda i j | j <- [0..jmax] ] + rows = V.fromList [ row' i | i <- [0..imax] ]