From 1a9c07dd1fffdbd7eb939fa6a781793419947c08 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Fri, 19 Oct 2007 09:39:06 +0000 Subject: some refactoring --- lib/Data/Packed/Internal/Matrix.hs | 16 +--------------- lib/Data/Packed/Internal/Vector.hs | 3 --- lib/Data/Packed/Matrix.hs | 17 +++++++++++++++-- lib/Data/Packed/Vector.hs | 2 +- 4 files changed, 17 insertions(+), 21 deletions(-) (limited to 'lib/Data') diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index bf7f0ec..77906dc 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs @@ -22,10 +22,10 @@ import Data.Packed.Internal.Vector import Foreign hiding (xor) import Complex import Control.Monad(when) -import Data.List(transpose,intersperse) import Data.Maybe(fromJust) import Foreign.C.String import Foreign.C.Types +import Data.List(transpose) ----------------------------------------------------------------- @@ -199,20 +199,6 @@ instance Field (Complex Double) where ------------------------------------------------------------------ -instance (Show a, Field a) => (Show (Matrix a)) where - show m = (sizes++) . dsp . map (map show) . toLists $ m - where sizes = "("++show (rows m)++"><"++show (cols m)++")\n" - -dsp as = (++" ]") . (" ["++) . init . drop 2 . unlines . map (" , "++) . map unwords' $ transpose mtp - where - mt = transpose as - longs = map (maximum . map length) mt - mtp = zipWith (\a b -> map (pad a) b) longs mt - pad n str = replicate (n - length str) ' ' ++ str - unwords' = concat . intersperse ", " - ------------------------------------------------------------------- - (>|<) :: (Field a) => Int -> Int -> [a] -> Matrix a r >|< c = f where f l | dim v == r*c = matrixFromVector ColumnMajor c v diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index 9557206..76bd4d1 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs @@ -103,9 +103,6 @@ at :: Storable a => Vector a -> Int -> a at v n | n >= 0 && n < dim v = at' v n | otherwise = error "vector index out of range" -instance (Show a, Storable a) => (Show (Vector a)) where - show v = (show (dim v))++" |> " ++ show (toList v) - {- | takes a number of consecutive elements from a Vector @> subVector 2 3 (fromList [1..10]) diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index 2b93348..260c1e0 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs @@ -9,7 +9,7 @@ -- Stability : provisional -- Portability : portable -- --- Matrices +-- A Matrix representation suitable for numerical computations using LAPACK and GSL. -- ----------------------------------------------------------------------------- @@ -22,7 +22,7 @@ module Data.Packed.Matrix ( trans, conjTrans, asRow, asColumn, fromRows, toRows, fromColumns, toColumns, - fromBlocks, + fromBlocks, repmat, flipud, fliprl, subMatrix, takeRows, dropRows, takeColumns, dropColumns, extractRows, @@ -215,3 +215,16 @@ readMatrix = fromLists . map (map read). map words . filter (not.null) . lines extractRows :: Field t => [Int] -> Matrix t -> Matrix t extractRows l m = fromRows $ extract (toRows $ m) l where extract l is = [l!!i |i<-is] + +{- | creates matrix by repetition of a matrix a given number of rows and columns + +@> repmat (ident 2) 2 3 :: Matrix Double +(4><6) + [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 + , 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 + , 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 + , 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ]@ + +-} +repmat :: (Field t) => Matrix t -> Int -> Int -> Matrix t +repmat m r c = fromBlocks $ partit c $ replicate (r*c) m \ No newline at end of file diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs index c893fe7..4c331ef 100644 --- a/lib/Data/Packed/Vector.hs +++ b/lib/Data/Packed/Vector.hs @@ -8,7 +8,7 @@ -- Stability : provisional -- Portability : portable -- --- Vectors +-- A representation of 1D arrays suitable for numeric computations using external libraries. -- ----------------------------------------------------------------------------- -- cgit v1.2.3