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.Sparse

Description

ArrayFire Docs Functions to create and handle sparse arrays and matrix operations.

  • Note* Sparse functionality support was added to ArrayFire in v3.4.0.
>>> createSparseArray 10 10 (matrix @Double (10,10) [[1,2],[3,4]]) (vector @Int32 10 [1..]) (vector @Int32 10 [1..]) CSR
Synopsis

Documentation

createSparseArray Source #

Arguments

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

is the number of rows in the dense matrix

-> Int

is the number of columns in the dense matrix

-> Array a

is the Array containing the non-zero elements of the matrix

-> Array Int32

is the row indices for the sparse array

-> Array Int32

the column indices for the sparse array

-> Storage

the storage format of the sparse array

-> Array a

Sparse Array

This function converts af::array of values, row indices and column indices into a sparse array.

ArrayFire Docs

  • Note* This function only create references of these arrays into the sparse data structure and does not do deep copies.
>>> createSparseArray 10 10 (matrix @Double (10,10) [[1,2],[3,4]]) (vector @Int32 10 [1..]) (vector @Int32 10 [1..]) CSR

createSparseArrayFromDense Source #

Arguments

:: (AFType a, Fractional a) 
=> Array a

is the source dense matrix

-> Storage

is the storage format of the sparse array

-> Array a

Array for the sparse array with the given storage type

This function converts a dense af_array into a sparse array.

ArrayFire Docs

  • Note* This function only create references of these arrays into the sparse data structure and does not do deep copies.
>>> createSparseArrayFromDense (matrix @Double (2,2) [[1,2],[3,4]]) CSR
ArrayFire Array
Storage Format : AF_STORAGE_CSR
[2 2 1 1]
ArrayFire Array: Values
[4 1 1 1]
    1.0000     3.0000     2.0000     4.0000
ArrayFire Array: RowIdx
[3 1 1 1]
         0          2          4
ArrayFire Array: ColIdx
[4 1 1 1]
         0          1          0          1

sparseConvertTo Source #

Arguments

:: (AFType a, Fractional a) 
=> Array a

is the source sparse matrix to be converted

-> Storage

is the storage format of the output sparse array

-> Array a

the sparse array with the given storage type

Convert an existing sparse array into a different storage format.

ArrayFire Docs

Converting storage formats is allowed between CSR, COO and DENSE.

When converting to DENSE, a dense array is returned.

  • Note* CSC is currently not supported.
>>> array = createSparseArrayFromDense (matrix @Double (2,2) [[1,2],[3,4]]) CSR
>>> array
ArrayFire Array
Storage Format : AF_STORAGE_CSR
[2 2 1 1]
ArrayFire Array: Values
[4 1 1 1]
    1.0000     3.0000     2.0000     4.0000
ArrayFire Array: RowIdx
[3 1 1 1]
         0          2          4
ArrayFire Array: ColIdx
[4 1 1 1]
         0          1          0          1
>>> sparseConvertTo array COO
ArrayFire Array
Storage Format : AF_STORAGE_COO
[2 2 1 1]
ArrayFire Array: Values
[4 1 1 1]
    1.0000     2.0000     3.0000     4.0000
ArrayFire Array: RowIdx
[4 1 1 1]
         0          1          0          1
ArrayFire Array: ColIdx
[4 1 1 1]
         0          0          1          1

sparseToDense :: (AFType a, Fractional a) => Array a -> Array a Source #

Returns a dense array from a sparse input

ArrayFire Docs

Converts the sparse matrix into a dense matrix and returns it

>>> array = createSparseArrayFromDense (matrix @Double (2,2) [[1,2],[3,4]]) CSR
>>> array
ArrayFire Array
Storage Format : AF_STORAGE_CSR
[2 2 1 1]
ArrayFire Array: Values
[4 1 1 1]
    1.0000     3.0000     2.0000     4.0000
ArrayFire Array: RowIdx
[3 1 1 1]
         0          2          4
ArrayFire Array: ColIdx
[4 1 1 1]
         0          1          0          1
>>> sparseToDense array
ArrayFire Array
[2 2 1 1]
    1.0000     2.0000
    3.0000     4.0000

sparseGetInfo :: (AFType a, Fractional a) => Array a -> (Array a, Array a, Array a, Storage) Source #

Returns reference to components of the input sparse array.

ArrayFire Docs

Returns reference to values, row indices, column indices and storage format of an input sparse array

>>> (values, cols, rows, storage) = sparseGetInfo $ createSparseArrayFromDense (matrix @Double (2,2) [[1,2],[3,4]]) CSR
>>> values
ArrayFire Array
[4 1 1 1]
   1.0000     3.0000     2.0000     4.0000
>>> cols
ArrayFire Array
[3 1 1 1]
        0          2          4
>>> rows
ArrayFire Array
[4 1 1 1]
        0          1          0          1
>>> storage
CSR

sparseGetValues :: (AFType a, Fractional a) => Array a -> Array a Source #

Returns reference to the values component of the sparse array.

ArrayFire Docs

Returns reference to the values component of the sparse array. Values is the Array containing the non-zero elements of the dense matrix.

>>> sparseGetValues (createSparseArrayFromDense (matrix @Double (2,2) [[1,2],[3,4]]) CSR)
ArrayFire Array
[4 1 1 1]
   1.0000     3.0000     2.0000     4.0000

sparseGetRowIdx :: (AFType a, Fractional a) => Array a -> Array a Source #

Returns reference to the row indices component of the sparse array. More...

ArrayFire Docs

Returns reference to the row indices component of the sparse array. Row indices is the Array containing the column indices of the sparse array.

>>> sparseGetRowIdx (createSparseArrayFromDense (matrix @Double (2,2) [[1,2],[3,4]]) CSR)
ArrayFire Array
[3 1 1 1]
        0          2          4

sparseGetColIdx :: (AFType a, Fractional a) => Array a -> Array a Source #

Returns reference to the column indices component of the sparse array. More...

ArrayFire Docs

Returns reference to the column indices component of the sparse array. Column indices is the Array containing the column indices of the sparse array.

>>> sparseGetColIdx (createSparseArrayFromDense (matrix @Double (2,2) [[1,2],[3,4]]) CSR)
ArrayFire Array
[4 1 1 1]
        0          1          0          1

sparseGetStorage :: (AFType a, Fractional a) => Array a -> Storage Source #

Returns the storage type of a sparse array.

ArrayFire Docs

Returns the number of non zero elements in the sparse array. This is always equal to the size of the values array.

>>> sparseGetStorage $ createSparseArrayFromDense (matrix @Double (2,2) [[1,2],[3,4]]) CSR
CSR

sparseGetNNZ :: (AFType a, Fractional a) => Array a -> Int Source #

Returns the number of non zero elements in the sparse array. More...

ArrayFire Docs

Returns the number of non zero elements in the sparse array. This is always equal to the size of the values array.

>>> sparseGetNNZ $ createSparseArrayFromDense (matrix @Double (2,2) [[1,2],[3,4]]) CSR
4