Create Sparse Array without Copying

I have the row vector, column vector and the value vectors of a sparse matrix and would like to create a sparse matrix with them without copying the vectors because the vectors already take up 59% of my systems memory. Is this possible? Basically, I have indexI, indexJ, and val as regular arrays and would like something that accomplishes sparse(indexI, indexJ, val) without copying the vectors as that would require too much memory

Depending on what it is you need the sparse matrix for, there may be a solution that does not involve construction of the sparse matrix: simply work with the representation of the matrix provided by the three vectors.

Gotcha - yeah, I wanted the BLAS library functions for sparse vectors and matrices

Sorry, say again? BLAS is dense only AFAIK.

It may not be called BLAS in this particular case with sparse matrices and vectors, but the common linear algebra functions defined for matrices and vectors

If you are short on memory, you could try constructing the colptr (relatively small), rowval, and nzval vectors, then just using the inner constructor for SparseMatrixCSC. This does not copy.

See this explanation for the storage format:

https://docs.julialang.org/en/v1/stdlib/SparseArrays/#man-csc-1

2 Likes