get_mask_1d¶
- paddle.fluid.contrib.sparsity.utils. get_mask_1d ( mat, n, m ) [source]
-
Generate 1D n:m sparse pattern mask of the input matrix
mat
in row-directory. This function would pad the second dimension ofmat
by zero to be a multiples ofm
before mask generation.1D n:m sparse pattern: At least
n
zeros in every \(1 \times m\) block.- Parameters
-
mat (nparray) – The input matrix.
n (int) – n of n:m sparse pattern.
m (int) – m of n:m sparse pattern.
- Returns
-
The 1D n:m sparse mask of
mat
. - Return type
-
nparray
Examples
import numpy as np import paddle.fluid.contrib.sparsity as sparsity mat = np.array([[0, 1, 5, 4], [2, 7, 3, 6]]) mask = sparsity.get_mask_1d(mat, 2, 4) # nparray([[0, 0, 1, 1], # [0, 1, 0, 1]]) sparsity.check_mask_1d(mask, 2, 4) # True