import torch


def sampling_and_group_layer_all(xyz, points=None):
    """
    Group layer (all)

    Parameters
    ----------
    xyz : torch.tensor [B, 3, N]
        xyz tensor
    points : torch.tensor [B, D, N]
        Concatenate points to return value (new_points).

    Returns
    -------
    new_xyz : torch.tensor [B, 3, 1]
        new xyz
    new_points : torch.tensor [B, 3, 1, N] or [B, 3+D, 1, N]
        If points is not None, new_points shape is [B, 3+D, 1, N].
    """
    device = xyz.device
    B, C, N = xyz.shape
    new_xyz = torch.zeros(B, C, 1).to(device)
    grouped_xyz = xyz.view(B, C, 1, N)
    if points is not None:
        new_points = torch.cat([grouped_xyz, points.view(B, -1, 1, N)], dim=1)
    else:
        new_points = grouped_xyz
    return new_xyz, new_points