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

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

ArrayFire.Util

Description

Various utilities for working with the ArrayFire C library

import qualified ArrayFire as A
import           Control.Monad

main :: IO ()
main = do
  let arr = A.constant [1,1,1,1] 10
  idx <- A.saveArray "key" arr "file.array" False
  foundIndex <- A.readArrayKeyCheck "file.array" "key"
  when (idx == foundIndex) $ do
    array <- A.readArrayKey "file.array" "key"
    print array
ArrayFire Array
[ 1 1 1 1 ]
        10
Synopsis

Documentation

getVersion :: IO (Int, Int, Int) Source #

Retrieve version for ArrayFire API

>>> print =<< getVersion
(3.6.4)

printArray Source #

Arguments

:: Array a

Input Array

-> IO () 

Prints array to stdout

>>> printArray (constant @Double [1] 1)
ArrayFire Array
  [ 1 1 1 1 ]
      1.0

getRevision :: IO String Source #

Gets git revision of ArrayFire

>>> putStrLn =<< getRevision
1b8030c5

printArrayGen Source #

Arguments

:: String

is the expression or name of the array

-> Array a

is the input array

-> Int

precision for the display

-> IO () 

Prints Array with error codes

>>> printArrayGen "test" (constant @Double [1] 1) 2
ArrayFire Array
  [ 1 1 1 1 ]
      1.00

saveArray Source #

Arguments

:: String

An expression used as tag/key for the Array during readArray

-> Array a

Input Array

-> FilePath

Path that Array will be saved

-> Bool

Used to append to an existing file when True and create or overwrite an existing file when False

-> IO Int

The index location of the Array in the file

Saves Array to disk

Save an array to a binary file. The saveArray and readArray functions are designed to provide store and read access to arrays using files written to disk. http://arrayfire.org/docs/group__stream__func__save.htm

>>> saveArray "my array" (constant @Double [1] 1) "array.file" True
0

readArrayIndex Source #

Arguments

:: FilePath

Path to Array location

-> Int

Index into Array

-> IO (Array a) 

Reads Array by index

The saveArray and readArray functions are designed to provide store and read access to arrays using files written to disk. http://arrayfire.org/docs/group__stream__func__save.htm

>>> readArrayIndex "array.file" 0
ArrayFire Array
  [ 1 1 1 1 ]
         10.0000

readArrayKey Source #

Arguments

:: FilePath

Path to Array

-> String

Key of Array on disk

-> IO (Array a)

Returned Array

Reads Array by key

>>> readArrayKey "array.file" "my array"
ArrayFire Array
   [ 1 1 1 1 ]
       10.0000

readArrayKeyCheck Source #

Arguments

:: FilePath

Path to file

-> String

Key

-> IO Int

is the tag/name of the array to be read. The key needs to have an exact match.

Reads Array, checks if a key exists in the specified file

When reading by key, it may be a good idea to run this function first to check for the key and then call the readArray using the index. http://arrayfire.org/docs/group__stream__func__read.htm#ga31522b71beee2b1c06d49b5aa65a5c6f

>>> readArrayCheck "array.file" "my array"
0

arrayString Source #

Arguments

:: Array a

Input Array

-> String

String representation of Array

Convert ArrayFire Array to String, used for Show instance.

>>> putStrLn $ arrayString (constant @Double 10 [1,1,1,1])
ArrayFire Array
   [ 1 1 1 1 ]
       10.0000

arrayToString Source #

Arguments

:: String

Name of Array

-> Array a

Array input

-> Int

Precision of Array values.

-> Bool

If True, performs takes the transpose before rendering to String

-> String

Array rendered to String

Convert ArrayFire Array to String

>>> print (constant @Double 10 [1,1,1,1]) 4 False
ArrayFire Array
   [ 1 1 1 1 ]
       10.0000

getSizeOf Source #

Arguments

:: AFType a 
=> Proxy a

Witness of Haskell type that mirrors ArrayFire type.

-> Int

Size of ArrayFire type

Retrieve size of ArrayFire data type

>>> getSizeOf (Proxy @ Double)
8