From f9a18f9f5685f86697475529033096e8c6f6e627 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 11 Feb 2014 15:07:35 -0500 Subject: [PATCH] Add reverse2 to Linear.Matrix. --- src/Linear/Matrix.hs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Linear/Matrix.hs b/src/Linear/Matrix.hs index e4acc9a..c33e966 100644 --- a/src/Linear/Matrix.hs +++ b/src/Linear/Matrix.hs @@ -31,8 +31,7 @@ import Data.Vector.Fixed ( mk2, mk3, mk4, - mk5 - ) + mk5 ) import qualified Data.Vector.Fixed as V ( and, fromList, @@ -42,6 +41,7 @@ import qualified Data.Vector.Fixed as V ( map, maximum, replicate, + reverse, toList, zipWith ) import Data.Vector.Fixed.Cont ( Arity, arity ) @@ -875,7 +875,7 @@ map2 f (Mat rows) = -- Examples: -- -- >>> let m = fromList [[1,2,3],[4,5,6],[7,8,9]] :: Mat3 Int --- >>> ifoldl2 (\i j cur _ -> cur + i + j) 0 m +-- >>> ifoldl2 (\i j cur _ -> cur + i + j) 0 m -- 18 -- ifoldl2 :: forall a b m n. @@ -911,3 +911,23 @@ imap2 f (Mat rows) = Mat $ V.imap g rows where g i = V.imap (f i) + + +-- | Reverse the order of elements in a matrix. +-- +-- Examples: +-- +-- >>> let m1 = fromList [[1,2,3]] :: Row3 Int +-- >>> reverse2 m1 +-- ((3,2,1)) +-- +-- >>> let m1 = vec3d (1,2,3 :: Int) +-- >>> reverse2 m1 +-- ((3),(2),(1)) +-- +-- >>> let m = fromList [[1,2,3],[4,5,6],[7,8,9]] :: Mat3 Int +-- >>> reverse2 m +-- ((9,8,7),(6,5,4),(3,2,1)) +-- +reverse2 :: (Arity m, Arity n) => Mat m n a -> Mat m n a +reverse2 (Mat rows) = Mat $ V.reverse $ V.map V.reverse rows -- 2.44.2