summaryrefslogtreecommitdiff
path: root/lib/Numeric/Container.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-04-30 16:10:20 +0200
committerAlberto Ruiz <aruiz@um.es>2014-04-30 16:10:20 +0200
commitcf1379fed234cf99b2ccce6d9311bfc5c58ef4a3 (patch)
tree2532837500eb98af048404e33018fa88d8a7f535 /lib/Numeric/Container.hs
parentb8b7b47450a1007d4d8c77bb7d04e2744c3bfcd4 (diff)
improved documentation
Diffstat (limited to 'lib/Numeric/Container.hs')
-rw-r--r--lib/Numeric/Container.hs65
1 files changed, 59 insertions, 6 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs
index d2fd351..5339c7e 100644
--- a/lib/Numeric/Container.hs
+++ b/lib/Numeric/Container.hs
@@ -85,8 +85,8 @@ constant = constantD-- about 2x faster
85 85
86{- | Creates a real vector containing a range of values: 86{- | Creates a real vector containing a range of values:
87 87
88@\> linspace 5 (-3,7) 88>>> linspace 5 (-3,7)
895 |> [-3.0,-0.5,2.0,4.5,7.0]@ 89fromList [-3.0,-0.5,2.0,4.5,7.0]@
90 90
91Logarithmic spacing can be defined as follows: 91Logarithmic spacing can be defined as follows:
92 92
@@ -105,7 +105,32 @@ cdot u v = udot (conj u) v
105class Contraction a b c | a b -> c, a c -> b, b c -> a 105class Contraction a b c | a b -> c, a c -> b, b c -> a
106 where 106 where
107 infixl 7 <> 107 infixl 7 <>
108 -- | matrix-matrix product, matrix-vector product, unconjugated dot product 108 {- | matrix-matrix product, matrix-vector product, unconjugated dot product
109
110>>> let a = (3><4) [1..] :: Matrix Double
111
112>>> a
113(3><4)
114 [ 1.0, 2.0, 3.0, 4.0
115 , 5.0, 6.0, 7.0, 8.0
116 , 9.0, 10.0, 11.0, 12.0 ]
117
118>>> disp 2 (a <> trans a)
1193x3
120 30 70 110
121 70 174 278
122110 278 446
123
124>>> a <> fromList [1,0,2,-1::Double]
125fromList [3.0,11.0,19.0]
126
127>>> fromList [1,2,3::Double] <> a
128fromList [38.0,44.0,50.0,56.0]
129
130>>> fromList [1,i] <> fromList[2*i+1,3]
1311.0 :+ 5.0
132
133-}
109 (<>) :: a -> b -> c 134 (<>) :: a -> b -> c
110 135
111instance Product t => Contraction (Vector t) (Vector t) t where 136instance Product t => Contraction (Vector t) (Vector t) t where
@@ -135,9 +160,14 @@ instance LSDiv Matrix Matrix where
135 160
136-------------------------------------------------------- 161--------------------------------------------------------
137 162
138-- | dot product : @u · v = 'cdot' u v@ 163{- | dot product : @u · v = 'cdot' u v@
139-- 164
140-- unicode 0x00b7, Alt-Gr . 165 unicode 0x00b7, Alt-Gr .
166
167>>> fromList [1,i] · fromList[2*i+1,3]
1681.0 :+ (-1.0)
169
170-}
141(·) :: (Container Vector t, Product t) => Vector t -> Vector t -> t 171(·) :: (Container Vector t, Product t) => Vector t -> Vector t -> t
142infixl 7 · 172infixl 7 ·
143u · v = cdot u v 173u · v = cdot u v
@@ -147,6 +177,16 @@ u · v = cdot u v
147-- bidirectional type inference 177-- bidirectional type inference
148class Konst e d c | d -> c, c -> d 178class Konst e d c | d -> c, c -> d
149 where 179 where
180 -- |
181 -- >>> konst 7 3 :: Vector Float
182 -- fromList [7.0,7.0,7.0]
183 --
184 -- >>> konst i (3::Int,4::Int)
185 -- (3><4)
186 -- [ 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0
187 -- , 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0
188 -- , 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0 ]
189 --
150 konst :: e -> d -> c e 190 konst :: e -> d -> c e
151 191
152instance Container Vector e => Konst e Int Vector 192instance Container Vector e => Konst e Int Vector
@@ -161,6 +201,19 @@ instance Container Vector e => Konst e (Int,Int) Matrix
161 201
162class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f 202class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f
163 where 203 where
204 -- |
205 -- >>> build 5 (**2) :: Vector Double
206 -- fromList [0.0,1.0,4.0,9.0,16.0]
207 --
208 -- Hilbert matrix of order N:
209 --
210 -- >>> let hilb n = build (n,n) (\i j -> 1/(i+j+1)) :: Matrix Double
211 -- >>> putStr . dispf 2 $ hilb 3
212 -- 3x3
213 -- 1.00 0.50 0.33
214 -- 0.50 0.33 0.25
215 -- 0.33 0.25 0.20
216 --
164 build :: d -> f -> c e 217 build :: d -> f -> c e
165 218
166instance Container Vector e => Build Int (e -> e) Vector e 219instance Container Vector e => Build Int (e -> e) Vector e