Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor II
18 Views

Sparse conversion routines; convert in place ?

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
18 Views

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:

12.5.2.13 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
Highlighted
Employee
18 Views

Hi Andrew, 

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

Regards,

Ying

0 Kudos