Generate 2D n:m sparse pattern mask of the input matrix mat to form sparse matrix with maximun L1 norm .This function would pad each dimension of mat by zero to be a multiples of m before mask generation.

2D n:m sparse pattern: At least $$n \times n$$ zeros in every $$m \times m$$ block under the constraint of at least n zeros for each row and column.

Note: L1 norm of sparse matrix from Best API is greater than or equal to the one from Greedy.

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
print("L1 norm of greedy sparse matrix", np.multiply(mat, mask_greedy).sum()) # 56
print("L1 norm of best sparse matrix", np.multiply(mat, mask_best).sum()) # 61