arrayfire-0.9.0.0: Haskell bindings to the ArrayFire general-purpose GPU library
CopyrightDavid Johnson (c) 2019-2026
LicenseBSD 3
MaintainerDavid Johnson <code@dmj.io>
StabilityExperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

ArrayFire.Data

Description

Functions for populating Array with Data.

>>> constant @Double [2,2] 2.0
 ArrayFire Array
[2 2 1 1]
   2.0000     2.0000
   2.0000     2.0000
Synopsis

Documentation

bitNot :: (AFType a, Bits a, Integral a) => Array a -> Array a Source #

Bitwise complement of every element in an Array

>>> A.bitNot (A.scalar @Int32 0)
ArrayFire Array
[1 1 1 1]
       -1

constant Source #

Arguments

:: AFType a 
=> [Int]

Dimensions

-> Double

Scalar value

-> Array a 

Creates a constant Array filled with a Double scalar. ArrayFire converts the value to the element type internally. Use constantComplex for complex arrays, constantLong / constantULong for 64-bit integer arrays where the value exceeds 2^53.

constantComplex Source #

Arguments

:: (Real r, AFType (Complex r)) 
=> [Int]

Dimensions

-> Complex r

Scalar value

-> Array (Complex r) 

Creates a constant complex Array from a Complex scalar.

constantLong Source #

Arguments

:: [Int]

Dimensions

-> Int

Scalar value

-> Array Int 

Creates a constant Array of 64-bit signed integers. Preserves the full integer value without Double rounding.

constantULong Source #

Arguments

:: [Int]

Dimensions

-> Word64

Scalar value

-> Array Word64 

Creates a constant Array of 64-bit unsigned integers. Preserves the full integer value without Double rounding.

arange :: AFType a => [Int] -> Int -> Array a Source #

Creates a range of values in an Array

>>> arange @Double [10] (-1)
ArrayFire Array
[10 1 1 1]
    0.0000
    1.0000
    2.0000
    3.0000
    4.0000
    5.0000
    6.0000
    7.0000
    8.0000
    9.0000

iota Source #

Arguments

:: AFType a 
=> [Int]

is the array containing sizes of the dimension

-> [Int]

is array containing the number of repetitions of the unit dimensions

-> Array a

is the generated array

Create an sequence [0, dims.elements() - 1] and modify to specified dimensions dims and then tile it according to tile_dims.

http://arrayfire.org/docs/group__data__func__iota.htm

>>> iota @Double [5,3] []
ArrayFire Array
[5 3 1 1]
    0.0000     5.0000    10.0000
    1.0000     6.0000    11.0000
    2.0000     7.0000    12.0000
    3.0000     8.0000    13.0000
    4.0000     9.0000    14.0000
>>> iota @Double [5,3] [1,2]
ArrayFire Array
[5 6 1 1]
    0.0000     5.0000    10.0000     0.0000     5.0000    10.0000
    1.0000     6.0000    11.0000     1.0000     6.0000    11.0000
    2.0000     7.0000    12.0000     2.0000     7.0000    12.0000
    3.0000     8.0000    13.0000     3.0000     8.0000    13.0000
    4.0000     9.0000    14.0000     4.0000     9.0000    14.0000

identity Source #

Arguments

:: AFType a 
=> [Int]

Dimensions

-> Array a 

Creates the identity Array from given dimensions

>>> identity [2,2]
ArrayFire Array
[2 2 1 1]
   1.0000     0.0000
   0.0000     1.0000

diagCreate Source #

Arguments

:: AFType a 
=> Array a

is the input array which is the diagonal

-> Int

is the diagonal index

-> Array a 

Create a diagonal matrix from input array when extract is set to false

>>> diagCreate (vector @Double 2 [1..]) 0
ArrayFire Array
[2 2 1 1]
   1.0000     0.0000
   0.0000     2.0000

diagExtract :: AFType a => Array a -> Int -> Array a Source #

Create a diagonal matrix from input array when extract is set to false

>>> diagExtract (matrix @Double (2,2) [[1,2],[3,4]]) 0
ArrayFire Array
[2 1 1 1]
    1.0000
    4.0000

join :: Int -> Array a -> Array a -> Array a Source #

Join two Arrays together along a specified dimension

>>> join 0 (matrix @Double (2,2) [[1,2],[3,4]]) (matrix @Double (2,2) [[5,6],[7,8]])
ArrayFire Array
[4 2 1 1]
    1.0000     3.0000
    2.0000     4.0000
    5.0000     7.0000
    6.0000     8.0000

joinMany :: Int -> [Array a] -> Array a Source #

Join many Arrays together along a specified dimension

>>> joinMany 0 [vector @Int 3 [1..], vector @Int 3 [1..]]
ArrayFire Array
[6 1 1 1]
         1
         2
         3
         1
         2
         3

withManyForeignPtr :: [ForeignPtr a] -> (Int -> Ptr (Ptr a) -> IO b) -> IO b Source #

Marshals a list of ForeignPtr into a temporary, contiguous C array of raw pointers, keeping every ForeignPtr alive for the duration of the action. The continuation receives the number of pointers and a pointer to the array.

tile :: Array a -> [Int] -> Array a Source #

Tiles an Array according to specified dimensions

>>> tile @Double (scalar 22.0) [5,5]
ArrayFire Array
[5 5 1 1]
22.0000    22.0000    22.0000    22.0000    22.0000
22.0000    22.0000    22.0000    22.0000    22.0000
22.0000    22.0000    22.0000    22.0000    22.0000
22.0000    22.0000    22.0000    22.0000    22.0000
22.0000    22.0000    22.0000    22.0000    22.0000

reorder :: Array a -> [Int] -> Array a Source #

Reorders an Array according to newly specified dimensions

  • FIX ME*
>>> reorder @Double (scalar 22.0) [5,5]
ArrayFire Array
[5 5 1 1]
22.0000    22.0000    22.0000    22.0000    22.0000
22.0000    22.0000    22.0000    22.0000    22.0000
22.0000    22.0000    22.0000    22.0000    22.0000
22.0000    22.0000    22.0000    22.0000    22.0000
22.0000    22.0000    22.0000    22.0000    22.0000

shift :: Array a -> Int -> Int -> Int -> Int -> Array a Source #

Shift elements in an Array along a specified dimension (elements will wrap).

>>> shift (vector @Double 4 [1..]) 2 0 0 0
ArrayFire Array
[4 1 1 1]
    3.0000
    4.0000
    1.0000
    2.0000

moddims :: Array a -> [Int] -> Array a Source #

Modify dimensions of array

>>> moddims (vector @Double 3 [1..]) [1,3]
ArrayFire Array
[1 3 1 1]
    1.0000     2.0000     3.0000

flat :: Array a -> Array a Source #

Flatten an Array into a single dimension

>>> flat (matrix @Double (2,2) [[1..],[1..]])
ArrayFire Array
[4 1 1 1]
    1.0000
    2.0000
    1.0000
    2.0000
>>> flat $ cube @Int (2,2,2) [[[1,1],[1,1]],[[1,1],[1,1]]]
ArrayFire Array
[8 1 1 1]
         1
         1
         1
         1
         1
         1
         1
         1

flip :: Array a -> Int -> Array a Source #

Flip the values of an Array along a specified dimension

>>> matrix @Double (2,2) [[2,2],[3,3]]
ArrayFire Array
[2 2 1 1]
    2.0000     3.0000
    2.0000     3.0000
>>> A.flip (matrix @Double (2,2) [[2,2],[3,3]]) 1
ArrayFire Array
[2 2 1 1]
    3.0000     2.0000
    3.0000     2.0000

lower Source #

Arguments

:: Array a

is the input matrix

-> Bool

boolean parameter specifying if the diagonal elements should be 1

-> Array a 

Create a lower triangular matrix from input array.

>>> lower (constant [2,2] 10 :: Array Double) True
ArrayFire Array
[2 2 1 1]
    1.0000     0.0000
   10.0000     1.0000

upper :: Array a -> Bool -> Array a Source #

Create an upper triangular matrix from input array.

>>> upper (constant [2,2] 10 :: Array Double) True
ArrayFire Array
[2 2 1 1]
   1.0000     10.0000
   0.0000     1.0000

select Source #

Arguments

:: Array CBool

is the conditional array

-> Array a

is the array containing elements from the true part of the condition

-> Array a

is the array containing elements from the false part of the condition

-> Array a

is the output containing elements of a when cond is true else elements from b

Selects elements from two arrays based on the values of a binary conditional array.

>>> cond = vector @CBool 5 [1,0,1,0,1]
>>> arr1 = vector @Double 5 (repeat 1)
>>> arr2 = vector @Double 5 (repeat 2)
>>> select cond arr1 arr2
ArrayFire Array
[5 1 1 1]
    1.0000
    2.0000
    1.0000
    2.0000
    1.0000

selectScalarR Source #

Arguments

:: Array CBool

is the conditional array

-> Array a

is the array containing elements from the true part of the condition

-> Double

is a scalar assigned to out when cond is false

-> Array a

the output containing elements of a when cond is true else elements from b

Selects elements from two arrays based on the values of a binary conditional array.

http://arrayfire.org/docs/group__data__func__select.htm#gab6886120d0bac4717276910e468bbe88

>>> cond = vector @CBool 5 [1,0,1,0,1]
>>> arr1 = vector @Double 5 (repeat 1)
>>> x = 99
>>> selectScalarR cond arr1 x
ArrayFire Array
[5 1 1 1]
    1.0000
   99.0000
    1.0000
   99.0000
    1.0000

selectScalarL Source #

Arguments

:: Array CBool

the conditional array

-> Double

a scalar assigned to out when cond is true

-> Array a

the array containing elements from the false part of the condition

-> Array a

is the output containing elements of a when cond is true else elements from b

Selects elements from two arrays based on the values of a binary conditional array.

ArrayFire Docs

>>> cond = vector @CBool 5 [1,0,1,0,1]
>>> arr1 = vector @Double 5 (repeat 1)
>>> x = 99
>>> selectScalarL cond x arr1
ArrayFire Array
[5 1 1 1]
   99.0000
    1.0000
   99.0000
    1.0000
   99.0000