From a96be0c7818e0408b4aac9076df131c5b3ec6ff4 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 7 Feb 2014 18:56:21 -0500 Subject: [PATCH] Drop the 'column' function that returned a vector instead of a matrix. --- src/Linear/Matrix.hs | 22 +++++++++++----------- src/Linear/QR.hs | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Linear/Matrix.hs b/src/Linear/Matrix.hs index 054bb6e..6d13a69 100644 --- a/src/Linear/Matrix.hs +++ b/src/Linear/Matrix.hs @@ -188,24 +188,23 @@ row' m i = -- | 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 (!) +--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 = +column :: (Arity m, Arity n) => Mat m n a -> Int -> Col m a +column m j = construct lambda where lambda i _ = m !!! (i, j) -- | Transpose @m@; switch it's columns and its rows. This is a dirty --- implementation.. it would be a little cleaner to use imap, but it --- doesn't seem to work. +-- implementation, but I don't see a better way. -- -- TODO: Don't cheat with fromList. -- @@ -216,9 +215,10 @@ column' m j = -- ((1,3),(2,4)) -- transpose :: (Arity m, Arity n) => Mat m n a -> Mat n m a -transpose m = Mat $ V.fromList column_list +transpose matrix = + construct lambda where - column_list = [ column m i | i <- [0..(ncols m)-1] ] + lambda i j = matrix !!! (j,i) -- | Is @m@ symmetric? diff --git a/src/Linear/QR.hs b/src/Linear/QR.hs index 043b172..8d9ea42 100644 --- a/src/Linear/QR.hs +++ b/src/Linear/QR.hs @@ -231,7 +231,7 @@ eigenvalues iterations matrix -- Examples: -- -- >>> import Linear.Matrix ( Col2, Col3, Mat2, Mat3 ) --- >>> import Linear.Matrix ( column', frobenius_norm, fromList ) +-- >>> import Linear.Matrix ( column, frobenius_norm, fromList ) -- >>> import Linear.Matrix ( identity_matrix, vec3d ) -- >>> import Normed ( Normed(..) ) -- @@ -253,11 +253,11 @@ eigenvalues iterations matrix -- >>> let v1 = (1 / (norm v1') :: Double) *> v1' -- >>> let v2' = vec3d (-4, -2, 5) :: Col3 Double -- >>> let v2 = (1 / (norm v2') :: Double) *> v2' --- >>> frobenius_norm ((column' vecs 0) - v0) < 1e-12 +-- >>> frobenius_norm ((column vecs 0) - v0) < 1e-12 -- True --- >>> frobenius_norm ((column' vecs 1) - v1) < 1e-12 +-- >>> frobenius_norm ((column vecs 1) - v1) < 1e-12 -- True --- >>> frobenius_norm ((column' vecs 2) - v2) < 1e-12 +-- >>> frobenius_norm ((column vecs 2) - v2) < 1e-12 -- True -- eigenvectors_symmetric :: forall m a. (Arity m, Algebraic.C a, Eq a) -- 2.43.2