import torch


def to_bitmask(M):
  """
  Returns the bitmask sparse format of matrix 'M'

  :param M: original weight matrix M
  """

  wmb = (M != 0).float()
  data = M[torch.nonzero(M, as_tuple=True)]

  return wmb, data