from typing import Sequence
import torch


def affine_transformation_translation(t: Sequence[float]) -> torch.Tensor:
    """
    Defines an affine translation for 2D or 3D data

    For a 3D transformation, returns a 4x4 matrix:

           | 1 0 0 X |
       M = | 0 1 0 Y |
           | 0 0 1 Z |
           | 0 0 0 1 |
    Args:
        t: a (X, Y, Z) or (X, Y) tuple

    Returns:
        a transformation matrix
    """
    d = len(t)
    assert d == 2 or d == 3
    tfm = torch.eye(d + 1, dtype=torch.float32)
    tfm[0:d, d] = torch.FloatTensor(t)
    return tfm