I wish to create m = 10^5 sparse matrices of size n by n, say n = 10^4. I have been using
A = cell(m, 1);for i = 1:m row = ...; col = ...; val = ...; % here ... means some certain assignment in column vectors A{i} = sparse(row, col, val, n, n);end
But it is too slow. So I tried to use the types ndSparse (https://www.mathworks.com/matlabcentral/fileexchange/29832-n-dimensional-sparse-arrays) and sptensor (https://www.sandia.gov/~tgkolda/TensorToolbox/index-2.6.html). They do the job fast by creating m matrices all at once in 3d (n*n*m). It requires concatenating index and value vectors, where the speed is acceptable. However, I then need individual matrices for some operations that do NOT work on types ndSparse and sptensor. For example,
[R, p] = chol(A(:, :, i));
does not work. If I convert the object to Matlab sparse type as
[R, p] = chol(sparse(A(:, :, i)));
then it is even slower than creating A one by one in the for loop. Considering that Matlab does not support multidimensional sparse arrays (so I cannot reshape the abovementioned types into Matlab sparse tensor), how can I speed up creating m sparse matrices? Thank you!
Best Answer