summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/base/hmatrix.cabal2
-rw-r--r--packages/base/src/Internal/Algorithms.hs11
-rw-r--r--packages/base/src/Internal/Container.hs31
-rw-r--r--packages/base/src/Internal/Convolution.hs6
-rw-r--r--packages/base/src/Internal/Matrix.hs3
-rw-r--r--packages/base/src/Internal/Sparse.hs4
-rw-r--r--packages/base/src/Internal/Static.hs16
-rw-r--r--packages/base/src/Internal/Util.hs6
-rw-r--r--packages/base/src/Internal/Vector.hs12
-rw-r--r--packages/base/src/Internal/Vectorized.hs3
-rw-r--r--packages/base/src/Numeric/LinearAlgebra.hs3
11 files changed, 59 insertions, 38 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
173fromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15] 173[35.18264833189422,1.4769076999800903,1.089145439970417e-15]
174it :: Vector Double
174 175
175>>> disp 3 v 176>>> disp 3 v
1763x3 1773x3
@@ -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
227fromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15] 228[35.18264833189422,1.4769076999800903,1.089145439970417e-15]
229it :: Vector Double
228 230
229>>> disp 3 v 231>>> disp 3 v
2303x3 2323x3
@@ -283,7 +285,8 @@ a = (5><3)
283-0.690 -0.352 285-0.690 -0.352
284 286
285>>> s 287>>> s
286fromList [35.18264833189422,1.4769076999800903] 288[35.18264833189422,1.476907699980091]
289it :: Vector Double
287 290
288>>> disp 3 u 291>>> disp 3 u
2895x2 2925x2
@@ -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
538fromList [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
5413x3 5443x3
diff --git a/packages/base/src/Internal/Container.hs b/packages/base/src/Internal/Container.hs
index 282163e..41b8214 100644
--- a/packages/base/src/Internal/Container.hs
+++ b/packages/base/src/Internal/Container.hs
@@ -40,10 +40,12 @@ 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)
43fromList [-3.0,-0.5,2.0,4.5,7.0]@ 43[-3.0,-0.5,2.0,4.5,7.0]
44it :: Vector Double
44 45
45>>> linspace 5 (8,2+i) :: Vector (Complex Double) 46>>> linspace 5 (8,3:+2) :: Vector (Complex Double)
46fromList [8.0 :+ 0.0,6.5 :+ 0.25,5.0 :+ 0.5,3.5 :+ 0.75,2.0 :+ 1.0] 47[8.0 :+ 0.0,6.75 :+ 0.5,5.5 :+ 1.0,4.25 :+ 1.5,3.0 :+ 2.0]
48it :: Vector (Complex Double)
47 49
48Logarithmic spacing can be defined as follows: 50Logarithmic spacing can be defined as follows:
49 51
@@ -87,7 +89,8 @@ infixr 8 <.>
87>>> let v = vector [10,20,30] 89>>> let v = vector [10,20,30]
88 90
89>>> m #> v 91>>> m #> v
90fromList [140.0,320.0] 92[140.0,320.0]
93it :: Vector Numeric.LinearAlgebra.Data.R
91 94
92-} 95-}
93infixr 8 #> 96infixr 8 #>
@@ -136,10 +139,12 @@ v = vector [13.0,27.0,1.0]
136 139
137>>> let x = a <\> v 140>>> let x = a <\> v
138>>> x 141>>> x
139fromList [3.0799999999999996,5.159999999999999] 142[3.0799999999999996,5.159999999999999]
143it :: Vector Numeric.LinearAlgebra.Data.R
140 144
141>>> a #> x 145>>> a #> x
142fromList [13.399999999999999,26.799999999999997,1.0] 146[13.399999999999999,26.799999999999997,0.9999999999999991]
147it :: Vector Numeric.LinearAlgebra.Data.R
143 148
144It also admits multiple right-hand sides stored as columns in a matrix. 149It also admits multiple right-hand sides stored as columns in a matrix.
145 150
@@ -167,7 +172,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 172 where
168 -- | 173 -- |
169 -- >>> build 5 (**2) :: Vector Double 174 -- >>> build 5 (**2) :: Vector Double
170 -- fromList [0.0,1.0,4.0,9.0,16.0] 175 -- [0.0,1.0,4.0,9.0,16.0]
176 -- it :: Vector Double
171 -- 177 --
172 -- Hilbert matrix of order N: 178 -- Hilbert matrix of order N:
173 -- 179 --
@@ -204,12 +210,11 @@ optimiseMult = mconcat
204 210
205{- | Compute mean vector and covariance matrix of the rows of a matrix. 211{- | Compute mean vector and covariance matrix of the rows of a matrix.
206 212
207>>> meanCov $ gaussianSample 666 1000 (fromList[4,5]) (diagl[2,3]) 213>>> meanCov $ gaussianSample 666 1000 (fromList[4,5]) (trustSym $ diagl [2,3])
208(fromList [4.010341078059521,5.0197204699640405], 214([3.9933155655086696,5.061409102770331],Herm (2><2)
209(2><2) 215 [ 1.9963242906624408, -4.227815571404954e-2
210 [ 1.9862461923890056, -1.0127225830525157e-2 216 , -4.227815571404954e-2, 3.2003833097832857 ])
211 , -1.0127225830525157e-2, 3.0373954915729318 ]) 217it :: (Vector Double, Herm Double)
212
213-} 218-}
214meanCov :: Matrix Double -> (Vector Double, Herm Double) 219meanCov :: Matrix Double -> (Vector Double, Herm Double)
215meanCov x = (med,cov) where 220meanCov x = (med,cov) where
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])
44fromList [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]
45it :: (Enum t, Product t, Container Vector t) => Vector t
45 46
46-} 47-}
47corr ker v 48corr 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])
57fromList [-1.0,0.0,1.0] 58[-1.0,0.0,1.0]
59it :: (Product t, Container Vector t) => Vector t
58 60
59-} 61-}
60conv ker v 62conv 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)
163fromList [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]
164it :: (Num t, Element t) => Vector t
164 165
165-} 166-}
166flatten :: Element t => Matrix t -> Vector t 167flatten :: 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)]
175m :: GMatrix
175>>> m !#> vector [1..2000] 176>>> m !#> vector [1..2000]
176fromList [1000.0,4000.0] 177[1000.0,4000.0]
178it :: Vector Double
177 179
178-} 180-}
179infixr 8 !#> 181infixr 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))
324instance KnownNat n => Show (R n) 324instance 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
332instance KnownNat n => Show (C n) 332instance 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
340instance (KnownNat m, KnownNat n) => Show (L m n) 340instance (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
349instance (KnownNat m, KnownNat n) => Show (M m n) 349instance (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]
102fromList [1.0,2.0,3.0,4.0,5.0] 102[1.0,2.0,3.0,4.0,5.0]
103it :: Vector R
103 104
104-} 105-}
105vector :: [R] -> Vector R 106vector :: [R] -> Vector R
@@ -378,7 +379,8 @@ size = size'
378On a matrix it gets the k-th row as a vector: 379On 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
381fromList [6.0,7.0,8.0,9.0,10.0] 382[6.0,7.0,8.0,9.0,10.0]
383it :: Vector Double
382 384
383>>> matrix 5 [1..15] ! 1 ! 3 385>>> matrix 5 [1..15] ! 1 ! 3
3849.0 3869.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..]
119fromList [1.0,2.0,3.0,4.0,5.0] 119[1.0,2.0,3.0,4.0,5.0]
120it :: (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])
138fromList [3.0,4.0,5.0] 139[3.0,4.0,5.0]
140it :: (Enum t, Num t, Foreign.Storable.Storable t) => Vector t
139 141
140-} 142-}
141subVector :: Storable t => Int -- ^ index of the starting element 143subVector :: 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]
172fromList [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]
175it :: Vector Double
173 176
174-} 177-}
175vjoin :: Storable t => [Vector t] -> Vector t 178vjoin :: 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]]
198it :: [Vector Double]
195 199
196-} 200-}
197takesV :: Storable t => [Int] -> Vector t -> [Vector t] 201takesV :: 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--
422range :: Int -> Vector I 423range :: Int -> Vector I
423range n = unsafePerformIO $ do 424range 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)