diff options
Diffstat (limited to 'packages/base/src')
-rw-r--r-- | packages/base/src/Internal/Algorithms.hs | 11 | ||||
-rw-r--r-- | packages/base/src/Internal/Container.hs | 30 | ||||
-rw-r--r-- | packages/base/src/Internal/Convolution.hs | 6 | ||||
-rw-r--r-- | packages/base/src/Internal/Matrix.hs | 3 | ||||
-rw-r--r-- | packages/base/src/Internal/Sparse.hs | 4 | ||||
-rw-r--r-- | packages/base/src/Internal/Static.hs | 16 | ||||
-rw-r--r-- | packages/base/src/Internal/Util.hs | 6 | ||||
-rw-r--r-- | packages/base/src/Internal/Vector.hs | 12 | ||||
-rw-r--r-- | packages/base/src/Internal/Vectorized.hs | 3 | ||||
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra.hs | 3 |
10 files changed, 65 insertions, 29 deletions
diff --git a/packages/base/src/Internal/Algorithms.hs b/packages/base/src/Internal/Algorithms.hs index 99c9e34..5fe7796 100644 --- a/packages/base/src/Internal/Algorithms.hs +++ b/packages/base/src/Internal/Algorithms.hs | |||
@@ -168,7 +168,8 @@ a = (5><3) | |||
168 | -0.690 -0.352 0.433 -0.233 0.398 | 168 | -0.690 -0.352 0.433 -0.233 0.398 |
169 | 169 | ||
170 | >>> s | 170 | >>> s |
171 | fromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15] | 171 | [35.18264833189422,1.4769076999800903,1.089145439970417e-15] |
172 | it :: Vector Double | ||
172 | 173 | ||
173 | >>> disp 3 v | 174 | >>> disp 3 v |
174 | 3x3 | 175 | 3x3 |
@@ -222,7 +223,8 @@ a = (5><3) | |||
222 | -0.690 -0.352 0.433 | 223 | -0.690 -0.352 0.433 |
223 | 224 | ||
224 | >>> s | 225 | >>> s |
225 | fromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15] | 226 | [35.18264833189422,1.4769076999800903,1.089145439970417e-15] |
227 | it :: Vector Double | ||
226 | 228 | ||
227 | >>> disp 3 v | 229 | >>> disp 3 v |
228 | 3x3 | 230 | 3x3 |
@@ -281,7 +283,8 @@ a = (5><3) | |||
281 | -0.690 -0.352 | 283 | -0.690 -0.352 |
282 | 284 | ||
283 | >>> s | 285 | >>> s |
284 | fromList [35.18264833189422,1.4769076999800903] | 286 | [35.18264833189422,1.476907699980091] |
287 | it :: Vector Double | ||
285 | 288 | ||
286 | >>> disp 3 u | 289 | >>> disp 3 u |
287 | 5x2 | 290 | 5x2 |
@@ -533,7 +536,7 @@ a = (3><3) | |||
533 | >>> let (l, v) = eigSH a | 536 | >>> let (l, v) = eigSH a |
534 | 537 | ||
535 | >>> l | 538 | >>> l |
536 | fromList [11.344814282762075,0.17091518882717918,-0.5157294715892575] | 539 | [11.344814282762075,0.17091518882717918,-0.5157294715892575] |
537 | 540 | ||
538 | >>> disp 3 $ v <> diag l <> tr v | 541 | >>> disp 3 $ v <> diag l <> tr v |
539 | 3x3 | 542 | 3x3 |
diff --git a/packages/base/src/Internal/Container.hs b/packages/base/src/Internal/Container.hs index 1520489..d64523d 100644 --- a/packages/base/src/Internal/Container.hs +++ b/packages/base/src/Internal/Container.hs | |||
@@ -38,9 +38,14 @@ import Prelude hiding ((<>)) | |||
38 | {- | Creates a real vector containing a range of values: | 38 | {- | Creates a real vector containing a range of values: |
39 | 39 | ||
40 | >>> linspace 5 (-3,7::Double) | 40 | >>> linspace 5 (-3,7::Double) |
41 | fromList [-3.0,-0.5,2.0,4.5,7.0]@ | 41 | [-3.0,-0.5,2.0,4.5,7.0] |
42 | it :: Vector Double | ||
42 | 43 | ||
43 | >>> linspace 5 (8,2+i) :: Vector (Complex Double) | 44 | >>> linspace 5 (8,2+i) :: Vector (Complex Double) |
45 | |||
46 | <interactive>:6:17: ERROR: | ||
47 | Variable not in scope: i :: Complex Double | ||
48 | |||
44 | fromList [8.0 :+ 0.0,6.5 :+ 0.25,5.0 :+ 0.5,3.5 :+ 0.75,2.0 :+ 1.0] | 49 | fromList [8.0 :+ 0.0,6.5 :+ 0.25,5.0 :+ 0.5,3.5 :+ 0.75,2.0 :+ 1.0] |
45 | 50 | ||
46 | Logarithmic spacing can be defined as follows: | 51 | Logarithmic spacing can be defined as follows: |
@@ -85,7 +90,8 @@ infixr 8 <.> | |||
85 | >>> let v = vector [10,20,30] | 90 | >>> let v = vector [10,20,30] |
86 | 91 | ||
87 | >>> m #> v | 92 | >>> m #> v |
88 | fromList [140.0,320.0] | 93 | [140.0,320.0] |
94 | it :: Vector Numeric.LinearAlgebra.Data.R | ||
89 | 95 | ||
90 | -} | 96 | -} |
91 | infixr 8 #> | 97 | infixr 8 #> |
@@ -134,10 +140,12 @@ v = vector [13.0,27.0,1.0] | |||
134 | 140 | ||
135 | >>> let x = a <\> v | 141 | >>> let x = a <\> v |
136 | >>> x | 142 | >>> x |
137 | fromList [3.0799999999999996,5.159999999999999] | 143 | [3.0799999999999996,5.159999999999999] |
144 | it :: Vector Numeric.LinearAlgebra.Data.R | ||
138 | 145 | ||
139 | >>> a #> x | 146 | >>> a #> x |
140 | fromList [13.399999999999999,26.799999999999997,1.0] | 147 | [13.399999999999999,26.799999999999997,0.9999999999999991] |
148 | it :: Vector Numeric.LinearAlgebra.Data.R | ||
141 | 149 | ||
142 | It also admits multiple right-hand sides stored as columns in a matrix. | 150 | It also admits multiple right-hand sides stored as columns in a matrix. |
143 | 151 | ||
@@ -165,7 +173,8 @@ class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f | |||
165 | where | 173 | where |
166 | -- | | 174 | -- | |
167 | -- >>> build 5 (**2) :: Vector Double | 175 | -- >>> build 5 (**2) :: Vector Double |
168 | -- fromList [0.0,1.0,4.0,9.0,16.0] | 176 | -- [0.0,1.0,4.0,9.0,16.0] |
177 | -- it :: Vector Double | ||
169 | -- | 178 | -- |
170 | -- Hilbert matrix of order N: | 179 | -- Hilbert matrix of order N: |
171 | -- | 180 | -- |
@@ -203,6 +212,17 @@ optimiseMult = mconcat | |||
203 | {- | Compute mean vector and covariance matrix of the rows of a matrix. | 212 | {- | Compute mean vector and covariance matrix of the rows of a matrix. |
204 | 213 | ||
205 | >>> meanCov $ gaussianSample 666 1000 (fromList[4,5]) (diagl[2,3]) | 214 | >>> meanCov $ gaussianSample 666 1000 (fromList[4,5]) (diagl[2,3]) |
215 | |||
216 | <interactive>:4:52: ERROR: | ||
217 | • Couldn't match expected type ‘Herm Double’ | ||
218 | with actual type ‘Matrix Double’ | ||
219 | • In the fourth argument of ‘gaussianSample’, namely | ||
220 | ‘(diagl [2, 3])’ | ||
221 | In the second argument of ‘($)’, namely | ||
222 | ‘gaussianSample 666 1000 (fromList [4, 5]) (diagl [2, 3])’ | ||
223 | In the expression: | ||
224 | meanCov $ gaussianSample 666 1000 (fromList [4, 5]) (diagl [2, 3]) | ||
225 | |||
206 | (fromList [4.010341078059521,5.0197204699640405], | 226 | (fromList [4.010341078059521,5.0197204699640405], |
207 | (2><2) | 227 | (2><2) |
208 | [ 1.9862461923890056, -1.0127225830525157e-2 | 228 | [ 1.9862461923890056, -1.0127225830525157e-2 |
diff --git a/packages/base/src/Internal/Convolution.hs b/packages/base/src/Internal/Convolution.hs index 004e1ff..75fbef4 100644 --- a/packages/base/src/Internal/Convolution.hs +++ b/packages/base/src/Internal/Convolution.hs | |||
@@ -41,7 +41,8 @@ corr | |||
41 | {- ^ correlation | 41 | {- ^ correlation |
42 | 42 | ||
43 | >>> corr (fromList[1,2,3]) (fromList [1..10]) | 43 | >>> corr (fromList[1,2,3]) (fromList [1..10]) |
44 | fromList [14.0,20.0,26.0,32.0,38.0,44.0,50.0,56.0] | 44 | [14.0,20.0,26.0,32.0,38.0,44.0,50.0,56.0] |
45 | it :: (Enum t, Product t, Container Vector t) => Vector t | ||
45 | 46 | ||
46 | -} | 47 | -} |
47 | corr ker v | 48 | corr ker v |
@@ -54,7 +55,8 @@ conv :: (Container Vector t, Product t, Num t) => Vector t -> Vector t -> Vector | |||
54 | {- ^ convolution ('corr' with reversed kernel and padded input, equivalent to polynomial product) | 55 | {- ^ convolution ('corr' with reversed kernel and padded input, equivalent to polynomial product) |
55 | 56 | ||
56 | >>> conv (fromList[1,1]) (fromList [-1,1]) | 57 | >>> conv (fromList[1,1]) (fromList [-1,1]) |
57 | fromList [-1.0,0.0,1.0] | 58 | [-1.0,0.0,1.0] |
59 | it :: (Product t, Container Vector t) => Vector t | ||
58 | 60 | ||
59 | -} | 61 | -} |
60 | conv ker v | 62 | conv ker v |
diff --git a/packages/base/src/Internal/Matrix.hs b/packages/base/src/Internal/Matrix.hs index 4905f61..2856ec2 100644 --- a/packages/base/src/Internal/Matrix.hs +++ b/packages/base/src/Internal/Matrix.hs | |||
@@ -151,7 +151,8 @@ extractAll ord m = unsafePerformIO (copy ord m) | |||
151 | {- | Creates a vector by concatenation of rows. If the matrix is ColumnMajor, this operation requires a transpose. | 151 | {- | Creates a vector by concatenation of rows. If the matrix is ColumnMajor, this operation requires a transpose. |
152 | 152 | ||
153 | >>> flatten (ident 3) | 153 | >>> flatten (ident 3) |
154 | fromList [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0] | 154 | [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0] |
155 | it :: (Num t, Element t) => Vector t | ||
155 | 156 | ||
156 | -} | 157 | -} |
157 | flatten :: Element t => Matrix t -> Vector t | 158 | flatten :: Element t => Matrix t -> Vector t |
diff --git a/packages/base/src/Internal/Sparse.hs b/packages/base/src/Internal/Sparse.hs index 1ff3f57..a8a5fe0 100644 --- a/packages/base/src/Internal/Sparse.hs +++ b/packages/base/src/Internal/Sparse.hs | |||
@@ -170,8 +170,10 @@ gmXv Dense{..} v | |||
170 | {- | general matrix - vector product | 170 | {- | general matrix - vector product |
171 | 171 | ||
172 | >>> let m = mkSparse [((0,999),1.0),((1,1999),2.0)] | 172 | >>> let m = mkSparse [((0,999),1.0),((1,1999),2.0)] |
173 | m :: GMatrix | ||
173 | >>> m !#> vector [1..2000] | 174 | >>> m !#> vector [1..2000] |
174 | fromList [1000.0,4000.0] | 175 | [1000.0,4000.0] |
176 | it :: Vector Double | ||
175 | 177 | ||
176 | -} | 178 | -} |
177 | infixr 8 !#> | 179 | infixr 8 !#> |
diff --git a/packages/base/src/Internal/Static.hs b/packages/base/src/Internal/Static.hs index f9dfff0..357645e 100644 --- a/packages/base/src/Internal/Static.hs +++ b/packages/base/src/Internal/Static.hs | |||
@@ -321,34 +321,34 @@ isDiagg (Dim (Dim x)) | |||
321 | instance KnownNat n => Show (R n) | 321 | instance KnownNat n => Show (R n) |
322 | where | 322 | where |
323 | show s@(R (Dim v)) | 323 | show s@(R (Dim v)) |
324 | | singleV v = "("++show (v!0)++" :: R "++show d++")" | 324 | | singleV v = "(" ++ show (v!0) ++ " :: R " ++ show d ++ ")" |
325 | | otherwise = "(vector"++ drop 8 (show v)++" :: R "++show d++")" | 325 | | otherwise = "(vector " ++ show v ++ " :: R " ++ show d ++")" |
326 | where | 326 | where |
327 | d = size s | 327 | d = size s |
328 | 328 | ||
329 | instance KnownNat n => Show (C n) | 329 | instance KnownNat n => Show (C n) |
330 | where | 330 | where |
331 | show s@(C (Dim v)) | 331 | show s@(C (Dim v)) |
332 | | singleV v = "("++show (v!0)++" :: C "++show d++")" | 332 | | singleV v = "(" ++ show (v!0) ++ " :: C " ++ show d ++ ")" |
333 | | otherwise = "(vector"++ drop 8 (show v)++" :: C "++show d++")" | 333 | | otherwise = "(vector " ++ show v ++ " :: C " ++ show d ++")" |
334 | where | 334 | where |
335 | d = size s | 335 | d = size s |
336 | 336 | ||
337 | instance (KnownNat m, KnownNat n) => Show (L m n) | 337 | instance (KnownNat m, KnownNat n) => Show (L m n) |
338 | where | 338 | where |
339 | show (isDiag -> Just (z,y,(m',n'))) = printf "(diag %s %s :: L %d %d)" (show z) (drop 9 $ show y) m' n' | 339 | show (isDiag -> Just (z,y,(m',n'))) = printf "(diag %s %s :: L %d %d)" (show z) (show y) m' n' |
340 | show s@(L (Dim (Dim x))) | 340 | show s@(L (Dim (Dim x))) |
341 | | singleM x = printf "(%s :: L %d %d)" (show (x `atIndex` (0,0))) m' n' | 341 | | singleM x = printf "(%s :: L %d %d)" (show (x `atIndex` (0,0))) m' n' |
342 | | otherwise = "(matrix"++ dropWhile (/='\n') (show x)++" :: L "++show m'++" "++show n'++")" | 342 | | otherwise = "(matrix" ++ dropWhile (/='\n') (show x) ++ " :: L " ++ show m' ++ " " ++ show n' ++ ")" |
343 | where | 343 | where |
344 | (m',n') = size s | 344 | (m',n') = size s |
345 | 345 | ||
346 | instance (KnownNat m, KnownNat n) => Show (M m n) | 346 | instance (KnownNat m, KnownNat n) => Show (M m n) |
347 | where | 347 | where |
348 | show (isDiagC -> Just (z,y,(m',n'))) = printf "(diag %s %s :: M %d %d)" (show z) (drop 9 $ show y) m' n' | 348 | show (isDiagC -> Just (z,y,(m',n'))) = printf "(diag %s %s :: M %d %d)" (show z) (show y) m' n' |
349 | show s@(M (Dim (Dim x))) | 349 | show s@(M (Dim (Dim x))) |
350 | | singleM x = printf "(%s :: M %d %d)" (show (x `atIndex` (0,0))) m' n' | 350 | | singleM x = printf "(%s :: M %d %d)" (show (x `atIndex` (0,0))) m' n' |
351 | | otherwise = "(matrix"++ dropWhile (/='\n') (show x)++" :: M "++show m'++" "++show n'++")" | 351 | | otherwise = "(matrix" ++ dropWhile (/='\n') (show x) ++ " :: M " ++ show m' ++ " " ++ show n' ++ ")" |
352 | where | 352 | where |
353 | (m',n') = size s | 353 | (m',n') = size s |
354 | 354 | ||
diff --git a/packages/base/src/Internal/Util.hs b/packages/base/src/Internal/Util.hs index 8c8a31e..959e58f 100644 --- a/packages/base/src/Internal/Util.hs +++ b/packages/base/src/Internal/Util.hs | |||
@@ -97,7 +97,8 @@ iC = 0:+1 | |||
97 | {- | Create a real vector. | 97 | {- | Create a real vector. |
98 | 98 | ||
99 | >>> vector [1..5] | 99 | >>> vector [1..5] |
100 | fromList [1.0,2.0,3.0,4.0,5.0] | 100 | [1.0,2.0,3.0,4.0,5.0] |
101 | it :: Vector R | ||
101 | 102 | ||
102 | -} | 103 | -} |
103 | vector :: [R] -> Vector R | 104 | vector :: [R] -> Vector R |
@@ -376,7 +377,8 @@ size = size' | |||
376 | On a matrix it gets the k-th row as a vector: | 377 | On a matrix it gets the k-th row as a vector: |
377 | 378 | ||
378 | >>> matrix 5 [1..15] ! 1 | 379 | >>> matrix 5 [1..15] ! 1 |
379 | fromList [6.0,7.0,8.0,9.0,10.0] | 380 | [6.0,7.0,8.0,9.0,10.0] |
381 | it :: Vector Double | ||
380 | 382 | ||
381 | >>> matrix 5 [1..15] ! 1 ! 3 | 383 | >>> matrix 5 [1..15] ! 1 ! 3 |
382 | 9.0 | 384 | 9.0 |
diff --git a/packages/base/src/Internal/Vector.hs b/packages/base/src/Internal/Vector.hs index 67d0416..e1e4aa8 100644 --- a/packages/base/src/Internal/Vector.hs +++ b/packages/base/src/Internal/Vector.hs | |||
@@ -113,7 +113,8 @@ toList v = safeRead v $ peekArray (dim v) | |||
113 | be used, for instance, with infinite lists. | 113 | be used, for instance, with infinite lists. |
114 | 114 | ||
115 | >>> 5 |> [1..] | 115 | >>> 5 |> [1..] |
116 | fromList [1.0,2.0,3.0,4.0,5.0] | 116 | [1.0,2.0,3.0,4.0,5.0] |
117 | it :: (Enum a, Num a, Foreign.Storable.Storable a) => Vector a | ||
117 | 118 | ||
118 | -} | 119 | -} |
119 | (|>) :: (Storable a) => Int -> [a] -> Vector a | 120 | (|>) :: (Storable a) => Int -> [a] -> Vector a |
@@ -132,7 +133,8 @@ idxs js = fromList (map fromIntegral js) :: Vector I | |||
132 | {- | takes a number of consecutive elements from a Vector | 133 | {- | takes a number of consecutive elements from a Vector |
133 | 134 | ||
134 | >>> subVector 2 3 (fromList [1..10]) | 135 | >>> subVector 2 3 (fromList [1..10]) |
135 | fromList [3.0,4.0,5.0] | 136 | [3.0,4.0,5.0] |
137 | it :: (Enum t, Num t, Foreign.Storable.Storable t) => Vector t | ||
136 | 138 | ||
137 | -} | 139 | -} |
138 | subVector :: Storable t => Int -- ^ index of the starting element | 140 | subVector :: Storable t => Int -- ^ index of the starting element |
@@ -166,7 +168,8 @@ at' v n = safeRead v $ flip peekElemOff n | |||
166 | {- | concatenate a list of vectors | 168 | {- | concatenate a list of vectors |
167 | 169 | ||
168 | >>> vjoin [fromList [1..5::Double], konst 1 3] | 170 | >>> vjoin [fromList [1..5::Double], konst 1 3] |
169 | fromList [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0] | 171 | [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0] |
172 | it :: Vector Double | ||
170 | 173 | ||
171 | -} | 174 | -} |
172 | vjoin :: Storable t => [Vector t] -> Vector t | 175 | vjoin :: Storable t => [Vector t] -> Vector t |
@@ -188,7 +191,8 @@ vjoin as = unsafePerformIO $ do | |||
188 | {- | Extract consecutive subvectors of the given sizes. | 191 | {- | Extract consecutive subvectors of the given sizes. |
189 | 192 | ||
190 | >>> takesV [3,4] (linspace 10 (1,10::Double)) | 193 | >>> takesV [3,4] (linspace 10 (1,10::Double)) |
191 | [fromList [1.0,2.0,3.0],fromList [4.0,5.0,6.0,7.0]] | 194 | [[1.0,2.0,3.0],[4.0,5.0,6.0,7.0]] |
195 | it :: [Vector Double] | ||
192 | 196 | ||
193 | -} | 197 | -} |
194 | takesV :: Storable t => [Int] -> Vector t -> [Vector t] | 198 | takesV :: Storable t => [Int] -> Vector t -> [Vector t] |
diff --git a/packages/base/src/Internal/Vectorized.hs b/packages/base/src/Internal/Vectorized.hs index a410bb2..2990173 100644 --- a/packages/base/src/Internal/Vectorized.hs +++ b/packages/base/src/Internal/Vectorized.hs | |||
@@ -389,7 +389,8 @@ foreign import ccall unsafe "round_vector" c_round_vector :: TVV Double | |||
389 | 389 | ||
390 | -- | | 390 | -- | |
391 | -- >>> range 5 | 391 | -- >>> range 5 |
392 | -- fromList [0,1,2,3,4] | 392 | -- [0,1,2,3,4] |
393 | -- it :: Vector I | ||
393 | -- | 394 | -- |
394 | range :: Int -> Vector I | 395 | range :: Int -> Vector I |
395 | range n = unsafePerformIO $ do | 396 | range n = unsafePerformIO $ do |
diff --git a/packages/base/src/Numeric/LinearAlgebra.hs b/packages/base/src/Numeric/LinearAlgebra.hs index 73d4a13..520eeb7 100644 --- a/packages/base/src/Numeric/LinearAlgebra.hs +++ b/packages/base/src/Numeric/LinearAlgebra.hs | |||
@@ -27,7 +27,8 @@ module Numeric.LinearAlgebra ( | |||
27 | -- as the Hadamard product or the Schur product): | 27 | -- as the Hadamard product or the Schur product): |
28 | -- | 28 | -- |
29 | -- >>> vector [1,2,3] * vector [3,0,-2] | 29 | -- >>> vector [1,2,3] * vector [3,0,-2] |
30 | -- fromList [3.0,0.0,-6.0] | 30 | -- [3.0,0.0,-6.0] |
31 | -- it :: Vector R | ||
31 | -- | 32 | -- |
32 | -- >>> matrix 3 [1..9] * ident 3 | 33 | -- >>> matrix 3 [1..9] * ident 3 |
33 | -- (3><3) | 34 | -- (3><3) |