Some of the methods calculating sparse matrices are allocating their outputs internally (e.g. clsparseScsrSpGemm) which makes sense, because it is not known in advance how many non-zero entries there will be.
Other methods need the user to allocate the output buffers ( e.g. Sdense2Csr). In this case the user has to know in advance how many non-zero entries there will be. However, internally Sdense2Csr counts non-zero entries to be able to allocate the intermediate CooMatrix anyway, so zeros are counted twice in the end.
-
Documentation should clearly state when the user has to allocate output buffers and when the library does
-
Methods calculating sparse outputs should either allocate internally after counting non-zero entries or trust the non-zero count passed by the user in the user allocated output matrix to speed up calculations.