colperm
Column permutation that orders the columns by their number of nonzeros.
Category: Mathematics > Sparse Matrices
Syntax
p = colperm(S)
Returns a permutation vector p so that S(:,p) has columns with nondecreasing nonzero counts.
Description
The ordering is a cheap heuristic: columns with few nonzeros come first. Applied before an LU or QR factorization it sometimes reduces fill-in, the new nonzeros created during the factorization. Ties keep their original order.
It is much simpler than symrcm or an approximate minimum degree ordering, which usually give better results.
Input arguments
S- Sparse or full matrix.
Output arguments
p- Permutation vector of length
size(S,2).
Example
Sorting columns by density
S = sparse([1 1 1; 0 1 0; 0 1 1]);
p = colperm(S)
full(S(:, p))
Output
p = 1×3
1 3 2
ans = 3×3
1 1 1
0 0 1
0 1 1