import torch


def apply_mask(loss: torch.Tensor, mask: torch.Tensor) -> torch.Tensor:
    """
    Masking training loss by a boolean tensor to drop parts of training loss.
    
    Args:
        loss (T), shape = (B, None), data_type = torch.float: training loss
        mask (T), shape = (B, ), data_type = torch.bool: boolean tensor for masking
    
    Returns:
        T, shape = (1, ), data_type = torch.float: aggregated masked loss.
    """
    loss = loss[mask]
    return loss.sum() / mask.sum()