diff options
Diffstat (limited to 'packages/base')
-rw-r--r-- | packages/base/hmatrix.cabal | 2 | ||||
-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 |
11 files changed, 66 insertions, 30 deletions
diff --git a/packages/base/hmatrix.cabal b/packages/base/hmatrix.cabal index 7d0da2e..1380a36 100644 --- a/packages/base/hmatrix.cabal +++ b/packages/base/hmatrix.cabal | |||
@@ -47,7 +47,7 @@ library | |||
47 | bytestring, | 47 | bytestring, |
48 | storable-complex, | 48 | storable-complex, |
49 | semigroups, | 49 | semigroups, |
50 | vector >= 0.8 | 50 | vector >= 0.11 |
51 | 51 | ||
52 | hs-source-dirs: src | 52 | hs-source-dirs: src |
53 | 53 | ||
diff --git a/packages/base/src/Internal/Algorithms.hs b/packages/base/src/Internal/Algorithms.hs index cea06ce..6027c46 100644 --- a/packages/base/src/Internal/Algorithms.hs +++ b/packages/base/src/Internal/Algorithms.hs | |||
@@ -170,7 +170,8 @@ a = (5><3) | |||
170 | -0.690 -0.352 0.433 -0.233 0.398 | 170 | -0.690 -0.352 0.433 -0.233 0.398 |
171 | 171 | ||
172 | >>> s | 172 | >>> s |
173 | fromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15] | 173 | [35.18264833189422,1.4769076999800903,1.089145439970417e-15] |
174 | it :: Vector Double | ||
174 | 175 | ||
175 | >>> disp 3 v | 176 | >>> disp 3 v |
176 | 3x3 | 177 | 3x3 |
@@ -224,7 +225,8 @@ a = (5><3) | |||
224 | -0.690 -0.352 0.433 | 225 | -0.690 -0.352 0.433 |
225 | 226 | ||
226 | >>> s | 227 | >>> s |
227 | fromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15] | 228 | [35.18264833189422,1.4769076999800903,1.089145439970417e-15] |
229 | it :: Vector Double | ||
228 | 230 | ||
229 | >>> disp 3 v | 231 | >>> disp 3 v |
230 | 3x3 | 232 | 3x3 |
@@ -283,7 +285,8 @@ a = (5><3) | |||
283 | -0.690 -0.352 | 285 | -0.690 -0.352 |
284 | 286 | ||
285 | >>> s | 287 | >>> s |
286 | fromList [35.18264833189422,1.4769076999800903] | 288 | [35.18264833189422,1.476907699980091] |
289 | it :: Vector Double | ||
287 | 290 | ||
288 | >>> disp 3 u | 291 | >>> disp 3 u |
289 | 5x2 | 292 | 5x2 |
@@ -535,7 +538,7 @@ a = (3><3) | |||
535 | >>> let (l, v) = eigSH a | 538 | >>> let (l, v) = eigSH a |
536 | 539 | ||
537 | >>> l | 540 | >>> l |
538 | fromList [11.344814282762075,0.17091518882717918,-0.5157294715892575] | 541 | [11.344814282762075,0.17091518882717918,-0.5157294715892575] |
539 | 542 | ||
540 | >>> disp 3 $ v <> diag l <> tr v | 543 | >>> disp 3 $ v <> diag l <> tr v |
541 | 3x3 | 544 | 3x3 |
diff --git a/packages/base/src/Internal/Container.hs b/packages/base/src/Internal/Container.hs index 282163e..46e9cf3 100644 --- a/packages/base/src/Internal/Container.hs +++ b/packages/base/src/Internal/Container.hs | |||
@@ -40,9 +40,14 @@ import Prelude hiding ((<>)) | |||
40 | {- | Creates a real vector containing a range of values: | 40 | {- | Creates a real vector containing a range of values: |
41 | 41 | ||
42 | >>> linspace 5 (-3,7::Double) | 42 | >>> linspace 5 (-3,7::Double) |
43 | fromList [-3.0,-0.5,2.0,4.5,7.0]@ | 43 | [-3.0,-0.5,2.0,4.5,7.0] |
44 | it :: Vector Double | ||
44 | 45 | ||
45 | >>> linspace 5 (8,2+i) :: Vector (Complex Double) | 46 | >>> linspace 5 (8,2+i) :: Vector (Complex Double) |
47 | |||
48 | <interactive>:6:17: ERROR: | ||
49 | Variable not in scope: i :: Complex Double | ||
50 | |||
46 | fromList [8.0 :+ 0.0,6.5 :+ 0.25,5.0 :+ 0.5,3.5 :+ 0.75,2.0 :+ 1.0] | 51 | fromList [8.0 :+ 0.0,6.5 :+ 0.25,5.0 :+ 0.5,3.5 :+ 0.75,2.0 :+ 1.0] |
47 | 52 | ||
48 | Logarithmic spacing can be defined as follows: | 53 | Logarithmic spacing can be defined as follows: |
@@ -87,7 +92,8 @@ infixr 8 <.> | |||
87 | >>> let v = vector [10,20,30] | 92 | >>> let v = vector [10,20,30] |
88 | 93 | ||
89 | >>> m #> v | 94 | >>> m #> v |
90 | fromList [140.0,320.0] | 95 | [140.0,320.0] |
96 | it :: Vector Numeric.LinearAlgebra.Data.R | ||
91 | 97 | ||
92 | -} | 98 | -} |
93 | infixr 8 #> | 99 | infixr 8 #> |
@@ -136,10 +142,12 @@ v = vector [13.0,27.0,1.0] | |||
136 | 142 | ||
137 | >>> let x = a <\> v | 143 | >>> let x = a <\> v |
138 | >>> x | 144 | >>> x |
139 | fromList [3.0799999999999996,5.159999999999999] | 145 | [3.0799999999999996,5.159999999999999] |
146 | it :: Vector Numeric.LinearAlgebra.Data.R | ||
140 | 147 | ||
141 | >>> a #> x | 148 | >>> a #> x |
142 | fromList [13.399999999999999,26.799999999999997,1.0] | 149 | [13.399999999999999,26.799999999999997,0.9999999999999991] |
150 | it :: Vector Numeric.LinearAlgebra.Data.R | ||
143 | 151 | ||
144 | It also admits multiple right-hand sides stored as columns in a matrix. | 152 | It also admits multiple right-hand sides stored as columns in a matrix. |
145 | 153 | ||
@@ -167,7 +175,8 @@ class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f | |||
167 | where | 175 | where |
168 | -- | | 176 | -- | |
169 | -- >>> build 5 (**2) :: Vector Double | 177 | -- >>> build 5 (**2) :: Vector Double |
170 | -- fromList [0.0,1.0,4.0,9.0,16.0] | 178 | -- [0.0,1.0,4.0,9.0,16.0] |
179 | -- it :: Vector Double | ||
171 | -- | 180 | -- |
172 | -- Hilbert matrix of order N: | 181 | -- Hilbert matrix of order N: |
173 | -- | 182 | -- |
@@ -205,6 +214,17 @@ optimiseMult = mconcat | |||
205 | {- | Compute mean vector and covariance matrix of the rows of a matrix. | 214 | {- | Compute mean vector and covariance matrix of the rows of a matrix. |
206 | 215 | ||
207 | >>> meanCov $ gaussianSample 666 1000 (fromList[4,5]) (diagl[2,3]) | 216 | >>> meanCov $ gaussianSample 666 1000 (fromList[4,5]) (diagl[2,3]) |
217 | |||
218 | <interactive>:4:52: ERROR: | ||
219 | • Couldn't match expected type ‘Herm Double’ | ||
220 | with actual type ‘Matrix Double’ | ||
221 | • In the fourth argument of ‘gaussianSample’, namely | ||
222 | ‘(diagl [2, 3])’ | ||
223 | In the second argument of ‘($)’, namely | ||
224 | ‘gaussianSample 666 1000 (fromList [4, 5]) (diagl [2, 3])’ | ||
225 | In the expression: | ||
226 | meanCov $ gaussianSample 666 1000 (fromList [4, 5]) (diagl [2, 3]) | ||
227 | |||
208 | (fromList [4.010341078059521,5.0197204699640405], | 228 | (fromList [4.010341078059521,5.0197204699640405], |
209 | (2><2) | 229 | (2><2) |
210 | [ 1.9862461923890056, -1.0127225830525157e-2 | 230 | [ 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 4bfa13d..5436e59 100644 --- a/packages/base/src/Internal/Matrix.hs +++ b/packages/base/src/Internal/Matrix.hs | |||
@@ -160,7 +160,8 @@ extractAll ord m = unsafePerformIO (copy ord m) | |||
160 | {- | Creates a vector by concatenation of rows. If the matrix is ColumnMajor, this operation requires a transpose. | 160 | {- | Creates a vector by concatenation of rows. If the matrix is ColumnMajor, this operation requires a transpose. |
161 | 161 | ||
162 | >>> flatten (ident 3) | 162 | >>> flatten (ident 3) |
163 | fromList [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0] | 163 | [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0] |
164 | it :: (Num t, Element t) => Vector t | ||
164 | 165 | ||
165 | -} | 166 | -} |
166 | flatten :: Element t => Matrix t -> Vector t | 167 | flatten :: Element t => Matrix t -> Vector t |
diff --git a/packages/base/src/Internal/Sparse.hs b/packages/base/src/Internal/Sparse.hs index 6233b03..fbea11a 100644 --- a/packages/base/src/Internal/Sparse.hs +++ b/packages/base/src/Internal/Sparse.hs | |||
@@ -172,8 +172,10 @@ gmXv Dense{..} v | |||
172 | {- | general matrix - vector product | 172 | {- | general matrix - vector product |
173 | 173 | ||
174 | >>> let m = mkSparse [((0,999),1.0),((1,1999),2.0)] | 174 | >>> let m = mkSparse [((0,999),1.0),((1,1999),2.0)] |
175 | m :: GMatrix | ||
175 | >>> m !#> vector [1..2000] | 176 | >>> m !#> vector [1..2000] |
176 | fromList [1000.0,4000.0] | 177 | [1000.0,4000.0] |
178 | it :: Vector Double | ||
177 | 179 | ||
178 | -} | 180 | -} |
179 | infixr 8 !#> | 181 | infixr 8 !#> |
diff --git a/packages/base/src/Internal/Static.hs b/packages/base/src/Internal/Static.hs index 649fbb5..566506c 100644 --- a/packages/base/src/Internal/Static.hs +++ b/packages/base/src/Internal/Static.hs | |||
@@ -324,34 +324,34 @@ isDiagg (Dim (Dim x)) | |||
324 | instance KnownNat n => Show (R n) | 324 | instance KnownNat n => Show (R n) |
325 | where | 325 | where |
326 | show s@(R (Dim v)) | 326 | show s@(R (Dim v)) |
327 | | singleV v = "("++show (v!0)++" :: R "++show d++")" | 327 | | singleV v = "(" ++ show (v!0) ++ " :: R " ++ show d ++ ")" |
328 | | otherwise = "(vector"++ drop 8 (show v)++" :: R "++show d++")" | 328 | | otherwise = "(vector " ++ show v ++ " :: R " ++ show d ++")" |
329 | where | 329 | where |
330 | d = size s | 330 | d = size s |
331 | 331 | ||
332 | instance KnownNat n => Show (C n) | 332 | instance KnownNat n => Show (C n) |
333 | where | 333 | where |
334 | show s@(C (Dim v)) | 334 | show s@(C (Dim v)) |
335 | | singleV v = "("++show (v!0)++" :: C "++show d++")" | 335 | | singleV v = "(" ++ show (v!0) ++ " :: C " ++ show d ++ ")" |
336 | | otherwise = "(vector"++ drop 8 (show v)++" :: C "++show d++")" | 336 | | otherwise = "(vector " ++ show v ++ " :: C " ++ show d ++")" |
337 | where | 337 | where |
338 | d = size s | 338 | d = size s |
339 | 339 | ||
340 | instance (KnownNat m, KnownNat n) => Show (L m n) | 340 | instance (KnownNat m, KnownNat n) => Show (L m n) |
341 | where | 341 | where |
342 | show (isDiag -> Just (z,y,(m',n'))) = printf "(diag %s %s :: L %d %d)" (show z) (drop 9 $ show y) m' n' | 342 | show (isDiag -> Just (z,y,(m',n'))) = printf "(diag %s %s :: L %d %d)" (show z) (show y) m' n' |
343 | show s@(L (Dim (Dim x))) | 343 | show s@(L (Dim (Dim x))) |
344 | | singleM x = printf "(%s :: L %d %d)" (show (x `atIndex` (0,0))) m' n' | 344 | | singleM x = printf "(%s :: L %d %d)" (show (x `atIndex` (0,0))) m' n' |
345 | | otherwise = "(matrix"++ dropWhile (/='\n') (show x)++" :: L "++show m'++" "++show n'++")" | 345 | | otherwise = "(matrix" ++ dropWhile (/='\n') (show x) ++ " :: L " ++ show m' ++ " " ++ show n' ++ ")" |
346 | where | 346 | where |
347 | (m',n') = size s | 347 | (m',n') = size s |
348 | 348 | ||
349 | instance (KnownNat m, KnownNat n) => Show (M m n) | 349 | instance (KnownNat m, KnownNat n) => Show (M m n) |
350 | where | 350 | where |
351 | show (isDiagC -> Just (z,y,(m',n'))) = printf "(diag %s %s :: M %d %d)" (show z) (drop 9 $ show y) m' n' | 351 | show (isDiagC -> Just (z,y,(m',n'))) = printf "(diag %s %s :: M %d %d)" (show z) (show y) m' n' |
352 | show s@(M (Dim (Dim x))) | 352 | show s@(M (Dim (Dim x))) |
353 | | singleM x = printf "(%s :: M %d %d)" (show (x `atIndex` (0,0))) m' n' | 353 | | singleM x = printf "(%s :: M %d %d)" (show (x `atIndex` (0,0))) m' n' |
354 | | otherwise = "(matrix"++ dropWhile (/='\n') (show x)++" :: M "++show m'++" "++show n'++")" | 354 | | otherwise = "(matrix" ++ dropWhile (/='\n') (show x) ++ " :: M " ++ show m' ++ " " ++ show n' ++ ")" |
355 | where | 355 | where |
356 | (m',n') = size s | 356 | (m',n') = size s |
357 | 357 | ||
diff --git a/packages/base/src/Internal/Util.hs b/packages/base/src/Internal/Util.hs index def7cc3..f642e8d 100644 --- a/packages/base/src/Internal/Util.hs +++ b/packages/base/src/Internal/Util.hs | |||
@@ -99,7 +99,8 @@ iC = 0:+1 | |||
99 | {- | Create a real vector. | 99 | {- | Create a real vector. |
100 | 100 | ||
101 | >>> vector [1..5] | 101 | >>> vector [1..5] |
102 | fromList [1.0,2.0,3.0,4.0,5.0] | 102 | [1.0,2.0,3.0,4.0,5.0] |
103 | it :: Vector R | ||
103 | 104 | ||
104 | -} | 105 | -} |
105 | vector :: [R] -> Vector R | 106 | vector :: [R] -> Vector R |
@@ -378,7 +379,8 @@ size = size' | |||
378 | On a matrix it gets the k-th row as a vector: | 379 | On a matrix it gets the k-th row as a vector: |
379 | 380 | ||
380 | >>> matrix 5 [1..15] ! 1 | 381 | >>> matrix 5 [1..15] ! 1 |
381 | fromList [6.0,7.0,8.0,9.0,10.0] | 382 | [6.0,7.0,8.0,9.0,10.0] |
383 | it :: Vector Double | ||
382 | 384 | ||
383 | >>> matrix 5 [1..15] ! 1 ! 3 | 385 | >>> matrix 5 [1..15] ! 1 ! 3 |
384 | 9.0 | 386 | 9.0 |
diff --git a/packages/base/src/Internal/Vector.hs b/packages/base/src/Internal/Vector.hs index dedb822..6271bb6 100644 --- a/packages/base/src/Internal/Vector.hs +++ b/packages/base/src/Internal/Vector.hs | |||
@@ -116,7 +116,8 @@ toList v = safeRead v $ peekArray (dim v) | |||
116 | be used, for instance, with infinite lists. | 116 | be used, for instance, with infinite lists. |
117 | 117 | ||
118 | >>> 5 |> [1..] | 118 | >>> 5 |> [1..] |
119 | fromList [1.0,2.0,3.0,4.0,5.0] | 119 | [1.0,2.0,3.0,4.0,5.0] |
120 | it :: (Enum a, Num a, Foreign.Storable.Storable a) => Vector a | ||
120 | 121 | ||
121 | -} | 122 | -} |
122 | (|>) :: (Storable a) => Int -> [a] -> Vector a | 123 | (|>) :: (Storable a) => Int -> [a] -> Vector a |
@@ -135,7 +136,8 @@ idxs js = fromList (map fromIntegral js) :: Vector I | |||
135 | {- | takes a number of consecutive elements from a Vector | 136 | {- | takes a number of consecutive elements from a Vector |
136 | 137 | ||
137 | >>> subVector 2 3 (fromList [1..10]) | 138 | >>> subVector 2 3 (fromList [1..10]) |
138 | fromList [3.0,4.0,5.0] | 139 | [3.0,4.0,5.0] |
140 | it :: (Enum t, Num t, Foreign.Storable.Storable t) => Vector t | ||
139 | 141 | ||
140 | -} | 142 | -} |
141 | subVector :: Storable t => Int -- ^ index of the starting element | 143 | subVector :: Storable t => Int -- ^ index of the starting element |
@@ -169,7 +171,8 @@ at' v n = safeRead v $ flip peekElemOff n | |||
169 | {- | concatenate a list of vectors | 171 | {- | concatenate a list of vectors |
170 | 172 | ||
171 | >>> vjoin [fromList [1..5::Double], konst 1 3] | 173 | >>> vjoin [fromList [1..5::Double], konst 1 3] |
172 | fromList [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0] | 174 | [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0] |
175 | it :: Vector Double | ||
173 | 176 | ||
174 | -} | 177 | -} |
175 | vjoin :: Storable t => [Vector t] -> Vector t | 178 | vjoin :: Storable t => [Vector t] -> Vector t |
@@ -191,7 +194,8 @@ vjoin as = unsafePerformIO $ do | |||
191 | {- | Extract consecutive subvectors of the given sizes. | 194 | {- | Extract consecutive subvectors of the given sizes. |
192 | 195 | ||
193 | >>> takesV [3,4] (linspace 10 (1,10::Double)) | 196 | >>> takesV [3,4] (linspace 10 (1,10::Double)) |
194 | [fromList [1.0,2.0,3.0],fromList [4.0,5.0,6.0,7.0]] | 197 | [[1.0,2.0,3.0],[4.0,5.0,6.0,7.0]] |
198 | it :: [Vector Double] | ||
195 | 199 | ||
196 | -} | 200 | -} |
197 | takesV :: Storable t => [Int] -> Vector t -> [Vector t] | 201 | 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 c00c324..32430c6 100644 --- a/packages/base/src/Internal/Vectorized.hs +++ b/packages/base/src/Internal/Vectorized.hs | |||
@@ -417,7 +417,8 @@ foreign import ccall unsafe "round_vector" c_round_vector :: TVV Double | |||
417 | 417 | ||
418 | -- | | 418 | -- | |
419 | -- >>> range 5 | 419 | -- >>> range 5 |
420 | -- fromList [0,1,2,3,4] | 420 | -- [0,1,2,3,4] |
421 | -- it :: Vector I | ||
421 | -- | 422 | -- |
422 | range :: Int -> Vector I | 423 | range :: Int -> Vector I |
423 | range n = unsafePerformIO $ do | 424 | range n = unsafePerformIO $ do |
diff --git a/packages/base/src/Numeric/LinearAlgebra.hs b/packages/base/src/Numeric/LinearAlgebra.hs index 970c77e..91923e9 100644 --- a/packages/base/src/Numeric/LinearAlgebra.hs +++ b/packages/base/src/Numeric/LinearAlgebra.hs | |||
@@ -29,7 +29,8 @@ module Numeric.LinearAlgebra ( | |||
29 | -- as the Hadamard product or the Schur product): | 29 | -- as the Hadamard product or the Schur product): |
30 | -- | 30 | -- |
31 | -- >>> vector [1,2,3] * vector [3,0,-2] | 31 | -- >>> vector [1,2,3] * vector [3,0,-2] |
32 | -- fromList [3.0,0.0,-6.0] | 32 | -- [3.0,0.0,-6.0] |
33 | -- it :: Vector R | ||
33 | -- | 34 | -- |
34 | -- >>> matrix 3 [1..9] * ident 3 | 35 | -- >>> matrix 3 [1..9] * ident 3 |
35 | -- (3><3) | 36 | -- (3><3) |