Copyright | David Johnson (c) 2019-2020 |
---|---|
License | BSD3 |
Maintainer | David Johnson <djohnson.m@gmail.com> |
Stability | Experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
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
- createSparseArray :: (AFType a, Fractional a) => Int -> Int -> Array a -> Array Int32 -> Array Int32 -> Storage -> Array a
- createSparseArrayFromDense :: (AFType a, Fractional a) => Array a -> Storage -> Array a
- sparseConvertTo :: (AFType a, Fractional a) => Array a -> Storage -> Array a
- sparseToDense :: (AFType a, Fractional a) => Array a -> Array a
- sparseGetInfo :: (AFType a, Fractional a) => Array a -> (Array a, Array a, Array a, Storage)
- sparseGetValues :: (AFType a, Fractional a) => Array a -> Array a
- sparseGetRowIdx :: (AFType a, Fractional a) => Array a -> Array a
- sparseGetColIdx :: (AFType a, Fractional a) => Array a -> Array a
- sparseGetStorage :: (AFType a, Fractional a) => Array a -> Storage
- sparseGetNNZ :: (AFType a, Fractional a) => Array a -> Int
Documentation
:: (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 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.
- 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 #
:: (AFType a, Fractional a) | |
=> Array a | is the source dense matrix |
-> Storage | is the storage format of the sparse array |
-> Array a |
|
This function converts a dense af_array into a sparse array.
- 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
:: (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.
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
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.
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.
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...
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...
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.
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...
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