summaryrefslogtreecommitdiff
path: root/packages/base/src/Data/Packed
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-06-07 11:44:13 +0200
committerAlberto Ruiz <aruiz@um.es>2014-06-07 11:44:13 +0200
commit907d69558f8819a44b552e820750f99340f1f107 (patch)
treef825b16bf85ae4496b0eaca94ed239f2845c466d /packages/base/src/Data/Packed
parent2e07762524d0d08fbc2e565529d480dc7fa479b5 (diff)
documentation
Diffstat (limited to 'packages/base/src/Data/Packed')
-rw-r--r--packages/base/src/Data/Packed/Numeric.hs74
1 files changed, 26 insertions, 48 deletions
diff --git a/packages/base/src/Data/Packed/Numeric.hs b/packages/base/src/Data/Packed/Numeric.hs
index e90c612..d2a20be 100644
--- a/packages/base/src/Data/Packed/Numeric.hs
+++ b/packages/base/src/Data/Packed/Numeric.hs
@@ -1,4 +1,3 @@
1{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE FlexibleContexts #-} 1{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-} 2{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE MultiParamTypeClasses #-} 3{-# LANGUAGE MultiParamTypeClasses #-}
@@ -95,67 +94,46 @@ linspace 1 (a,b) = fromList[(a+b)/2]
95linspace n (a,b) = addConstant a $ scale s $ fromList $ map fromIntegral [0 .. n-1] 94linspace n (a,b) = addConstant a $ scale s $ fromList $ map fromIntegral [0 .. n-1]
96 where s = (b-a)/fromIntegral (n-1) 95 where s = (b-a)/fromIntegral (n-1)
97 96
98-------------------------------------------------------- 97--------------------------------------------------------------------------------
99
100{- Matrix product, matrix - vector product, and dot product (equivalent to 'contraction')
101
102(This operator can also be written using the unicode symbol ◇ (25c7).)
103
104Examples:
105
106>>> let a = (3><4) [1..] :: Matrix Double
107>>> let v = fromList [1,0,2,-1] :: Vector Double
108>>> let u = fromList [1,2,3] :: Vector Double
109
110>>> a
111(3><4)
112 [ 1.0, 2.0, 3.0, 4.0
113 , 5.0, 6.0, 7.0, 8.0
114 , 9.0, 10.0, 11.0, 12.0 ]
115
116matrix × matrix:
117 98
118>>> disp 2 (a <.> trans a) 99infixl 7 <.>
1193x3 100-- | An infix synonym for 'dot'
120 30 70 110 101(<.>) :: Numeric t => Vector t -> Vector t -> t
121 70 174 278 102(<.>) = dot
122110 278 446
123 103
124matrix × vector:
125 104
126>>> a <.> v 105infixr 8 <·>, #>
127fromList [3.0,11.0,19.0]
128 106
129dot product: 107{- | dot product
130 108
131>>> u <.> fromList[3,2,1::Double] 109>>> vect [1,2,3,4] <·> vect [-2,0,1,1]
13210 1105.0
133 111
134For complex vectors the first argument is conjugated: 112>>> let 𝑖 = 0:+1 :: ℂ
113>>> fromList [1+𝑖,1] <·> fromList [1,1+𝑖]
1142.0 :+ 0.0
135 115
136>>> fromList [1,i] <.> fromList[2*i+1,3] 116(the dot symbol "·" is obtained by Alt-Gr .)
1371.0 :+ (-1.0)
138 117
139>>> fromList [1,i,1-i] <.> complex a
140fromList [10.0 :+ 4.0,12.0 :+ 4.0,14.0 :+ 4.0,16.0 :+ 4.0]
141-} 118-}
119(<·>) :: Numeric t => Vector t -> Vector t -> t
120(<·>) = dot
142 121
143 122
144-------------------------------------------------------------------------------- 123{- | dense matrix-vector product
145
146infixl 7 <.>
147-- | An infix synonym for 'dot'
148(<.>) :: Numeric t => Vector t -> Vector t -> t
149(<.>) = dot
150 124
125>>> let m = (2><3) [1..]
126>>> m
127(2><3)
128 [ 1.0, 2.0, 3.0
129 , 4.0, 5.0, 6.0 ]
151 130
152infixr 8 <·>, #> 131>>> let v = vect [10,20,30]
153-- | dot product
154(<·>) :: Numeric t => Vector t -> Vector t -> t
155(<·>) = dot
156 132
133>>> m #> v
134fromList [140.0,320.0]
157 135
158-- | matrix-vector product 136-}
159(#>) :: Numeric t => Matrix t -> Vector t -> Vector t 137(#>) :: Numeric t => Matrix t -> Vector t -> Vector t
160(#>) = mXv 138(#>) = mXv
161 139
@@ -291,4 +269,4 @@ instance Numeric (Complex Double)
291instance Numeric Float 269instance Numeric Float
292instance Numeric (Complex Float) 270instance Numeric (Complex Float)
293 271
294-------------------------------------------------------------------------------- 272