Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7220 ディスカッション

Handling of duplicates in COO matrices

cpmech
ビギナー
1,311件の閲覧回数

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...)

0 件の賞賛
1 解決策
noffermans
従業員
1,293件の閲覧回数

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 返答(返信)
noffermans
従業員
1,294件の閲覧回数

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

cpmech
ビギナー
1,275件の閲覧回数

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.

ShanmukhS_Intel
モデレーター
1,216件の閲覧回数

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


noffermans
従業員
1,212件の閲覧回数

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

返信