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: storage : arrayfire.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: sparse : af.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: values : af.Array.
- Contains the non zero elements of the sparse array.
row_idx : af.Array.
- Contains row indices of the sparse array.
col_idx : af.Array.
- Contains column indices of the sparse array.
nrows : int.
- specifies the number of rows in sparse matrix.
ncols : int.
- specifies the number of columns in sparse matrix.
storage : optional: 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: dense : af.Array.
- A dense matrix.
storage : optional: 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: values : Any datatype that can be converted to array.
- Contains the non zero elements of the sparse array.
row_idx : Any datatype that can be converted to array.
- Contains row indices of the sparse array.
col_idx : Any datatype that can be converted to array.
- Contains column indices of the sparse array.
nrows : int.
- specifies the number of rows in sparse matrix.
ncols : int.
- specifies the number of columns in sparse matrix.
storage : optional: 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: sparse : af.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: sparse : af.Array.
- A sparse matrix.
Returns: (values, row_idx, col_idx, storage) where
values : arrayfire.Array containing non zero elements from sparse matrix
row_idx : arrayfire.Array containing the row indices
col_idx : arrayfire.Array containing the column indices
storage : sparse storage
-
arrayfire.sparse.
sparse_get_nnz
(sparse)[source]¶ Get the column indices from sparse matrix.
Parameters: sparse : af.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: sparse : af.Array.
- A sparse matrix.
Returns: arrayfire array containing the non zero elements.