diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-04-30 16:10:20 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-04-30 16:10:20 +0200 |
commit | cf1379fed234cf99b2ccce6d9311bfc5c58ef4a3 (patch) | |
tree | 2532837500eb98af048404e33018fa88d8a7f535 /lib/Numeric/Container.hs | |
parent | b8b7b47450a1007d4d8c77bb7d04e2744c3bfcd4 (diff) |
improved documentation
Diffstat (limited to 'lib/Numeric/Container.hs')
-rw-r--r-- | lib/Numeric/Container.hs | 65 |
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) |
89 | 5 |> [-3.0,-0.5,2.0,4.5,7.0]@ | 89 | fromList [-3.0,-0.5,2.0,4.5,7.0]@ |
90 | 90 | ||
91 | Logarithmic spacing can be defined as follows: | 91 | Logarithmic spacing can be defined as follows: |
92 | 92 | ||
@@ -105,7 +105,32 @@ cdot u v = udot (conj u) v | |||
105 | class Contraction a b c | a b -> c, a c -> b, b c -> a | 105 | class 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) | ||
119 | 3x3 | ||
120 | 30 70 110 | ||
121 | 70 174 278 | ||
122 | 110 278 446 | ||
123 | |||
124 | >>> a <> fromList [1,0,2,-1::Double] | ||
125 | fromList [3.0,11.0,19.0] | ||
126 | |||
127 | >>> fromList [1,2,3::Double] <> a | ||
128 | fromList [38.0,44.0,50.0,56.0] | ||
129 | |||
130 | >>> fromList [1,i] <> fromList[2*i+1,3] | ||
131 | 1.0 :+ 5.0 | ||
132 | |||
133 | -} | ||
109 | (<>) :: a -> b -> c | 134 | (<>) :: a -> b -> c |
110 | 135 | ||
111 | instance Product t => Contraction (Vector t) (Vector t) t where | 136 | instance 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] | ||
168 | 1.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 |
142 | infixl 7 · | 172 | infixl 7 · |
143 | u · v = cdot u v | 173 | u · v = cdot u v |
@@ -147,6 +177,16 @@ u · v = cdot u v | |||
147 | -- bidirectional type inference | 177 | -- bidirectional type inference |
148 | class Konst e d c | d -> c, c -> d | 178 | class 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 | ||
152 | instance Container Vector e => Konst e Int Vector | 192 | instance Container Vector e => Konst e Int Vector |
@@ -161,6 +201,19 @@ instance Container Vector e => Konst e (Int,Int) Matrix | |||
161 | 201 | ||
162 | class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f | 202 | class 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 | ||
166 | instance Container Vector e => Build Int (e -> e) Vector e | 219 | instance Container Vector e => Build Int (e -> e) Vector e |