From: Michael Orlitzky Date: Tue, 5 Feb 2013 00:01:00 +0000 (-0500) Subject: Remove reimplemented vector functions from FixedVector.hs. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=d2577173a6814c09a58217b5974215bc616b8c9e;p=numerical-analysis.git Remove reimplemented vector functions from FixedVector.hs. Replace custom Vn functions with vector equivalents. --- 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] ] diff --git a/src/FixedVector.hs b/src/FixedVector.hs index 70f641e..844b9b5 100644 --- a/src/FixedVector.hs +++ b/src/FixedVector.hs @@ -172,32 +172,6 @@ angle v1 v2 = norms = (norm v1) * (norm v2) --- | The length of a vector. --- --- Examples: --- --- >>> let v1 = make2d (1,2) --- >>> length v1 --- 2 --- -length :: (V.Vector v a) => Vn v a -> Int -length (Vn v1) = V.length v1 - - --- | Unsafe indexing. --- --- Examples: --- --- >>> let v1 = make3d (1,2,3) --- >>> v1 ! 2 --- 3 --- >>> v1 ! 3 --- *** Exception: Data.Vector.Fixed.!: index out of range --- -(!) :: (V.Vector v a) => Vn v a -> Int -> a -(!) (Vn v1) idx = v1 V.! idx - - -- | Safe indexing. -- -- Examples: @@ -208,44 +182,11 @@ length (Vn v1) = V.length v1 -- >>> v1 !? 3 -- Nothing -- -(!?) :: (V.Vector v a) => Vn v a -> Int -> Maybe a -(!?) v1@(Vn v2) idx - | idx < 0 || idx >= V.length v2 = Nothing - | otherwise = Just $ v1 ! idx - +(!?) :: (V.Vector v a) => v a -> Int -> Maybe a +(!?) v1 idx + | idx < 0 || idx >= V.length v1 = Nothing + | otherwise = Just $ v1 V.! idx --- | Convert vector to a list. --- --- Examples: --- --- >>> let v1 = make2d (1,2) --- >>> toList v1 --- [1,2] --- -toList :: (V.Vector v a) => Vn v a -> [a] -toList (Vn v1) = V.toList v1 - - --- | Convert a list to a vector. --- --- Examples: --- --- >>> fromList [1,2] :: Vn Vec2D Int --- (1,2) --- -fromList :: (V.Vector v a) => [a] -> Vn v a -fromList xs = Vn $ V.fromList xs - --- | Map a function over a vector. --- --- Examples: --- --- >>> let v1 = make2d (1,2) --- >>> map (*2) v1 --- (2,4) --- -map :: (V.Vector v a, V.Vector v b) => (a -> b) -> Vn v a -> Vn v b -map f (Vn vs) = Vn $ V.map f vs