Code Analyzer detects an indexing pattern for a sparse array that is likely to be slow. An assignment that changes the nonzero pattern of a sparse array can cause this error because such assignments result in considerable overhead.
If possible, build sparse arrays using sparse
as follows, and
do not use indexed assignments (such as C(4) = B
) to build
them:
Create separate index and value arrays.
Call sparse
to assemble the index and value
arrays.
If you must use indexed assignments to build sparse arrays, you can optimize
performance by first preallocating the sparse array with spalloc
.
If the code changes only array elements that are already nonzero, then the overhead is reasonable. Suppress this message as described in Adjust Code Analyzer Message Indicators and Messages.
For more information, see “Constructing Sparse Matrices”.