From: Michael Orlitzky Date: Sat, 8 Feb 2014 00:10:02 +0000 (-0500) Subject: Remove the "row" function which returned a vector instead of a matrix. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=numerical-analysis.git;a=commitdiff_plain;h=9ef91ad4ec3a5c0966f0850d40310722b6c38b68 Remove the "row" function which returned a vector instead of a matrix. --- diff --git a/src/Integration/Gaussian.hs b/src/Integration/Gaussian.hs index 38214a0..be92e5c 100644 --- a/src/Integration/Gaussian.hs +++ b/src/Integration/Gaussian.hs @@ -29,7 +29,7 @@ import Linear.Matrix ( fromList, identity_matrix, map2, - row', + row, transpose ) import Linear.QR ( eigenvectors_symmetric ) import Normed ( Normed(..) ) @@ -119,7 +119,7 @@ nodes_and_weights iterations = nodes = shifted_nodes + ones -- unshift the nodes -- Get the first component of each column. - first_components = row' vecs 0 + first_components = row vecs 0 -- Square it and multiply by 2; see the Golub-Welsch paper for -- this magic. diff --git a/src/Linear/Matrix.hs b/src/Linear/Matrix.hs index 6d13a69..a5fbb84 100644 --- a/src/Linear/Matrix.hs +++ b/src/Linear/Matrix.hs @@ -152,49 +152,37 @@ fromList vs = Mat (V.fromList $ map V.fromList vs) -- | Unsafe indexing. (!!!) :: (Arity m, Arity n) => Mat m n a -> (Int, Int) -> a -(!!!) m (i, j) = (row m i) ! j +(!!!) (Mat rows) (i, j) = (rows ! i) ! j + -- | Safe indexing. -(!!?) :: Mat m n a -> (Int, Int) -> Maybe a -(!!?) m@(Mat rows) (i, j) +(!!?) :: (Arity m, Arity n) => Mat m n a -> (Int, Int) -> Maybe a +(!!?) matrix (i, j) | i < 0 || j < 0 = Nothing - | i > V.length rows = Nothing - | otherwise = if j > V.length (row m j) - then Nothing - else Just $ (row m j) ! j + | i > (nrows matrix) - 1 = Nothing + | j > (ncols matrix) - 1 = Nothing + | otherwise = Just $ matrix !!! (i,j) -- | The number of rows in the matrix. nrows :: forall m n a. (Arity m) => Mat m n a -> Int nrows _ = arity (undefined :: m) + -- | The number of columns in the first row of the -- matrix. Implementation stolen from Data.Vector.Fixed.length. ncols :: forall m n a. (Arity n) => Mat m n a -> Int ncols _ = arity (undefined :: n) --- | Return the @i@th row of @m@. Unsafe. -row :: Mat m n a -> Int -> (Vec n a) -row (Mat rows) i = rows ! i - - -- | Return the @i@th row of @m@ as a matrix. Unsafe. -row' :: (Arity m, Arity n) => Mat m n a -> Int -> Row n a -row' m i = +row :: (Arity m, Arity n) => Mat m n a -> Int -> Row n a +row m i = construct lambda where lambda _ j = m !!! (i, j) --- | Return the @j@th column of @m@. Unsafe. ---column :: Mat m n a -> Int -> (Vec m a) ---column (Mat rows) j = --- V.map (element j) rows --- where --- element = flip (!) - - -- | Return the @j@th column of @m@ as a matrix. Unsafe. column :: (Arity m, Arity n) => Mat m n a -> Int -> Col m a column m j = @@ -270,6 +258,7 @@ identity_matrix :: (Arity m, Ring.C a) => Mat m m a identity_matrix = construct (\i j -> if i == j then (fromInteger 1) else (fromInteger 0)) + -- | Given a positive-definite matrix @m@, computes the -- upper-triangular matrix @r@ with (transpose r)*r == m and all -- values on the diagonal of @r@ positive.