summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Util.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/LinearAlgebra/Util.hs
parentb8b7b47450a1007d4d8c77bb7d04e2744c3bfcd4 (diff)
improved documentation
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Util.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Util.hs49
1 files changed, 41 insertions, 8 deletions
diff --git a/lib/Numeric/LinearAlgebra/Util.hs b/lib/Numeric/LinearAlgebra/Util.hs
index be01bc1..21b6188 100644
--- a/lib/Numeric/LinearAlgebra/Util.hs
+++ b/lib/Numeric/LinearAlgebra/Util.hs
@@ -13,7 +13,7 @@ Stability : provisional
13{-# OPTIONS_HADDOCK hide #-} 13{-# OPTIONS_HADDOCK hide #-}
14 14
15module Numeric.LinearAlgebra.Util( 15module Numeric.LinearAlgebra.Util(
16 16
17 -- * Convenience functions 17 -- * Convenience functions
18 size, disp, 18 size, disp,
19 zeros, ones, 19 zeros, ones,
@@ -65,8 +65,16 @@ import Numeric.LinearAlgebra.Util.Convolution
65import Graphics.Plot 65import Graphics.Plot
66 66
67 67
68{- | print a real matrix with given number of digits after the decimal point
69
70>>> disp 5 $ ident 2 / 3
712x2
720.33333 0.00000
730.00000 0.33333
74
75-}
68disp :: Int -> Matrix Double -> IO () 76disp :: Int -> Matrix Double -> IO ()
69-- ^ show a matrix with given number of digits after the decimal point 77
70disp n = putStrLn . dispf n 78disp n = putStrLn . dispf n
71 79
72-- | pseudorandom matrix with uniform elements between 0 and 1 80-- | pseudorandom matrix with uniform elements between 0 and 1
@@ -82,7 +90,16 @@ randm d r c = do
82rand :: Int -> Int -> IO (Matrix Double) 90rand :: Int -> Int -> IO (Matrix Double)
83rand = randm Uniform 91rand = randm Uniform
84 92
85-- | pseudorandom matrix with normal elements 93{- | pseudorandom matrix with normal elements
94
95>>> x <- randn 3 5
96>>> disp 3 x
973x5
980.386 -1.141 0.491 -0.510 1.512
990.069 -0.919 1.022 -0.181 0.745
1000.313 -0.670 -0.097 -1.575 -0.583
101
102-}
86randn :: Int -> Int -> IO (Matrix Double) 103randn :: Int -> Int -> IO (Matrix Double)
87randn = randm Gaussian 104randn = randm Gaussian
88 105
@@ -115,9 +132,17 @@ infixl 3 &
115(&) :: Vector Double -> Vector Double -> Vector Double 132(&) :: Vector Double -> Vector Double -> Vector Double
116a & b = vjoin [a,b] 133a & b = vjoin [a,b]
117 134
118-- | horizontal concatenation of real matrices 135{- | horizontal concatenation of real matrices
119-- 136
120-- (0x00a6 broken bar) 137 (0x00a6 broken bar)
138
139>>> ident 3 ¦ konst 7 (3,4)
140(3><7)
141 [ 1.0, 0.0, 0.0, 7.0, 7.0, 7.0, 7.0
142 , 0.0, 1.0, 0.0, 7.0, 7.0, 7.0, 7.0
143 , 0.0, 0.0, 1.0, 7.0, 7.0, 7.0, 7.0 ]
144
145-}
121infixl 3 ¦ 146infixl 3 ¦
122(¦) :: Matrix Double -> Matrix Double -> Matrix Double 147(¦) :: Matrix Double -> Matrix Double -> Matrix Double
123a ¦ b = fromBlocks [[a,b]] 148a ¦ b = fromBlocks [[a,b]]
@@ -141,7 +166,15 @@ row = asRow . fromList
141col :: [Double] -> Matrix Double 166col :: [Double] -> Matrix Double
142col = asColumn . fromList 167col = asColumn . fromList
143 168
144-- | extract selected rows 169{- | extract selected rows
170
171>>> (20><4) [1..] ? [2,1,1]
172(3><4)
173 [ 9.0, 10.0, 11.0, 12.0
174 , 5.0, 6.0, 7.0, 8.0
175 , 5.0, 6.0, 7.0, 8.0 ]
176
177-}
145infixl 9 ? 178infixl 9 ?
146(?) :: Element t => Matrix t -> [Int] -> Matrix t 179(?) :: Element t => Matrix t -> [Int] -> Matrix t
147(?) = flip extractRows 180(?) = flip extractRows
@@ -172,7 +205,7 @@ norm = pnorm PNorm2
172unitary :: Vector Double -> Vector Double 205unitary :: Vector Double -> Vector Double
173unitary v = v / scalar (norm v) 206unitary v = v / scalar (norm v)
174 207
175-- | (rows &&& cols) 208-- | ('rows' &&& 'cols')
176size :: Matrix t -> (Int, Int) 209size :: Matrix t -> (Int, Int)
177size m = (rows m, cols m) 210size m = (rows m, cols m)
178 211