maxtrans¶
- sksparse.btf.maxtrans(A)[source]¶
Compute the maximum transversal of a sparse matrix.
This function finds a permutation of the columns of a sparse matrix so that it has a zero-free diagonal, if possible [1].
- Parameters:
A ((M, N) {array-like, sparse array}) – An array convertible to a sparse matrix in Compressed Sparse Column (CSC) format.
- Returns:
jmatch ((M,) ndarray) – Array containing the maximum transversal.
Adapted from the BTF maxtrans documentation [1]:
The output is an array
jmatchof sizeN. If rowiis matched with columnj, thenA[i, j]is nonzero, and thenjmatch[i] = j. If the matrix is structurally nonsingular, all entries in thejmatcharray are unique, andjmatchcan be viewed as a column permutation if A is square. That is, column k of the original matrix becomes columnjmatch[k]of the permuted matrix.If row
iis not matched with any column, thenjmatch[i] = -1.
Added in version 0.5.0.
References
Examples
>>> import numpy as np >>> from scipy.sparse import random_array >>> from sksparse.btf import maxtrans >>> # Create a non-symmetric matrix >>> N = 11 >>> rng = np.random.default_rng(56) >>> A = random_array((N, N - 3), density=0.5, format='csc', rng=rng) >>> jmatch = maxtrans(A) >>> jmatch array([ 0, 2, 1, 3, 4, 5, 7, -1, 6, -1, -1], dtype=int32)