arrayfire.sparse module

Functions to create and manipulate sparse matrices.

arrayfire.sparse.convert_sparse(sparse, storage)[source]

Convert sparse matrix from one format to another.

Parameters
storagearrayfire.STORAGE.
Returns
Sparse matrix converted to the appropriate type.
arrayfire.sparse.convert_sparse_to_dense(sparse)[source]

Create a dense matrix from a sparse matrix.

Parameters
sparseaf.Array.
  • A sparse matrix.

Returns
A dense matrix.
arrayfire.sparse.create_sparse(values, row_idx, col_idx, nrows, ncols, storage=<STORAGE.CSR: 1>)[source]

Create a sparse matrix from it’s constituent parts.

Parameters
valuesaf.Array.
  • Contains the non zero elements of the sparse array.

row_idxaf.Array.
  • Contains row indices of the sparse array.

col_idxaf.Array.
  • Contains column indices of the sparse array.

nrowsint.
  • specifies the number of rows in sparse matrix.

ncolsint.
  • specifies the number of columns in sparse matrix.

storageoptional: arrayfire.STORAGE. default: arrayfire.STORAGE.CSR.
  • Can be one of arrayfire.STORAGE.CSR, arrayfire.STORAGE.COO.

Returns
A sparse matrix.
arrayfire.sparse.create_sparse_from_dense(dense, storage=<STORAGE.CSR: 1>)[source]

Create a sparse matrix from a dense matrix.

Parameters
denseaf.Array.
  • A dense matrix.

storageoptional: arrayfire.STORAGE. default: arrayfire.STORAGE.CSR.
  • Can be one of arrayfire.STORAGE.CSR, arrayfire.STORAGE.COO.

Returns
A sparse matrix.
arrayfire.sparse.create_sparse_from_host(values, row_idx, col_idx, nrows, ncols, storage=<STORAGE.CSR: 1>)[source]

Create a sparse matrix from it’s constituent parts.

Parameters
valuesAny datatype that can be converted to array.
  • Contains the non zero elements of the sparse array.

row_idxAny datatype that can be converted to array.
  • Contains row indices of the sparse array.

col_idxAny datatype that can be converted to array.
  • Contains column indices of the sparse array.

nrowsint.
  • specifies the number of rows in sparse matrix.

ncolsint.
  • specifies the number of columns in sparse matrix.

storageoptional: arrayfire.STORAGE. default: arrayfire.STORAGE.CSR.
  • Can be one of arrayfire.STORAGE.CSR, arrayfire.STORAGE.COO.

Returns
A sparse matrix.
arrayfire.sparse.sparse_get_col_idx(sparse)[source]

Get the column indices from sparse matrix.

Parameters
sparseaf.Array.
  • A sparse matrix.

Returns
arrayfire array containing the non zero elements.
arrayfire.sparse.sparse_get_info(sparse)[source]

Get the constituent arrays and storage info from a sparse matrix.

Parameters
sparseaf.Array.
  • A sparse matrix.

Returns
(values, row_idx, col_idx, storage) where
valuesarrayfire.Array containing non zero elements from sparse matrix
row_idxarrayfire.Array containing the row indices
col_idxarrayfire.Array containing the column indices
storagesparse storage
arrayfire.sparse.sparse_get_nnz(sparse)[source]

Get the column indices from sparse matrix.

Parameters
sparseaf.Array.
  • A sparse matrix.

Returns
Number of non zero elements in the sparse matrix.
arrayfire.sparse.sparse_get_row_idx(sparse)[source]

Get the row indices from sparse matrix.

Parameters
sparseaf.Array.
  • A sparse matrix.

Returns
arrayfire array containing the non zero elements.
arrayfire.sparse.sparse_get_storage(sparse)[source]

Get the column indices from sparse matrix.

Parameters
sparseaf.Array.
  • A sparse matrix.

Returns
Number of non zero elements in the sparse matrix.
arrayfire.sparse.sparse_get_values(sparse)[source]

Get the non zero values from sparse matrix.

Parameters
sparseaf.Array.
  • A sparse matrix.

Returns
arrayfire array containing the non zero elements.