torchdrivesim.utils
#
Miscellaneous utilities, including for geometric operations on tensors.
Module Contents#
Functions#
|
Checks whether elements of tensor x are contained in tensor y. |
|
Normalize to <-pi, pi) range by shifting by a multiple of 2*pi. |
|
Counterclockwise rotation matrix in 2D. |
|
Rotate the vector counterclockwise (from x towards y). |
|
Computes position and orientation of the target relative to origin. |
|
Checks whether a given point is inside a given convex polygon. |
|
Merges a sequence of dictionaries, giving preference to entries earlier in the sequence. |
|
Attributes#
- torchdrivesim.utils.isin(x: torch.Tensor, y: torch.Tensor) torch.Tensor [source]#
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.
- Parameters:
x – any tensor
y – a one-dimensional tensor
- Returns:
a boolean tensor with the same shape as x
- torchdrivesim.utils.normalize_angle(angle)[source]#
Normalize to <-pi, pi) range by shifting by a multiple of 2*pi. Works with floats, numpy arrays, and torch tensors.
- torchdrivesim.utils.rotation_matrix(theta: torch.Tensor) torch.Tensor [source]#
Counterclockwise rotation matrix in 2D.
- Parameters:
theta – tensor of shape Sx1 with rotation angle in radians
- Returns:
Sx2x2 tensor with the rotation matrix.
- torchdrivesim.utils.rotate(v: torch.Tensor, angle: torch.Tensor) torch.Tensor [source]#
Rotate the vector counterclockwise (from x towards y). Works correctly in batch mode.
- Parameters:
v – tensor of shape Sx2 representing points
angle – tensor of shape Sx1 representing rotation angle
- Returns:
Sx2 tensor of rotated points
- torchdrivesim.utils.relative(origin_xy: torch.Tensor, origin_psi: torch.Tensor, target_xy: torch.Tensor, target_psi: torch.Tensor) Tuple[torch.Tensor, torch.Tensor] [source]#
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.
- torchdrivesim.utils.is_inside_polygon(point: torch.Tensor, polygon: torch.Tensor) torch.Tensor [source]#
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.
- Parameters:
point – BxPx2 tensor of x-y coordinates
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