summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-09-14 18:23:20 +0000
committerAlberto Ruiz <aruiz@um.es>2007-09-14 18:23:20 +0000
commitd14515a4a50d5b5335f9c1525432b68ab67fa7c8 (patch)
treefb07b2e27b4b5cebc32a3c7ee064ef376344d7e7
parent9e2f7fb0ca902665b430a96f77959522976a97f9 (diff)
more refactoring
-rw-r--r--HSSL.cabal2
-rw-r--r--examples/oldtests.hs20
-rw-r--r--examples/tests.hs17
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs7
-rw-r--r--lib/Data/Packed/Matrix.hs4
-rw-r--r--lib/GSL/Matrix.hs2
-rw-r--r--lib/GSLHaskell.hs44
-rw-r--r--lib/LinearAlgebra.hs15
-rw-r--r--lib/LinearAlgebra/Linear.hs40
9 files changed, 89 insertions, 62 deletions
diff --git a/HSSL.cabal b/HSSL.cabal
index 9fd148a..8090d1c 100644
--- a/HSSL.cabal
+++ b/HSSL.cabal
@@ -14,7 +14,7 @@ tested-with: GHC ==6.6.1
14Build-Depends: base, haskell98 14Build-Depends: base, haskell98
15Extensions: ForeignFunctionInterface 15Extensions: ForeignFunctionInterface
16--ghc-options: -Wall 16--ghc-options: -Wall
17ghc-options: -O 17ghc-options: -O0
18hs-source-dirs: lib 18hs-source-dirs: lib
19Exposed-modules: Data.Packed.Internal, 19Exposed-modules: Data.Packed.Internal,
20 Data.Packed.Internal.Common, 20 Data.Packed.Internal.Common,
diff --git a/examples/oldtests.hs b/examples/oldtests.hs
index b01675f..f60f4e2 100644
--- a/examples/oldtests.hs
+++ b/examples/oldtests.hs
@@ -5,14 +5,14 @@ import System.Random(randomRs,mkStdGen)
5realMatrix = fromLists :: [[Double]] -> Matrix Double 5realMatrix = fromLists :: [[Double]] -> Matrix Double
6realVector = fromList :: [Double] -> Vector Double 6realVector = fromList :: [Double] -> Vector Double
7 7
8toComplexM = uncurry $ liftMatrix2 (curry toComplex) 8
9 9
10infixl 2 =~= 10infixl 2 =~=
11a =~= b = pnorm 1 (flatten (a - b)) < 1E-6 11a =~= b = pnorm 1 (flatten (a - b)) < 1E-6
12 12
13randomMatrix seed (n,m) = reshape m $ realVector $ take (n*m) $ randomRs (-100,100) $ mkStdGen seed 13randomMatrix seed (n,m) = reshape m $ realVector $ take (n*m) $ randomRs (-100,100) $ mkStdGen seed
14 14
15randomMatrixC seed (n,m) = toComplexM (randomMatrix seed (n,m), randomMatrix (seed+1) (n,m)) 15randomMatrixC seed (n,m) = toComplex (randomMatrix seed (n,m), randomMatrix (seed+1) (n,m))
16 16
17besselTest = do 17besselTest = do
18 let (r,e) = bessel_J0_e 5.0 18 let (r,e) = bessel_J0_e 5.0
@@ -31,7 +31,7 @@ ms = realMatrix [[1,2,3]
31 31
32ms' = randomMatrix 27 (50,100) 32ms' = randomMatrix 27 (50,100)
33 33
34ms'' = toComplexM (randomMatrix 100 (50,100),randomMatrix 101 (50,100)) 34ms'' = toComplex (randomMatrix 100 (50,100),randomMatrix 101 (50,100))
35 35
36fullsvdTest method mat msg = do 36fullsvdTest method mat msg = do
37 let (u,s,vt) = method mat 37 let (u,s,vt) = method mat
@@ -43,7 +43,7 @@ full_svd_Rd = svdRdd
43 43
44-------------------------------------------------------------------- 44--------------------------------------------------------------------
45 45
46mcu = toComplexM (randomMatrix 33 (20,20),randomMatrix 34 (20,20)) 46mcu = toComplex (randomMatrix 33 (20,20),randomMatrix 34 (20,20))
47 47
48mcur = randomMatrix 35 (40,40) 48mcur = randomMatrix 35 (40,40)
49 49
@@ -53,7 +53,7 @@ eigTest method m msg = do
53 assertBool msg $ m <> v =~= v <> diag s 53 assertBool msg $ m <> v =~= v <> diag s
54 54
55bigmat = m + trans m where m = randomMatrix 18 (1000,1000) 55bigmat = m + trans m where m = randomMatrix 18 (1000,1000)
56bigmatc = mc + conjTrans mc where mc = toComplexM(m,m) 56bigmatc = mc + conjTrans mc where mc = toComplex(m,m)
57 m = randomMatrix 19 (1000,1000) 57 m = randomMatrix 19 (1000,1000)
58 58
59-------------------------------------------------------------------- 59--------------------------------------------------------------------
@@ -62,22 +62,22 @@ invTest msg m = do
62 assertBool msg $ m <> inv m =~= ident (rows m) 62 assertBool msg $ m <> inv m =~= ident (rows m)
63 63
64invComplexTest msg m = do 64invComplexTest msg m = do
65 assertBool msg $ m <> invC m =~= ident (rows m) 65 assertBool msg $ m <> invC m =~= identC (rows m)
66 66
67invC m = linearSolveC m (ident (rows m)) 67invC m = linearSolveC m (identC (rows m))
68 68
69--identC n = toComplexM(ident n, (0::Double) <>ident n) 69identC = comp . ident
70 70
71-------------------------------------------------------------------- 71--------------------------------------------------------------------
72 72
73pinvTest f msg m = do 73pinvTest f msg m = do
74 assertBool msg $ m <> f m <> m =~= m 74 assertBool msg $ m <> f m <> m =~= m
75 75
76pinvC m = linearSolveLSC m (ident (rows m)) 76pinvC m = linearSolveLSC m (identC (rows m))
77 77
78pinvSVDR m = linearSolveSVDR Nothing m (ident (rows m)) 78pinvSVDR m = linearSolveSVDR Nothing m (ident (rows m))
79 79
80pinvSVDC m = linearSolveSVDC Nothing m (ident (rows m)) 80pinvSVDC m = linearSolveSVDC Nothing m (identC (rows m))
81 81
82-------------------------------------------------------------------- 82--------------------------------------------------------------------
83 83
diff --git a/examples/tests.hs b/examples/tests.hs
index 0a09ced..2f3b3d8 100644
--- a/examples/tests.hs
+++ b/examples/tests.hs
@@ -6,10 +6,9 @@
6 6
7----------------------------------------------------------------------------- 7-----------------------------------------------------------------------------
8 8
9import Data.Packed.Internal 9import Data.Packed.Internal((>|<), fdat, cdat, multiply', multiplyG, MatrixOrder(..))
10import Data.Packed.Vector 10import Data.Packed.Vector
11import Data.Packed.Matrix 11import Data.Packed.Matrix
12import Data.Packed.Internal.Matrix
13import GSL.Vector 12import GSL.Vector
14import GSL.Integration 13import GSL.Integration
15import GSL.Differentiation 14import GSL.Differentiation
@@ -95,6 +94,8 @@ asC m = (rows m >< cols m) $ toList (cdat m)
95mulC a b = multiply' RowMajor a b 94mulC a b = multiply' RowMajor a b
96mulF a b = multiply' ColumnMajor a b 95mulF a b = multiply' ColumnMajor a b
97 96
97identC = comp . ident
98
98infixl 7 <> 99infixl 7 <>
99a <> b = mulF a b 100a <> b = mulF a b
100 101
@@ -198,15 +199,15 @@ svdTestR fun m = u <> s <> trans v |~| m
198 199
199 200
200svdTestC m = u <> s' <> (trans v) |~| m 201svdTestC m = u <> s' <> (trans v) |~| m
201 && u <> conjTrans u |~| ident (rows m) 202 && u <> conjTrans u |~| identC (rows m)
202 && v <> conjTrans v |~| ident (cols m) 203 && v <> conjTrans v |~| identC (cols m)
203 where (u,s,v) = svdC m 204 where (u,s,v) = svdC m
204 s' = liftMatrix comp s 205 s' = liftMatrix comp s
205 206
206--svdg' m = (u,s',v) where 207--svdg' m = (u,s',v) where
207 208
208eigTestC (SqM m) = (m <> v) |~| (v <> diag s) 209eigTestC (SqM m) = (m <> v) |~| (v <> diag s)
209 && takeDiag (conjTrans v <> v) |~| constant 1 (rows m) --normalized 210 && takeDiag (conjTrans v <> v) |~| comp (constant 1 (rows m)) --normalized
210 where (s,v) = eigC m 211 where (s,v) = eigC m
211 212
212eigTestR (SqM m) = (liftMatrix comp m <> v) |~| (v <> diag s) 213eigTestR (SqM m) = (liftMatrix comp m <> v) |~| (v <> diag s)
@@ -218,7 +219,7 @@ eigTestS (Sym m) = (m <> v) |~| (v <> diag s)
218 where (s,v) = eigS m 219 where (s,v) = eigS m
219 220
220eigTestH (Her m) = (m <> v) |~| (v <> diag (comp s)) 221eigTestH (Her m) = (m <> v) |~| (v <> diag (comp s))
221 && v <> conjTrans v |~| ident (cols m) 222 && v <> conjTrans v |~| identC (cols m)
222 where (s,v) = eigH m 223 where (s,v) = eigH m
223 224
224linearSolveSQTest fun singu (PairSM a b) = singu a || (a <> fun a b) |~| b 225linearSolveSQTest fun singu (PairSM a b) = singu a || (a <> fun a b) |~| b
@@ -248,11 +249,11 @@ identC n = toComplex(ident n, (0::Double) <>ident n)
248pinvTest f m = (m <> f m <> m) |~| m 249pinvTest f m = (m <> f m <> m) |~| m
249 250
250pinvR m = linearSolveLSR m (ident (rows m)) 251pinvR m = linearSolveLSR m (ident (rows m))
251pinvC m = linearSolveLSC m (ident (rows m)) 252pinvC m = linearSolveLSC m (identC (rows m))
252 253
253pinvSVDR m = linearSolveSVDR Nothing m (ident (rows m)) 254pinvSVDR m = linearSolveSVDR Nothing m (ident (rows m))
254 255
255pinvSVDC m = linearSolveSVDC Nothing m (ident (rows m)) 256pinvSVDC m = linearSolveSVDC Nothing m (identC (rows m))
256 257
257-------------------------------------------------------------------- 258--------------------------------------------------------------------
258 259
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs
index 89a162a..58b325c 100644
--- a/lib/Data/Packed/Internal/Matrix.hs
+++ b/lib/Data/Packed/Internal/Matrix.hs
@@ -348,7 +348,7 @@ foreign import ccall safe "aux.h constantC"
348@> constant 2 7 348@> constant 2 7
3497 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@ 3497 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@
350-} 350-}
351constant :: Field a => a -> Int -> Vector a 351constant :: Double -> Int -> Vector Double
352constant = constantD 352constant = constantD
353 353
354-------------------------------------------------------------------------- 354--------------------------------------------------------------------------
@@ -361,6 +361,11 @@ conj v = asComplex $ cdat $ reshape 2 (asReal v) `multiply` diag (fromList [1,-1
361toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double) 361toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double)
362toComplex (r,i) = asComplex $ cdat $ fromColumns [r,i] 362toComplex (r,i) = asComplex $ cdat $ fromColumns [r,i]
363 363
364-- | the inverse of 'toComplex'
365fromComplex :: Vector (Complex Double) -> (Vector Double, Vector Double)
366fromComplex z = (r,i) where
367 [r,i] = toColumns $ reshape 2 $ asReal z
368
364-- | converts a real vector into a complex representation (with zero imaginary parts) 369-- | converts a real vector into a complex representation (with zero imaginary parts)
365comp :: Vector Double -> Vector (Complex Double) 370comp :: Vector Double -> Vector (Complex Double)
366comp v = toComplex (v,constant 0 (dim v)) 371comp v = toComplex (v,constant 0 (dim v))
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 01e8133..fc08ce4 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -75,12 +75,12 @@ diagRect s r c
75 | r == c = diag s 75 | r == c = diag s
76 | r < c = trans $ diagRect s c r 76 | r < c = trans $ diagRect s c r
77 | r > c = joinVert [diag s , zeros (r-c,c)] 77 | r > c = joinVert [diag s , zeros (r-c,c)]
78 where zeros (r,c) = reshape c $ constant 0 (r*c) 78 where zeros (r,c) = reshape c $ constantD 0 (r*c)
79 79
80takeDiag :: (Field t) => Matrix t -> Vector t 80takeDiag :: (Field t) => Matrix t -> Vector t
81takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]] 81takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]]
82 82
83ident :: (Num t, Field t) => Int -> Matrix t 83ident :: Int -> Matrix Double
84ident n = diag (constant 1 n) 84ident n = diag (constant 1 n)
85 85
86------------------------------------------------------------ 86------------------------------------------------------------
diff --git a/lib/GSL/Matrix.hs b/lib/GSL/Matrix.hs
index 15710df..ec8ceea 100644
--- a/lib/GSL/Matrix.hs
+++ b/lib/GSL/Matrix.hs
@@ -289,7 +289,7 @@ luC m = (l,u,p, fromIntegral s') where
289 lu = reshape r $ subVector 0 (r*r) v 289 lu = reshape r $ subVector 0 (r*r) v
290 s':p = map (round.realPart) . toList . subVector (r*r) (r+1) $ v 290 s':p = map (round.realPart) . toList . subVector (r*r) (r+1) $ v
291 u = triang r r 0 1 `mul` lu 291 u = triang r r 0 1 `mul` lu
292 l = (triang r r 0 0 `mul` lu) `add` ident r 292 l = (triang r r 0 0 `mul` lu) `add` liftMatrix comp (ident r)
293 add = liftMatrix2 $ vectorZipC Add 293 add = liftMatrix2 $ vectorZipC Add
294 mul = liftMatrix2 $ vectorZipC Mul 294 mul = liftMatrix2 $ vectorZipC Mul
295 295
diff --git a/lib/GSLHaskell.hs b/lib/GSLHaskell.hs
index e65ff28..3158458 100644
--- a/lib/GSLHaskell.hs
+++ b/lib/GSLHaskell.hs
@@ -18,6 +18,7 @@ module GSLHaskell(
18 module Data.Packed.Vector, 18 module Data.Packed.Vector,
19 module Data.Packed.Matrix, 19 module Data.Packed.Matrix,
20 module LinearAlgebra.Algorithms, 20 module LinearAlgebra.Algorithms,
21 module LinearAlgebra.Linear,
21 module LAPACK, 22 module LAPACK,
22 module GSL.Integration, 23 module GSL.Integration,
23 module GSL.Differentiation, 24 module GSL.Differentiation,
@@ -28,18 +29,15 @@ module GSLHaskell(
28 module GSL.Special, 29 module GSL.Special,
29 module Graphics.Plot, 30 module Graphics.Plot,
30 module Complex, 31 module Complex,
31 Mul,(<>), readMatrix, size, dispR, dispC, format, gmap, Joinable, (<|>),(<->), GSLHaskell.constant, 32 Mul,(<>), readMatrix, size, dispR, dispC, format, gmap, Joinable, (<|>),(<->),
32 fromArray2D, fromComplex, toComplex, GSLHaskell.pnorm, scale, outer 33 fromArray2D, GSLHaskell.pnorm,
33) where 34) where
34 35
35
36import LAPACK
37import GSL.Integration 36import GSL.Integration
38import GSL.Differentiation 37import GSL.Differentiation
39import GSL.Fourier 38import GSL.Fourier
40import GSL.Polynomials 39import GSL.Polynomials
41import GSL.Minimization 40import GSL.Minimization
42import GSL.Matrix
43import Graphics.Plot 41import Graphics.Plot
44import Complex 42import Complex
45import GSL.Special(setErrorHandlerOff, 43import GSL.Special(setErrorHandlerOff,
@@ -48,14 +46,16 @@ import GSL.Special(setErrorHandlerOff,
48 bessel_J0_e, 46 bessel_J0_e,
49 exp_e10_e, 47 exp_e10_e,
50 gamma) 48 gamma)
51import Data.Packed.Internal hiding (dsp) 49--import Data.Packed.Internal hiding (dsp,comp)
52import Data.Packed.Vector hiding (constant) 50import Data.Packed.Vector
53import Data.Packed.Matrix 51import Data.Packed.Matrix
54import Data.Packed.Matrix hiding ((><)) 52import Data.Packed.Matrix hiding ((><))
55import GSL.Vector 53import GSL.Vector
56import LinearAlgebra.Linear
57import qualified LinearAlgebra.Algorithms 54import qualified LinearAlgebra.Algorithms
55import LAPACK
56import GSL.Matrix
58import LinearAlgebra.Algorithms hiding (pnorm) 57import LinearAlgebra.Algorithms hiding (pnorm)
58import LinearAlgebra.Linear
59import Complex 59import Complex
60import Numeric(showGFloat) 60import Numeric(showGFloat)
61import Data.List(transpose,intersperse) 61import Data.List(transpose,intersperse)
@@ -69,7 +69,7 @@ adaptScalar f1 f2 f3 x y
69 | otherwise = f2 x y 69 | otherwise = f2 x y
70 70
71liftMatrix2' :: (Field t, Field a, Field b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t 71liftMatrix2' :: (Field t, Field a, Field b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t
72liftMatrix2' f m1 m2 | compat' m1 m2 = reshape (max (cols m1) (cols m2)) (f (cdat m1) (cdat m2)) 72liftMatrix2' f m1 m2 | compat' m1 m2 = reshape (max (cols m1) (cols m2)) (f (flatten m1) (flatten m2))
73 | otherwise = error "nonconformant matrices in liftMatrix2'" 73 | otherwise = error "nonconformant matrices in liftMatrix2'"
74 74
75compat' :: Matrix a -> Matrix b -> Bool 75compat' :: Matrix a -> Matrix b -> Bool
@@ -89,7 +89,7 @@ instance (Linear Vector a) => Num (Vector a) where
89 fromInteger = fromList . return . fromInteger 89 fromInteger = fromList . return . fromInteger
90 90
91instance (Eq a, Field a) => Eq (Matrix a) where 91instance (Eq a, Field a) => Eq (Matrix a) where
92 a == b = rows a == rows b && cols a == cols b && cdat a == cdat b && fdat a == fdat b 92 a == b = cols a == cols b && flatten a == flatten b
93 93
94instance (Field a, Linear Vector a) => Num (Matrix a) where 94instance (Field a, Linear Vector a) => Num (Matrix a) where
95 (+) = liftMatrix2' (+) 95 (+) = liftMatrix2' (+)
@@ -377,9 +377,6 @@ size = dim
377gmap :: (Storable a, Storable b) => (a->b) -> Vector a -> Vector b 377gmap :: (Storable a, Storable b) => (a->b) -> Vector a -> Vector b
378gmap f v = liftVector f v 378gmap f v = liftVector f v
379 379
380constant :: Double -> Int -> Vector Double
381constant = constantR
382
383-- shows a Double with n digits after the decimal point 380-- shows a Double with n digits after the decimal point
384shf :: (RealFloat a) => Int -> a -> String 381shf :: (RealFloat a) => Int -> a -> String
385shf dec n | abs n < 1e-10 = "0." 382shf dec n | abs n < 1e-10 = "0."
@@ -473,27 +470,6 @@ fromArray2D m = (r><c) (elems m)
473 r = r1-r0+1 470 r = r1-r0+1
474 c = c1-c0+1 471 c = c1-c0+1
475 472
476-- | creates a complex vector from vectors with real and imaginary parts
477toComplexV :: (Vector Double, Vector Double) -> Vector (Complex Double)
478toComplexV (r,i) = asComplex $ flatten $ fromColumns [r,i]
479
480-- | extracts the real and imaginary parts of a complex vector
481fromComplexV :: Vector (Complex Double) -> (Vector Double, Vector Double)
482fromComplexV m = (a,b) where [a,b] = toColumns $ reshape 2 $ asReal m
483
484-- | creates a complex matrix from matrices with real and imaginary parts
485toComplexM :: (Matrix Double, Matrix Double) -> Matrix (Complex Double)
486toComplexM (r,i) = reshape (cols r) $ asComplex $ flatten $ fromColumns [flatten r, flatten i]
487
488-- | extracts the real and imaginary parts of a complex matrix
489fromComplexM :: Matrix (Complex Double) -> (Matrix Double, Matrix Double)
490fromComplexM m = (reshape c a, reshape c b)
491 where c = cols m
492 [a,b] = toColumns $ reshape 2 $ asReal $ flatten m
493
494fromComplex :: Matrix (Complex Double) -> (Matrix Double, Matrix Double)
495fromComplex = fromComplexM
496
497 473
498pnorm :: (Normed t1, Num t) => t -> t1 -> Double 474pnorm :: (Normed t1, Num t) => t -> t1 -> Double
499pnorm 0 = LinearAlgebra.Algorithms.pnorm Infinity 475pnorm 0 = LinearAlgebra.Algorithms.pnorm Infinity
diff --git a/lib/LinearAlgebra.hs b/lib/LinearAlgebra.hs
index b0c8b9d..3b56fc4 100644
--- a/lib/LinearAlgebra.hs
+++ b/lib/LinearAlgebra.hs
@@ -13,6 +13,19 @@ Some linear algebra algorithms, implemented by means of BLAS, LAPACK or GSL.
13-} 13-}
14----------------------------------------------------------------------------- 14-----------------------------------------------------------------------------
15module LinearAlgebra ( 15module LinearAlgebra (
16 16 module Data.Packed.Vector,
17 module Data.Packed.Matrix,
18 module LinearAlgebra.Linear,
19 module LAPACK,
20 module GSL.Matrix,
21 module LinearAlgebra.Algorithms,
22 module Complex
17) where 23) where
18 24
25import LinearAlgebra.Linear
26import LinearAlgebra.Algorithms
27import LAPACK
28import GSL.Matrix
29import Data.Packed.Matrix
30import Data.Packed.Vector
31import Complex \ No newline at end of file
diff --git a/lib/LinearAlgebra/Linear.hs b/lib/LinearAlgebra/Linear.hs
index 53e011f..a2071ed 100644
--- a/lib/LinearAlgebra/Linear.hs
+++ b/lib/LinearAlgebra/Linear.hs
@@ -15,8 +15,6 @@ Portability : uses ffi
15 15
16module LinearAlgebra.Linear ( 16module LinearAlgebra.Linear (
17 Linear(..), 17 Linear(..),
18 toComplex, comp,
19 conj,
20 multiply, dot, outer 18 multiply, dot, outer
21) where 19) where
22 20
@@ -33,6 +31,10 @@ class (Field e) => Linear c e where
33 add :: c e -> c e -> c e 31 add :: c e -> c e -> c e
34 sub :: c e -> c e -> c e 32 sub :: c e -> c e -> c e
35 mul :: c e -> c e -> c e 33 mul :: c e -> c e -> c e
34 toComplex :: RealFloat e => (c e, c e) -> c (Complex e)
35 fromComplex :: RealFloat e => c (Complex e) -> (c e, c e)
36 comp :: RealFloat e => c e -> c (Complex e)
37 conj :: RealFloat e => c (Complex e) -> c (Complex e)
36 38
37instance Linear Vector Double where 39instance Linear Vector Double where
38 scale = vectorMapValR Scale 40 scale = vectorMapValR Scale
@@ -40,6 +42,10 @@ instance Linear Vector Double where
40 add = vectorZipR Add 42 add = vectorZipR Add
41 sub = vectorZipR Sub 43 sub = vectorZipR Sub
42 mul = vectorZipR Mul 44 mul = vectorZipR Mul
45 toComplex = Data.Packed.Internal.toComplex
46 fromComplex = Data.Packed.Internal.fromComplex
47 comp = Data.Packed.Internal.comp
48 conj = Data.Packed.Internal.conj
43 49
44instance Linear Vector (Complex Double) where 50instance Linear Vector (Complex Double) where
45 scale = vectorMapValC Scale 51 scale = vectorMapValC Scale
@@ -47,6 +53,34 @@ instance Linear Vector (Complex Double) where
47 add = vectorZipC Add 53 add = vectorZipC Add
48 sub = vectorZipC Sub 54 sub = vectorZipC Sub
49 mul = vectorZipC Mul 55 mul = vectorZipC Mul
56 toComplex = undefined -- can't match
57 fromComplex = undefined
58 comp = undefined
59 conj = undefined
60
61instance Linear Matrix Double where
62 scale x = liftMatrix (scale x)
63 addConstant x = liftMatrix (addConstant x)
64 add = liftMatrix2 add
65 sub = liftMatrix2 sub
66 mul = liftMatrix2 mul
67 toComplex = uncurry $ liftMatrix2 $ curry LinearAlgebra.Linear.toComplex
68 fromComplex z = (reshape c r, reshape c i)
69 where (r,i) = LinearAlgebra.Linear.fromComplex (cdat z)
70 c = cols z
71 comp = liftMatrix Data.Packed.Internal.comp
72 conj = liftMatrix Data.Packed.Internal.conj
73
74instance Linear Matrix (Complex Double) where
75 scale x = liftMatrix (scale x)
76 addConstant x = liftMatrix (addConstant x)
77 add = liftMatrix2 add
78 sub = liftMatrix2 sub
79 mul = liftMatrix2 mul
80 toComplex = undefined
81 fromComplex = undefined
82 comp = undefined
83 conj = undefined
50 84
51-------------------------------------------------- 85--------------------------------------------------
52 86
@@ -58,8 +92,6 @@ dot u v = dat (multiply r c) `at` 0
58 c = asColumn v 92 c = asColumn v
59 93
60 94
61
62
63{- | Outer product of two vectors. 95{- | Outer product of two vectors.
64 96
65@\> 'fromList' [1,2,3] \`outer\` 'fromList' [5,2,3] 97@\> 'fromList' [1,2,3] \`outer\` 'fromList' [5,2,3]