code: def euler_angles_to_matrix(
      euler_angles: torch.Tensor, convention: str
  ) -> torch.Tensor:
      """
      Convert rotations given as Euler angles in radians to rotation matrices.
  
      Args:
          euler_angles: Euler angles in radians as tensor of shape (..., 3).
          convention: Convention string of three uppercase letters from
              {"X", "Y", and "Z"}.
  
      Returns:
          Rotation matrices as tensor of shape (..., 3, 3).
      """
      if euler_angles.dim() == 0 or euler_angles.shape[-1] != 3:
          raise ValueError("Invalid input euler angles.")
      if len(convention) != 3:
          raise ValueError("Convention must have 3 letters.")
      if convention[1] in (convention[0], convention[2]):
          raise ValueError(f"Invalid convention {convention}.")
      for letter in convention:
          if letter not in ("X", "Y", "Z"):
              raise ValueError(
                  f"Invalid letter {letter} in convention string."
              )
      matrices = [
          _axis_angle_rotation(c, e)
          for c, e in zip(convention, torch.unbind(euler_angles, -1))
      ]
      # return functools.reduce(torch.matmul, matrices)
      return torch.matmul(
          torch.matmul(matrices[0], matrices[1]), matrices[2]
      )
  
imports: from typing import Optional
  import torch
  import torch.nn.functional
  from ..common.datatypes import Device
label_desc: Use image node_id 6 for calling a global function with example usage: euler_angles_to_matrix(euler_angles, convention) and returns: torch