summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-10-19 09:39:06 +0000
committerAlberto Ruiz <aruiz@um.es>2007-10-19 09:39:06 +0000
commit1a9c07dd1fffdbd7eb939fa6a781793419947c08 (patch)
tree849f7206f3179b60b19a6e986809b108381c9414 /lib
parentf71bcb5b4fbc68f514acc05005cc96932ced32dc (diff)
some refactoring
Diffstat (limited to 'lib')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs16
-rw-r--r--lib/Data/Packed/Internal/Vector.hs3
-rw-r--r--lib/Data/Packed/Matrix.hs17
-rw-r--r--lib/Data/Packed/Vector.hs2
-rw-r--r--lib/Graphics/Plot.hs2
-rw-r--r--lib/Numeric/GSL.hs2
-rw-r--r--lib/Numeric/GSL/Vector.hs2
-rw-r--r--lib/Numeric/LinearAlgebra/Instances.hs23
-rw-r--r--lib/Numeric/LinearAlgebra/Interface.hs4
-rw-r--r--lib/Numeric/LinearAlgebra/Linear.hs2
10 files changed, 45 insertions, 28 deletions
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
22import Foreign hiding (xor) 22import Foreign hiding (xor)
23import Complex 23import Complex
24import Control.Monad(when) 24import Control.Monad(when)
25import Data.List(transpose,intersperse)
26import Data.Maybe(fromJust) 25import Data.Maybe(fromJust)
27import Foreign.C.String 26import Foreign.C.String
28import Foreign.C.Types 27import Foreign.C.Types
28import Data.List(transpose)
29 29
30----------------------------------------------------------------- 30-----------------------------------------------------------------
31 31
@@ -199,20 +199,6 @@ instance Field (Complex Double) where
199 199
200------------------------------------------------------------------ 200------------------------------------------------------------------
201 201
202instance (Show a, Field a) => (Show (Matrix a)) where
203 show m = (sizes++) . dsp . map (map show) . toLists $ m
204 where sizes = "("++show (rows m)++"><"++show (cols m)++")\n"
205
206dsp as = (++" ]") . (" ["++) . init . drop 2 . unlines . map (" , "++) . map unwords' $ transpose mtp
207 where
208 mt = transpose as
209 longs = map (maximum . map length) mt
210 mtp = zipWith (\a b -> map (pad a) b) longs mt
211 pad n str = replicate (n - length str) ' ' ++ str
212 unwords' = concat . intersperse ", "
213
214------------------------------------------------------------------
215
216(>|<) :: (Field a) => Int -> Int -> [a] -> Matrix a 202(>|<) :: (Field a) => Int -> Int -> [a] -> Matrix a
217r >|< c = f where 203r >|< c = f where
218 f l | dim v == r*c = matrixFromVector ColumnMajor c v 204 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
103at v n | n >= 0 && n < dim v = at' v n 103at v n | n >= 0 && n < dim v = at' v n
104 | otherwise = error "vector index out of range" 104 | otherwise = error "vector index out of range"
105 105
106instance (Show a, Storable a) => (Show (Vector a)) where
107 show v = (show (dim v))++" |> " ++ show (toList v)
108
109{- | takes a number of consecutive elements from a Vector 106{- | takes a number of consecutive elements from a Vector
110 107
111@> subVector 2 3 (fromList [1..10]) 108@> 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 @@
9-- Stability : provisional 9-- Stability : provisional
10-- Portability : portable 10-- Portability : portable
11-- 11--
12-- Matrices 12-- A Matrix representation suitable for numerical computations using LAPACK and GSL.
13-- 13--
14----------------------------------------------------------------------------- 14-----------------------------------------------------------------------------
15 15
@@ -22,7 +22,7 @@ module Data.Packed.Matrix (
22 trans, conjTrans, 22 trans, conjTrans,
23 asRow, asColumn, 23 asRow, asColumn,
24 fromRows, toRows, fromColumns, toColumns, 24 fromRows, toRows, fromColumns, toColumns,
25 fromBlocks, 25 fromBlocks, repmat,
26 flipud, fliprl, 26 flipud, fliprl,
27 subMatrix, takeRows, dropRows, takeColumns, dropColumns, 27 subMatrix, takeRows, dropRows, takeColumns, dropColumns,
28 extractRows, 28 extractRows,
@@ -215,3 +215,16 @@ readMatrix = fromLists . map (map read). map words . filter (not.null) . lines
215extractRows :: Field t => [Int] -> Matrix t -> Matrix t 215extractRows :: Field t => [Int] -> Matrix t -> Matrix t
216extractRows l m = fromRows $ extract (toRows $ m) l 216extractRows l m = fromRows $ extract (toRows $ m) l
217 where extract l is = [l!!i |i<-is] 217 where extract l is = [l!!i |i<-is]
218
219{- | creates matrix by repetition of a matrix a given number of rows and columns
220
221@> repmat (ident 2) 2 3 :: Matrix Double
222(4><6)
223 [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0
224 , 0.0, 1.0, 0.0, 1.0, 0.0, 1.0
225 , 1.0, 0.0, 1.0, 0.0, 1.0, 0.0
226 , 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ]@
227
228-}
229repmat :: (Field t) => Matrix t -> Int -> Int -> Matrix t
230repmat 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 @@
8-- Stability : provisional 8-- Stability : provisional
9-- Portability : portable 9-- Portability : portable
10-- 10--
11-- Vectors 11-- A representation of 1D arrays suitable for numeric computations using external libraries.
12-- 12--
13----------------------------------------------------------------------------- 13-----------------------------------------------------------------------------
14 14
diff --git a/lib/Graphics/Plot.hs b/lib/Graphics/Plot.hs
index 71ad0fc..c763294 100644
--- a/lib/Graphics/Plot.hs
+++ b/lib/Graphics/Plot.hs
@@ -8,7 +8,7 @@
8-- Stability : provisional 8-- Stability : provisional
9-- Portability : uses gnuplot and ImageMagick 9-- Portability : uses gnuplot and ImageMagick
10-- 10--
11-- Very basic (and provisional) drawing tools. 11-- Very basic (and provisional) drawing tools using gnuplot and imageMagick.
12-- 12--
13----------------------------------------------------------------------------- 13-----------------------------------------------------------------------------
14 14
diff --git a/lib/Numeric/GSL.hs b/lib/Numeric/GSL.hs
index 4bc3940..784dfbc 100644
--- a/lib/Numeric/GSL.hs
+++ b/lib/Numeric/GSL.hs
@@ -8,7 +8,7 @@ Maintainer : Alberto Ruiz (aruiz at um dot es)
8Stability : provisional 8Stability : provisional
9Portability : uses -fffi and -fglasgow-exts 9Portability : uses -fffi and -fglasgow-exts
10 10
11This module reexports all the available Numeric.GSL functions (except those in "LinearAlgebra"). 11This module reexports all the available GSL functions (except those in "LinearAlgebra").
12 12
13-} 13-}
14 14
diff --git a/lib/Numeric/GSL/Vector.hs b/lib/Numeric/GSL/Vector.hs
index 41efdc0..d94b377 100644
--- a/lib/Numeric/GSL/Vector.hs
+++ b/lib/Numeric/GSL/Vector.hs
@@ -9,7 +9,7 @@
9-- Stability : provisional 9-- Stability : provisional
10-- Portability : portable (uses FFI) 10-- Portability : portable (uses FFI)
11-- 11--
12-- Vector operations 12-- Low level interface to vector operations.
13-- 13--
14----------------------------------------------------------------------------- 14-----------------------------------------------------------------------------
15 15
diff --git a/lib/Numeric/LinearAlgebra/Instances.hs b/lib/Numeric/LinearAlgebra/Instances.hs
index 388f3da..4ee576f 100644
--- a/lib/Numeric/LinearAlgebra/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Instances.hs
@@ -9,7 +9,7 @@ Maintainer : Alberto Ruiz (aruiz at um dot es)
9Stability : provisional 9Stability : provisional
10Portability : portable 10Portability : portable
11 11
12Numeric instances for Vector and Matrix. 12This module exports Show, Eq, Num, Fractional, and Floating instances for Vector and Matrix.
13 13
14In the context of the standard numeric operators, one-component vectors and matrices automatically expand to match the dimensions of the other operand. 14In the context of the standard numeric operators, one-component vectors and matrices automatically expand to match the dimensions of the other operand.
15 15
@@ -24,6 +24,27 @@ import Numeric.GSL.Vector
24import Data.Packed.Matrix 24import Data.Packed.Matrix
25import Data.Packed.Vector 25import Data.Packed.Vector
26import Complex 26import Complex
27import Data.List(transpose,intersperse)
28import Foreign(Storable)
29
30------------------------------------------------------------------
31
32instance (Show a, Field a) => (Show (Matrix a)) where
33 show m = (sizes++) . dsp . map (map show) . toLists $ m
34 where sizes = "("++show (rows m)++"><"++show (cols m)++")\n"
35
36dsp as = (++" ]") . (" ["++) . init . drop 2 . unlines . map (" , "++) . map unwords' $ transpose mtp
37 where
38 mt = transpose as
39 longs = map (maximum . map length) mt
40 mtp = zipWith (\a b -> map (pad a) b) longs mt
41 pad n str = replicate (n - length str) ' ' ++ str
42 unwords' = concat . intersperse ", "
43
44instance (Show a, Storable a) => (Show (Vector a)) where
45 show v = (show (dim v))++" |> " ++ show (toList v)
46
47------------------------------------------------------------------
27 48
28adaptScalar f1 f2 f3 x y 49adaptScalar f1 f2 f3 x y
29 | dim x == 1 = f1 (x@>0) y 50 | dim x == 1 = f1 (x@>0) y
diff --git a/lib/Numeric/LinearAlgebra/Interface.hs b/lib/Numeric/LinearAlgebra/Interface.hs
index 5bd207a..fd076ec 100644
--- a/lib/Numeric/LinearAlgebra/Interface.hs
+++ b/lib/Numeric/LinearAlgebra/Interface.hs
@@ -2,14 +2,14 @@
2----------------------------------------------------------------------------- 2-----------------------------------------------------------------------------
3{- | 3{- |
4Module : Numeric.LinearAlgebra.Interface 4Module : Numeric.LinearAlgebra.Interface
5Copyright : (c) Alberto Ruiz 2006 5Copyright : (c) Alberto Ruiz 2007
6License : GPL-style 6License : GPL-style
7 7
8Maintainer : Alberto Ruiz (aruiz at um dot es) 8Maintainer : Alberto Ruiz (aruiz at um dot es)
9Stability : provisional 9Stability : provisional
10Portability : portable 10Portability : portable
11 11
12Operators for frequent operations. 12(Very provisional) operators for frequent operations.
13 13
14-} 14-}
15----------------------------------------------------------------------------- 15-----------------------------------------------------------------------------
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs
index a3a0183..3017936 100644
--- a/lib/Numeric/LinearAlgebra/Linear.hs
+++ b/lib/Numeric/LinearAlgebra/Linear.hs
@@ -25,7 +25,7 @@ import Data.Packed
25import Numeric.GSL.Vector 25import Numeric.GSL.Vector
26import Complex 26import Complex
27 27
28-- | basic optimized operations 28-- | A generic interface for vectors and matrices to a few element-by-element functions in Numeric.GSL.Vector.
29class (Container c e) => Linear c e where 29class (Container c e) => Linear c e where
30 scale :: e -> c e -> c e 30 scale :: e -> c e -> c e
31 addConstant :: e -> c e -> c e 31 addConstant :: e -> c e -> c e