btf_q_permutation¶
- sksparse.btf.btf_q_permutation(q)[source]¶
Convert a raw BTF column permutation vector to a valid permutation.
- Parameters:
q ((N,) ndarray of int) – The raw BTF column permutation vector. Contains negative entries for unmatched columns.
- Returns:
q_perm ((N,) ndarray of int) – The valid BTF column permutation vector. Contains only non-negative entries, where unmatched columns are replaced with their shifted absolute values.
Notes
In C, the values of
qare converted usingj = BTF_UNFLIP(Q[k]), which is a macro for:j = (Q[k] < 0) ? -Q[k] - 2 : Q[k]
This function is a Python equivalent of that macro.
Added in version 0.5.0.
Examples
>>> import numpy as np >>> from sksparse.btf import btf_q_permutation >>> q = np.array([0, 1, 2, -5, 10, 6, 5, 7, 8, 4, 9], dtype=np.int32) >>> btf_q_permutation(q) array([ 0, 1, 2, 3, 10, 6, 5, 7, 8, 4, 9], dtype=int32)