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

Sparse conversion routines; convert in place ?

New Contributor III

I would like to convert from COO to CSR without making a new copy of my matrix. Is it OK to have actual arguments point to the same arrays, i.e. acsr and acoo are the same array and similar for the index arrays ? The help file does not specify.

0 Kudos
2 Replies
Black Belt

In general, unless the documentation says so explicitly, it is not safe to have aliased arguments passed to library subroutines. Furthermore, In Fortran there is a restriction on procedure arguments being aliased: Restrictions on entities associated with dummy arguments

    1 While an entity is associated with a dummy argument, the following restrictions hold.


       (3) Action that affects the value of the entity or any subobject of it shall be taken only through the dummy argument

The compiler may not be able to detect if your code violates this requirement, and it is hard to catch associated bugs at run time.

In the case that you mentioned, the COO representation contains two index arrays of size Nnz, whereas the CSR representation contains an index array of size Nnz and a row-pointer array of size N+1, so one output array does not match any corresponding input array in size.

Why take the risk? If the arrays are dynamically allocated, it is easy enough to discard the COO arrays once the conversion is completed, or to reuse the allocated memory for some other useful purpose.

0 Kudos

Hi Andrew, 

Right, as micej  noted that the aliasing pointers is not supported unless explicitly mentioned in the documentation.



0 Kudos