summaryrefslogtreecommitdiff
path: root/examples/Real.hs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/Real.hs')
-rw-r--r--examples/Real.hs19
1 files changed, 14 insertions, 5 deletions
diff --git a/examples/Real.hs b/examples/Real.hs
index 02eba9f..9083b87 100644
--- a/examples/Real.hs
+++ b/examples/Real.hs
@@ -11,10 +11,10 @@ module Real(
11 row, 11 row,
12 col, 12 col,
13 (#),(&), (//), blocks, 13 (#),(&), (//), blocks,
14 rand 14 rand, randn
15) where 15) where
16 16
17import Numeric.LinearAlgebra hiding ((<>), (<|>), (<->), (<\>), (.*), (*/)) 17import Numeric.LinearAlgebra hiding ((<>), (<\>))
18import System.Random(randomIO) 18import System.Random(randomIO)
19 19
20infixl 7 <> 20infixl 7 <>
@@ -44,12 +44,21 @@ infixl 7 \>
44m \> v = flatten (m <\> reshape 1 v) 44m \> v = flatten (m <\> reshape 1 v)
45 45
46-- | Pseudorandom matrix with uniform elements between 0 and 1. 46-- | Pseudorandom matrix with uniform elements between 0 and 1.
47rand :: Int -- ^ rows 47randm :: RandDist
48 -> Int -- ^ rows
48 -> Int -- ^ columns 49 -> Int -- ^ columns
49 -> IO (Matrix Double) 50 -> IO (Matrix Double)
50rand r c = do 51randm d r c = do
51 seed <- randomIO 52 seed <- randomIO
52 return (reshape c $ randomVector seed Uniform (r*c)) 53 return (reshape c $ randomVector seed d (r*c))
54
55-- | Pseudorandom matrix with uniform elements between 0 and 1.
56rand :: Int -> Int -> IO (Matrix Double)
57rand = randm Uniform
58
59-- | Pseudorandom matrix with normal elements
60randn :: Int -> Int -> IO (Matrix Double)
61randn = randm Gaussian
53 62
54-- | Real identity matrix. 63-- | Real identity matrix.
55eye :: Int -> Matrix Double 64eye :: Int -> Matrix Double