torchdrivesim.utils =================== .. py:module:: torchdrivesim.utils .. autoapi-nested-parse:: Miscellaneous utilities, including for geometric operations on tensors. Attributes ---------- .. autoapisummary:: torchdrivesim.utils.Resolution Functions --------- .. autoapisummary:: torchdrivesim.utils.isin torchdrivesim.utils.normalize_angle torchdrivesim.utils.rotation_matrix torchdrivesim.utils.rotate torchdrivesim.utils.relative torchdrivesim.utils.is_inside_polygon torchdrivesim.utils.merge_dicts torchdrivesim.utils.assert_equal Module Contents --------------- .. py:data:: Resolution .. py:function:: isin(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor Checks whether elements of tensor x are contained in tensor y. This function is built-in in torch >= 1.10 and will be removed from here in the future. :param x: any tensor :param y: a one-dimensional tensor :returns: a boolean tensor with the same shape as x .. py:function:: normalize_angle(angle) Normalize to <-pi, pi) range by shifting by a multiple of 2*pi. Works with floats, numpy arrays, and torch tensors. .. py:function:: rotation_matrix(theta: torch.Tensor) -> torch.Tensor Counterclockwise rotation matrix in 2D. :param theta: tensor of shape Sx1 with rotation angle in radians :returns: Sx2x2 tensor with the rotation matrix. .. py:function:: rotate(v: torch.Tensor, angle: torch.Tensor) -> torch.Tensor Rotate the vector counterclockwise (from x towards y). Works correctly in batch mode. :param v: tensor of shape Sx2 representing points :param angle: tensor of shape Sx1 representing rotation angle :returns: Sx2 tensor of rotated points .. py:function:: relative(origin_xy: torch.Tensor, origin_psi: torch.Tensor, target_xy: torch.Tensor, target_psi: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor] Computes position and orientation of the target relative to origin. Points are represented as Sx2 tensors of coordinates and Sx1 tensors of orientations in radians. .. py:function:: is_inside_polygon(point: torch.Tensor, polygon: torch.Tensor) -> torch.Tensor Checks whether a given point is inside a given convex polygon. B and P can be zero or more batch dimensions, the former being batch and the latter points. :param point: BxPx2 tensor of x-y coordinates :param polygon: BxNx2 tensor of points specifying a convex polygon in either clockwise or counter-clockwise fashion. :returns: boolean tensor of shape BxP indicating whether the point is inside the polygon .. py:function:: merge_dicts(ds: List[Dict]) -> Dict Merges a sequence of dictionaries, giving preference to entries earlier in the sequence. .. py:function:: assert_equal(x, y)