Generate random quaternions representing rotations, i.e. versors with nonnegative real part. Args: n: Number of quaternions in a batch to return. dtype: Type to return. device: Desired device of returned tensor. Default: uses the current device for t
(
n: int, dtype: Optional[torch.dtype] = None)
| 432 | |
| 433 | #from pytorch3d |
| 434 | def random_quaternions( |
| 435 | n: int, dtype: Optional[torch.dtype] = None) -> torch.Tensor: |
| 436 | """ |
| 437 | Generate random quaternions representing rotations, |
| 438 | i.e. versors with nonnegative real part. |
| 439 | |
| 440 | Args: |
| 441 | n: Number of quaternions in a batch to return. |
| 442 | dtype: Type to return. |
| 443 | device: Desired device of returned tensor. Default: |
| 444 | uses the current device for the default tensor type. |
| 445 | |
| 446 | Returns: |
| 447 | Quaternions as tensor of shape (N, 4). |
| 448 | """ |
| 449 | o = torch.randn((n, 4), dtype=dtype, device=torch.device("cuda")) |
| 450 | s = (o * o).sum(1) |
| 451 | o = o / _copysign(torch.sqrt(s), o[:, 0])[:, None] |
| 452 | return o |
| 453 | |
| 454 | |
| 455 |
no test coverage detected