arrayfire-0.4.0.0: Haskell bindings to the ArrayFire general-purpose GPU library

CopyrightDavid Johnson (c) 2019-2020
LicenseBSD3
MaintainerDavid Johnson <djohnson.m@gmail.com>
StabilityExperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

ArrayFire.Random

Description

RandomEngine generation, Random Array generation.

{-# LANGUAGE TypeApplications #-}
module Main where

import ArrayFire

main :: IO ()
main = do
  seed <- getSeed
  -- ^ Retrieves seed
  engine <- createRandomEngine Mersenne seed
  -- ^ Creates engine
  array <- randomUniform [3,3] engine
  -- ^ Creates random Array from engine with uniformly distributed data
  print array

  print =<< randu @Double [2,2]
  -- ^ Shorthand for creating random Array
ArrayFire Array
[3 3 1 1]
   0.4446     0.1143     0.4283
   0.5725     0.1456     0.9182
   0.1915     0.1643     0.5997
ArrayFire Array
[2 2 1 1]
   0.6010     0.0278
   0.9806     0.2126
Synopsis

Documentation

createRandomEngine Source #

Arguments

:: Int

Initial seed value of random number generator

-> RandomEngineType

Type of random engine to employ

-> IO RandomEngine

Opaque RandomEngine handle

Create random number generator object.

>>> engine <- createRandomEngine 100 Philox

retainRandomEngine Source #

Arguments

:: RandomEngine

RandomEngine to retain

-> IO RandomEngine

Retained RandomEngine

Retains RandomEngine reference

>>> nextEngine <- retainRandomEngine engine

setRandomEngine Source #

Sets RandomEngine to a new RandomEngineType

>>> setRandomEngine engine Philox

getRandomEngineType Source #

Retrieves RandomEngine

>>> randomEngineType <- getRandomEngineType engine

randomEngineSetSeed Source #

Arguments

:: RandomEngine

RandomEngine argument

-> Int

Seed

-> IO () 

Sets seed on RandomEngine

>>> randomEngineSetSeed engine 100

getDefaultRandomEngine :: IO RandomEngine Source #

Retrieve default RandomEngine

>>> engine <- getDefaultRandomEngine

setDefaultRandomEngineType Source #

Arguments

:: RandomEngineType

RandomEngine type

-> IO () 

Set defualt RandomEngine type

>>> setDefaultRandomEngineType Philox

randomEngineGetSeed Source #

Arguments

:: RandomEngine

RandomEngine argument

-> IO Int 

Retrieve seed of RandomEngine

>>> seed <- randomEngineGetSeed engine

setSeed :: Int -> IO () Source #

Set random seed

>>> setSeed 100

getSeed :: IO Int Source #

Retrieve random seed

>>> seed <- getSeed

randn Source #

Arguments

:: (AFType a, Fractional a) 
=> [Int]

Dimensions of random array

-> IO (Array a) 

Generate random Array

>>> randn @Double [2,2]
ArrayFire Array
[2 2 1 1]
   0.9428    -0.9523
  -1.0564    -0.4199

randu Source #

Arguments

:: AFType a 
=> [Int]

Dimensions of random array

-> IO (Array a) 

Generate random uniform Array

>>> randu @Double [2,2]
ArrayFire Array
[2 2 1 1]
   0.6010     0.0278
   0.9806     0.2126

randomUniform Source #

Arguments

:: AFType a 
=> [Int]

Dimensions of random array

-> RandomEngine

RandomEngine argument

-> IO (Array a) 

Generate random uniform Array

>>> randonUniform @Double [2,2] =<< getDefaultRandomEngine
ArrayFire Array
[2 2 1 1]
   0.0655     0.5497
   0.2864     0.3410

randomNormal Source #

Arguments

:: AFType a 
=> [Int]

Dimensions of random array

-> RandomEngine

RandomEngine argument

-> IO (Array a) 

Generate random uniform Array

>>> randonNormal @Double [2,2] =<< getDefaultRandomEngine
ArrayFire Array
[2 2 1 1]
  -1.1850    -0.2946
  -0.7206    -0.6813