With the release of <strong>ArrayFire v3.4</strong>, we have added a number of features that will help our vast range of users. Our users have been asking us for a way to reduce the memory footprint of their data on the GPU. And now we have answered our users' requests.
Introducing Sparse Matrices in ArrayFire!

Sparse Data Structure
A sparse data structure is one where all the non-zero elements are not stored. Sparse matrices are useful when the number of zero-values elements are >> number of non-zero elements (sparsity of the matrix is high).
The sparse data structure in general is stored as 3 arrays.
* A data or values array containing all the non-zero elements
* A vector for row indices (based on storage format).
* A vector for column indices (based on storage format).

There are many ways to store sparse matrices, the most prominent of which are <a href="https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_row_.28CSR.2C_CRS_or_Yale_format.29">Compressed Sparse Row</a>, <a href="https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_column_.28CSC_or_CCS.29">Compressed Storage Column</a>, <a href="https://en.wikipedia.org/wiki/Sparse_matrix#Coordinate_list_.28COO.29">Coordinate Format</a>. ArrayFire supports CSR and COO format, with CSC support coming in future releases.

A more detailed description of Sparse Matrix can be found on <a href="https://en.wikipedia.org/wiki/Sparse_matrix">Wikipedia</a>.

Sparse in ArrayFire
In ArrayFire, Sparse arrays use the same user facing object - af::array. This makes working with sparse arrays all the more seamless.
We have added a function <a href="http://arrayfire.org/docs/group__method__mat.htm#ga5945f95549bae25f75694a69d98ca584">af::array::issparse()</a> that allows users to check if an array is sparse or not.
Although externally, there is no difference between a sparse and dense array, internally, the sparse array is stored as 3 independent arrays along with other meta data.
These arrays, as well as other properties can be fetched using the <a href="http://arrayfire.org/docs/group__sparse__func.htm">sparse functions</a>.

Sparse Functionality
As of v3.4, the following features are supported for sparse arrays:
* <a href="http://arrayfire.org/docs/group__sparse__func__create.htm">Creation for sparse arrays.</a>
  * <a href="http://arrayfire.org/docs/group__sparse__func__create.htm#gae4621e58bfaf6d80668309824fde86c0">From 3 (data, row, column) sparse host or device memory vectors.</a>
  * <a href="http://arrayfire.org/docs/group__sparse__func__create.htm#gae9a843c7e93b05e6b090ca32b271ebe9">From 3 (data, row, column) sparse af::arrays.</a>
  * <a href="http://arrayfire.org/docs/group__sparse__func__create.htm#gac0d367d8c9daf27b36a6981bbfcdb970">From dense af::array.</a>
  * To create a sparse array from host or device dense array, first create a dense af::array, and then pass it to create sparse af::array from dense af::array.
* <a href="http://arrayfire.org/docs/group__sparse__func__convert__to.htm">Storage format conversions.</a>
  * <a href="http://arrayfire.org/docs/group__sparse__func__create.htm#gac0d367d8c9daf27b36a6981bbfcdb970">Dense to CSR/COO.</a>
  * <a href="http://arrayfire.org/docs/group__sparse__func__dense.htm">CSR/COO to dense.</a>
* Sparse-Dense Matrix Multiplication (SPMM/SPMV)
  * Sparse Matrix - Dense Matrix
  * Sparse Matrix - Dense Vector
  * Options for Sparse Matrix to be transposed.
The Sparse-Dense Matrix Multiplcation is a implemented as a part of <a href="http://arrayfire.org/docs/group__blas__func__matmul.htm#ga63306b6ed967bd1055086db862fe885b">af::matmul()</a>. This is part of making the usage of sparse arrays seamless with regular arrays.

Example


Performance and Memory Footprint

As with all ArrayFire features, Sparse support is available across all backends and all architectures.