def drop_nans(x, ind, validate_missing):
    """
    Remove nans, which we expect to find at missing indices.

    Args:
        x (`torch.Tensor`):
            Features
        ind (`torch.Tensor`):
            Binary values denoting whether or not a given feature is present.
        validate_missing (`bool`):
            Whether to validate that the missing location contains a nan.

    Returns:
        (`torch.tensor`):
            The features, with the missing values masked to zero.
    """
    missing = torch.nonzero(ind == 0).flatten()
    if missing.numel():
        if validate_missing:
            vals = x[missing[0]]
            assert vals.view(-1)[0], "expected nans at missing locations"
        x_ = x
        x_[missing] = 0
        x = x_
    return x
Remove nans, which we expect to find at missing indices.

Args:
x (`torch.Tensor`):
Features
ind (`torch.Tensor`):
Binary values denoting whether or not a given feature is present.
validate_missing (`bool`):
Whether to validate that the missing location contains a nan.

Returns:
(`torch.tensor`):
The features, with the missing values masked to zero.
towhee/models/collaborative_experts/collaborative_experts.py