nnrl/nn/distributions/flows/masks.py
def create_random_binary_mask(features):
    """
    Creates a random binary mask of a given dimension with half of its entries
    randomly set to 1s.
    :param features: Dimension of mask.
    :return: Binary mask with half of its entries set to 1s, of type torch.Tensor.
    """
    mask = torch.zeros(features).byte()
    weights = torch.ones(features).float()
    num_samples = features // 2 if features % 2 == 0 else features // 2 + 1
    indices = torch.multinomial(
        input=weights, num_samples=num_samples, replacement=False
    )
    mask[indices] += 1
    return mask

    Creates a random binary mask of a given dimension with half of its entries
    randomly set to 1s.
    :param features: Dimension of mask.
    :return: Binary mask with half of its entries set to 1s, of type torch.Tensor.
    
Creates a random binary mask of a given dimension with half of its entries
randomly set to 1s.
Creates a random binary mask of a given dimension with half of its entries randomly set to 1s .
def create_random_binary_mask(features):
    mask = torch.zeros(features).byte()
    weights = torch.ones(features).float()
    num_samples = features // 2 if features % 2 == 0 else features // 2 + 1
    indices = torch.multinomial(
        input=weights, num_samples=num_samples, replacement=False
    )
    mask[indices] += 1
    return mask
def create_random_binary_mask ( features ) : mask = torch . zeros ( features ) . byte ( ) weights = torch . ones ( features ) . float ( ) num_samples = features // 2 if features % 2 == 0 else features // 2 + 1 indices = torch . multinomial ( input = weights , num_samples = num_samples , replacement = False ) mask [ indices ] += 1 return mask
Creates a random binary mask of a given dimension with half of its entries
randomly set to 1s.
Creates a random binary mask of a given dimension with half of its entries randomly set to 1s .
"""
    Creates a random binary mask of a given dimension with half of its entries
    randomly set to 1s.
    :param features: Dimension of mask.
    :return: Binary mask with half of its entries set to 1s, of type torch.Tensor.
    """
Binary mask with half of its entries set to 1s, of type torch.Tensor.
Binary mask with half of its entries set to 1s of type torch . Tensor .
features
Dimension of mask.
Dimension of mask .