Mathematics |
Standard Mathematical Operations
Sparse matrices propagate through computations according to these rules:
size
function always returns a full vector, whether its input is full or sparse.
such as zeros
, ones
, rand
,
and eye
,
always return full results. This is necessary to avoid introducing sparsity unexpectedly. The sparse analog of zeros(m,n)
is simply sparse(m,n)
.
The sparse analogs of rand
and eye
are sprand
and speye
, respectively. There is no sparse analog for the function ones
.
S
is a sparse matrix, then chol(S)
is also a sparse matrix, and diag(S)
is a sparse vector. Columnwise functions such as max
and sum
also return sparse vectors, even though these vectors may be entirely nonzero. Important exceptions to this rule are the sparse
and full
functions.
S
is sparse and F
is full, then S+F
, S*F
, and F\S
are full, while S.*F
and S&F
are sparse. In some cases, the result might be sparse even though the matrix has few zero elements.
cat
function or square brackets produces sparse results for mixed operands.
T = S(i,j)
produces a sparse result if S
is sparse and either i
or j
is a vector. It produces a full scalar if both i
and j
are scalars. Submatrix indexing on the left, as in T(i,j) = S
, does not change the storage format of the matrix on the left.
Computational Considerations | Permutation and Reordering |