import torch


def nd_dropout(dim: int, p: float = 0.5, inplace: bool = False, **kwargs) -> torch.nn.Module:
    """
    Generate 1,2,3 dimensional dropout

    Args:
        dim (int): number of dimensions
        p (float): doupout probability
        inplace (bool): apply operation inplace
        **kwargs: passed to dropout

    Returns:
        torch.nn.Module: generated module
    """
    dropout_cls = getattr(torch.nn, "Dropout%dd" % dim)
    return dropout_cls(p=p, inplace=inplace, **kwargs)