import torch


def rotate_cart_vec(R, vec, autoconvert=True):
    """ Rotate a Cartesian vector by a Euler rotation matrix. """
    if autoconvert:
        R = R.to(vec.device, vec.dtype)
    return torch.matmul(vec, R)