diff options
Diffstat (limited to 'packages/base/src/Numeric/Vectorized.hs')
-rw-r--r-- | packages/base/src/Numeric/Vectorized.hs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/packages/base/src/Numeric/Vectorized.hs b/packages/base/src/Numeric/Vectorized.hs index a2d7f70..5aebb14 100644 --- a/packages/base/src/Numeric/Vectorized.hs +++ b/packages/base/src/Numeric/Vectorized.hs | |||
@@ -17,7 +17,8 @@ module Numeric.Vectorized ( | |||
17 | FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ, | 17 | FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ, |
18 | FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, vectorMapValQ, | 18 | FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, vectorMapValQ, |
19 | FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, | 19 | FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, |
20 | vectorScan, saveMatrix | 20 | vectorScan, saveMatrix, |
21 | Seed, RandDist(..), randomVector | ||
21 | ) where | 22 | ) where |
22 | 23 | ||
23 | import Data.Packed.Internal.Common | 24 | import Data.Packed.Internal.Common |
@@ -308,7 +309,13 @@ vectorScan s = do | |||
308 | foreign import ccall unsafe "saveMatrix" c_saveMatrix | 309 | foreign import ccall unsafe "saveMatrix" c_saveMatrix |
309 | :: CString -> CString -> TM | 310 | :: CString -> CString -> TM |
310 | 311 | ||
311 | saveMatrix :: FilePath -> String -> Matrix Double -> IO () | 312 | {- | save a matrix as a 2D ASCII table |
313 | -} | ||
314 | saveMatrix | ||
315 | :: FilePath | ||
316 | -> String -- ^ \"printf\" format (e.g. \"%.2f\", \"%g\", etc.) | ||
317 | -> Matrix Double | ||
318 | -> IO () | ||
312 | saveMatrix name format m = do | 319 | saveMatrix name format m = do |
313 | cname <- newCString name | 320 | cname <- newCString name |
314 | cformat <- newCString format | 321 | cformat <- newCString format |
@@ -317,4 +324,23 @@ saveMatrix name format m = do | |||
317 | free cformat | 324 | free cformat |
318 | return () | 325 | return () |
319 | 326 | ||
327 | -------------------------------------------------------------------------------- | ||
328 | |||
329 | type Seed = Int | ||
330 | |||
331 | data RandDist = Uniform -- ^ uniform distribution in [0,1) | ||
332 | | Gaussian -- ^ normal distribution with mean zero and standard deviation one | ||
333 | deriving Enum | ||
334 | |||
335 | -- | Obtains a vector of pseudorandom elements (use randomIO to get a random seed). | ||
336 | randomVector :: Seed | ||
337 | -> RandDist -- ^ distribution | ||
338 | -> Int -- ^ vector size | ||
339 | -> Vector Double | ||
340 | randomVector seed dist n = unsafePerformIO $ do | ||
341 | r <- createVector n | ||
342 | app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector" | ||
343 | return r | ||
344 | |||
345 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV | ||
320 | 346 | ||