Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Handling of duplicates in COO matrices

Beginner
633 Views

Does Intel MKL sum up duplicates when converting COO matrices to CSR matrices via mkl_sparse_convert_csr? (This essential information is missing from the web documentation...)

1 Solution
Employee
615 Views

Hi,

Yes, mkl_sparse_convert_csr performs a sum reduction on duplicates.

This can be easily verified with a simple example:

``````#define M      2
#define N      2
#define NNZ    3
MKL_INT m = M, n=N, nnz=NNZ;

MKL_INT ia_coo[NNZ] = {0, 0, 1};
MKL_INT ja_coo[NNZ] = {0, 0, 0};
double a_coo[NNZ] = {1.0, 2.0, 3.0};
sparse_matrix_t Acoo;
sparse_status_t status_create = mkl_sparse_d_create_coo(&Acoo, 0, m, n, nnz, ia_coo, ja_coo, a_coo);
printf("Status create : %d\n", status_create);

sparse_matrix_t Acsr;
sparse_status_t status_convert = mkl_sparse_convert_csr (Acoo, SPARSE_OPERATION_NON_TRANSPOSE, &Acsr);
printf("Status convert : %d\n", status_convert);

sparse_index_base_t indexing;
MKL_INT *iab_csr, *iae_csr, *ja_csr;
double *a_csr;
sparse_status_t status_export = mkl_sparse_d_export_csr(Acsr, &indexing, &m, &n, &iab_csr, &iae_csr, &ja_csr, &a_csr);
printf("Status export : %d\n", status_export);

MKL_INT i, j;
printf("Matrix converted to CSR format:\n");
for (i=0; i<m; i++) {
MKL_INT jab=iab_csr[i]-indexing, jae=iae_csr[i]-indexing;
for (j=jab; j<jae; j++) {
MKL_INT col = ja_csr[j];
printf("  A[%lld, %lld] = %lf\n", i+indexing, col, a_csr[j]);
}
}``````

Hope this helps.

Best,
Nicolas

4 Replies
Employee
616 Views

Hi,

Yes, mkl_sparse_convert_csr performs a sum reduction on duplicates.

This can be easily verified with a simple example:

``````#define M      2
#define N      2
#define NNZ    3
MKL_INT m = M, n=N, nnz=NNZ;

MKL_INT ia_coo[NNZ] = {0, 0, 1};
MKL_INT ja_coo[NNZ] = {0, 0, 0};
double a_coo[NNZ] = {1.0, 2.0, 3.0};
sparse_matrix_t Acoo;
sparse_status_t status_create = mkl_sparse_d_create_coo(&Acoo, 0, m, n, nnz, ia_coo, ja_coo, a_coo);
printf("Status create : %d\n", status_create);

sparse_matrix_t Acsr;
sparse_status_t status_convert = mkl_sparse_convert_csr (Acoo, SPARSE_OPERATION_NON_TRANSPOSE, &Acsr);
printf("Status convert : %d\n", status_convert);

sparse_index_base_t indexing;
MKL_INT *iab_csr, *iae_csr, *ja_csr;
double *a_csr;
sparse_status_t status_export = mkl_sparse_d_export_csr(Acsr, &indexing, &m, &n, &iab_csr, &iae_csr, &ja_csr, &a_csr);
printf("Status export : %d\n", status_export);

MKL_INT i, j;
printf("Matrix converted to CSR format:\n");
for (i=0; i<m; i++) {
MKL_INT jab=iab_csr[i]-indexing, jae=iae_csr[i]-indexing;
for (j=jab; j<jae; j++) {
MKL_INT col = ja_csr[j];
printf("  A[%lld, %lld] = %lf\n", i+indexing, col, a_csr[j]);
}
}``````

Hope this helps.

Best,
Nicolas

Beginner
597 Views

Hi, thank you, much appreciated! I'm wondering if we can have the (web) documentation updated with this information so our reviewing/quality-control team can accept our pull-requests more easily. Best, Doriv4l.

Moderator
538 Views

Hi,

It’s great to know that the issue has been resolved, in case you run into any other issues please feel free to create a new thread

>>I'm wondering if we can have the (web) documentation updated with this information

Sure, We will inform the concerned team regarding the documentation update. Thank you for your valuable suggestions.

Best Regards,

Shanmukh.SS

Employee
534 Views

Hi Doriv4l,

Yes, great that your issue is resolved! I can confirm that the Developer Reference will be updated. It might take a while before the change is visible on the webpage though.

Thanks for the feedback, it's always appreciated.

Best regards,
Nicolas