def METHOD_NAME(masks, mask_creator, sparsity_val=None):
    # Check that every value in the mask_creator grouping
    # is the same within the mask.  Assumes grouping applies
    # an absolute mean to each grouping
    # also checks that the grouped mask matches the target sparsity exactly
    if sparsity_val is None:
        sparsity_val = [sparsity_val] * len(masks)
    for mask, target_sparsity in zip(masks, sparsity_val):
        grouped_mask = mask_creator.group_tensor(mask)
        grouped_mask /= max(torch.max(grouped_mask).item(), 1.0)
        mask_vals_are_grouped = torch.all((grouped_mask == 0.0) | (grouped_mask == 1.0))
        assert mask_vals_are_grouped
        if target_sparsity is not None:
            _test_num_masked(grouped_mask, target_sparsity)