Conversion Functions#
aoclsparse_convert.h provides sparse format conversion functions.
aoclsparse_csr2ell_width()#
-
aoclsparse_status aoclsparse_csr2ell_width(aoclsparse_int m, aoclsparse_int nnz, const aoclsparse_int *csr_row_ptr, aoclsparse_int *ell_width)#
Convert a sparse CSR matrix into a sparse ELL matrix.
aoclsparse_csr2ell_widthcomputes the maximum of the per row non-zero elements over all rows, the ELLwidth, for a given CSR matrix.- Parameters
m – [in] number of rows of the sparse CSR matrix.
nnz – [in] number of non-zero entries of the sparse CSR matrix.
csr_row_ptr – [in] array of
m+1 elements that point to the start of every row of the sparse CSR matrix.ell_width – [out] pointer to the number of non-zero elements per row in ELL storage format.
- Return values
aoclsparse_status_success – the operation completed successfully.
aoclsparse_status_invalid_size –
mis invalid.aoclsparse_status_invalid_pointer –
csr_row_ptr, orell_widthpointer is invalid.aoclsparse_status_internal_error – an internal error occurred.
aoclsparse_?csr2ell()#
-
aoclsparse_status aoclsparse_scsr2ell(aoclsparse_int m, const aoclsparse_mat_descr descr, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const float *csr_val, aoclsparse_int *ell_col_ind, float *ell_val, aoclsparse_int ell_width)#
-
aoclsparse_status aoclsparse_dcsr2ell(aoclsparse_int m, const aoclsparse_mat_descr descr, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const double *csr_val, aoclsparse_int *ell_col_ind, double *ell_val, aoclsparse_int ell_width)#
Convert a sparse CSR matrix into a sparse ELLPACK matrix.
aoclsparse_?csr2ellconverts a CSR matrix into an ELL matrix. It is assumed, thatell_valandell_col_indare allocated. Allocation size is computed by the number of rows times the number of ELL non-zero elements per row, such that \(\text{nnz}_{\text{ELL}} \) is equal tomtimesell_width. The number of ELL non-zero elements per row is obtained by aoclsparse_csr2ell_width(). The index base is preserved during the conversion.- Parameters
m – [in] number of rows of the sparse CSR matrix.
descr – [in] descriptor of the input sparse CSR matrix. Only the base index is used in the conversion process, the remaining descriptor elements are ignored.
csr_val – [in] array containing the values of the sparse CSR matrix.
csr_row_ptr – [in] array of
m+1 elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array containing the column indices of the sparse CSR matrix.
ell_width – [in] number of non-zero elements per row in ELL storage format.
ell_val – [out] array of
mtimesell_widthelements of the sparse ELL matrix.ell_col_ind – [out] array of
mtimesell_widthelements containing the column indices of the sparse ELL matrix.
- Return values
aoclsparse_status_success – the operation completed successfully.
aoclsparse_status_invalid_handle – the library context was not initialized.
aoclsparse_status_invalid_size –
morell_widthis invalid.aoclsparse_status_invalid_pointer –
csr_val,csr_row_ptr,csr_col_ind,ell_valorell_col_indpointer is invalid.
aoclsparse_csr2dia_ndiag()#
-
aoclsparse_status aoclsparse_csr2dia_ndiag(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, aoclsparse_int nnz, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_int *dia_num_diag)#
Convert a sparse CSR matrix into a sparse DIA matrix.
aoclsparse_csr2dia_ndiagcomputes number of diagonals for a given CSR matrix.- Parameters
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
descr – [in] descriptor of the input sparse CSR matrix. Only the base index is used in computing the diagonals, the remaining descriptor elements are ignored.
nnz – [in] number of non-zero entries of the sparse CSR matrix.
csr_row_ptr – [in] array of
m+1 elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array containing the column indices of the sparse CSR matrix.
dia_num_diag – [out] pointer to the number of diagonals with non-zeroes in DIA storage format.
- Return values
aoclsparse_status_success – the operation completed successfully.
aoclsparse_status_invalid_size –
mis invalid.aoclsparse_status_invalid_pointer –
csr_row_ptr, orell_widthpointer is invalid.aoclsparse_status_internal_error – an internal error occurred.
aoclsparse_?csr2dia()#
-
aoclsparse_status aoclsparse_scsr2dia(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const float *csr_val, aoclsparse_int dia_num_diag, aoclsparse_int *dia_offset, float *dia_val)#
-
aoclsparse_status aoclsparse_dcsr2dia(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const double *csr_val, aoclsparse_int dia_num_diag, aoclsparse_int *dia_offset, double *dia_val)#
Convert a sparse CSR matrix into a sparse DIA matrix.
aoclsparse_?csr2diaconverts a CSR matrix into an DIA matrix. It is assumed, thatdia_valanddia_offsetare allocated. Allocation size is computed by the number of rows times the number of diagonals. The number of DIA diagonals is obtained by aoclsparse_csr2dia_ndiag().The index base is preserved during the conversion.- Parameters
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of cols of the sparse CSR matrix.
descr – [in] descriptor of the input sparse CSR matrix. Only the base index is used in the conversion process, the remaining descriptor elements are ignored.
csr_row_ptr – [in] array of
m+1 elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array containing the column indices of the sparse CSR matrix.
csr_val – [in] array containing the values of the sparse CSR matrix.
dia_num_diag – [in] number of diagoanls in ELL storage format.
dia_offset – [out] array of
dia_num_diagelements containing the diagonal offsets from main diagonal.dia_val – [out] array of
mtimesdia_num_diagelements of the sparse DIA matrix.
- Return values
aoclsparse_status_success – the operation completed successfully.
aoclsparse_status_invalid_handle – the library context was not initialized.
aoclsparse_status_invalid_size –
morell_widthis invalid.aoclsparse_status_invalid_pointer –
csr_val,csr_row_ptr,csr_col_ind,ell_valorell_col_indpointer is invalid.
aoclsparse_csr2bsr_nnz()#
-
aoclsparse_status aoclsparse_csr2bsr_nnz(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_int block_dim, aoclsparse_int *bsr_row_ptr, aoclsparse_int *bsr_nnz)#
aoclsparse_csr2bsr_nnzcomputes the number of nonzero block columns per row and the total number of nonzero blocks in a sparse BSR matrix given a sparse CSR matrix as input.- Parameters
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
descr – [in] descriptor of the input sparse CSR matrix. Only the base index is used in computing the nnz blocks, the remaining descriptor elements are ignored.
csr_row_ptr – [in] integer array containing
m+1 elements that point to the start of each row of the CSR matrixcsr_col_ind – [in] integer array of the column indices for each non-zero element in the CSR matrix
block_dim – [in] the block dimension of the BSR matrix. Between 1 and min(m, n)
bsr_row_ptr – [out] integer array containing
mb+1 elements that point to the start of each block row of the BSR matrixbsr_nnz – [out] total number of nonzero elements in device or host memory.
- Return values
aoclsparse_status_success – the operation completed successfully.
aoclsparse_status_invalid_size –
mornorblock_dimis invalid.aoclsparse_status_invalid_pointer –
csr_row_ptrorcsr_col_indorbsr_row_ptrorbsr_nnzpointer is invalid.
aoclsparse_?csr2bsr()#
-
aoclsparse_status aoclsparse_scsr2bsr(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const float *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_int block_dim, float *bsr_val, aoclsparse_int *bsr_row_ptr, aoclsparse_int *bsr_col_ind)#
-
aoclsparse_status aoclsparse_dcsr2bsr(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const double *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_int block_dim, double *bsr_val, aoclsparse_int *bsr_row_ptr, aoclsparse_int *bsr_col_ind)#
Convert a sparse CSR matrix into a sparse BSR matrix.
aoclsparse_?csr2bsrconverts a CSR matrix into a BSR matrix. It is assumed, thatbsr_val,bsr_col_indandbsr_row_ptrare allocated. Allocation size forbsr_row_ptris computed asmb+1wherembis the number of block rows in the BSR matrix. Allocation size forbsr_valandbsr_col_indis computed using this function which also fills inbsr_row_ptr. The index base is preserved during the conversion.- Parameters
m – [in] number of rows in the sparse CSR matrix.
n – [in] number of columns in the sparse CSR matrix.
descr – [in] descriptor of the input sparse CSR matrix. Only the base index is used in the conversion process, the remaining descriptor elements are ignored.
csr_val – [in] array of
nnzelements containing the values of the sparse CSR matrix.csr_row_ptr – [in] array of
m+1 elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array of
nnzelements containing the column indices of the sparse CSR matrix.block_dim – [in] size of the blocks in the sparse BSR matrix.
bsr_val – [out] array of
nnzb*block_dim*block_dimcontaining the values of the sparse BSR matrix.bsr_row_ptr – [out] array of
mb+1elements that point to the start of every block row of the sparse BSR matrix.bsr_col_ind – [out] array of
nnzbelements containing the block column indices of the sparse BSR matrix.
- Return values
aoclsparse_status_success – the operation completed successfully.
aoclsparse_status_invalid_size –
m, orn, orblock_dimis invalid.aoclsparse_status_invalid_pointer –
bsr_val,bsr_row_ptr,bsr_col_ind,csr_val,csr_row_ptrorcsr_col_indpointer is invalid.
aoclsparse_?csr2csc()#
-
aoclsparse_status aoclsparse_scsr2csc(aoclsparse_int m, aoclsparse_int n, aoclsparse_int nnz, const aoclsparse_mat_descr descr, aoclsparse_index_base baseCSC, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const float *csr_val, aoclsparse_int *csc_row_ind, aoclsparse_int *csc_col_ptr, float *csc_val)#
-
aoclsparse_status aoclsparse_dcsr2csc(aoclsparse_int m, aoclsparse_int n, aoclsparse_int nnz, const aoclsparse_mat_descr descr, aoclsparse_index_base baseCSC, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const double *csr_val, aoclsparse_int *csc_row_ind, aoclsparse_int *csc_col_ptr, double *csc_val)#
-
aoclsparse_status aoclsparse_ccsr2csc(aoclsparse_int m, aoclsparse_int n, aoclsparse_int nnz, const aoclsparse_mat_descr descr, aoclsparse_index_base baseCSC, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const aoclsparse_float_complex *csr_val, aoclsparse_int *csc_row_ind, aoclsparse_int *csc_col_ptr, aoclsparse_float_complex *csc_val)#
-
aoclsparse_status aoclsparse_zcsr2csc(aoclsparse_int m, aoclsparse_int n, aoclsparse_int nnz, const aoclsparse_mat_descr descr, aoclsparse_index_base baseCSC, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const aoclsparse_double_complex *csr_val, aoclsparse_int *csc_row_ind, aoclsparse_int *csc_col_ptr, aoclsparse_double_complex *csc_val)#
Convert a sparse CSR matrix into a sparse CSC matrix.
aoclsparse_?csr2cscconverts a CSR matrix into a CSC matrix. These functions can also be used to convert a CSC matrix into a CSR matrix. The index base can be modified during the conversion.Note
The resulting matrix can also be seen as the transpose of the input matrix.
- Parameters
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
nnz – [in] number of non-zero entries of the sparse CSR matrix.
descr – [in] descriptor of the input sparse CSR matrix. Only the base index is used in the conversion process, the remaining descriptor elements are ignored.
baseCSC – [in] the desired index base (zero or one) for the converted matrix.
csr_val – [in] array of
nnzelements of the sparse CSR matrix.csr_row_ptr – [in] array of
m+1 elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array of
nnzelements containing the column indices of the sparse CSR matrix.csc_val – [out] array of
nnzelements of the sparse CSC matrix.csc_row_ind – [out] array of
nnzelements containing the row indices of the sparse CSC matrix.csc_col_ptr – [out] array of
n+1 elements that point to the start of every column of the sparse CSC matrix. aoclsparse_csr2csc_buffer_size().
- Return values
aoclsparse_status_success – the operation completed successfully.
aoclsparse_status_invalid_size –
m,nornnzis invalid.aoclsparse_status_invalid_pointer –
csr_val,csr_row_ptr,csr_col_ind,csc_val,csc_row_ind,csc_col_ptris invalid.
aoclsparse_?csr2dense()#
-
aoclsparse_status aoclsparse_scsr2dense(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const float *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, float *A, aoclsparse_int ld, aoclsparse_order order)#
-
aoclsparse_status aoclsparse_dcsr2dense(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const double *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, double *A, aoclsparse_int ld, aoclsparse_order order)#
-
aoclsparse_status aoclsparse_ccsr2dense(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const aoclsparse_float_complex *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_float_complex *A, aoclsparse_int ld, aoclsparse_order order)#
-
aoclsparse_status aoclsparse_zcsr2dense(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const aoclsparse_double_complex *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_double_complex *A, aoclsparse_int ld, aoclsparse_order order)#
This function converts the sparse matrix in CSR format into a dense matrix.
- Parameters
m – [in] number of rows of the dense matrix
A.n – [in] number of columns of the dense matrix
A.descr – [in] the descriptor of the dense matrix
A, the supported matrix type is aoclsparse_matrix_type_general. Base index from the descriptor is used in the conversion process.csr_val – [in] array of size at least
nnznonzero elements of matrixA.csr_row_ptr – [in] CSR row pointer array of size (
m+1).csr_col_ind – [in] An array of CSR column indices of at least
nnzcolumn indices of the nonzero elements of matrixA.A – [out] array of dimensions (
lda,n)ld – [in] leading dimension of dense array
A.order – [in] memory layout of a dense matrix
A. It can be either aoclsparse_order_column or aoclsparse_order_row.
- Return values
aoclsparse_status_success – the operation completed successfully.
aoclsparse_status_invalid_size –
mornorldis invalid.aoclsparse_status_invalid_pointer –
A,csr_val,csr_row_ptr, orcsr_col_indpointers are invalid.
aoclsparse_convert_csr()#
-
aoclsparse_status aoclsparse_convert_csr(const aoclsparse_matrix src_mat, const aoclsparse_operation op, aoclsparse_matrix *dest_mat)#
Convert internal representation of matrix into a sparse CSR matrix.
aoclsparse_convert_csrconverts any supported matrix format into a CSR format matrix and returns it as a new aoclsparse_matrix. The new matrix can also be transposed, or conjugated and transposed during the conversion. It should be freed by calling aoclsparse_destroy(). The source matrix needs to be initalized using e.g. aoclsparse_create_scoo(), aoclsparse_create_scsr(), aoclsparse_create_scsc() or any of their variants.- Parameters
src_mat – [in] source matrix used for conversion.
op – [in] operation to be performed on destination matrix
dest_mat – [out] destination matrix output in CSR Format of the src_mat.
- Return values
aoclsparse_status_success – the operation completed successfully
aoclsparse_status_invalid_size – matrix dimension are invalid
aoclsparse_status_invalid_value –
src_matcontains invalid value typeaoclsparse_status_invalid_pointer – pointers in
src_matordest_matare invalidaoclsparse_status_not_implemented – conversion of the src_mat format given is not implemented
aoclsparse_status_memory_error – memory allocation for destination matrix failed