Spaces:
Running on Zero
Running on Zero
Download lingbot_map2/utils/rotation.py from hugging-apps/lingbot-map-v2-streaming: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/hugging-apps/lingbot-map-v2-streaming/resolve/main/lingbot_map2/utils/rotation.py
- Command line
-
hf download hf://spaces/hugging-apps/lingbot-map-v2-streaming/lingbot_map2/utils/rotation.py
-
curl -L -o rotation.py https://huggingface.co/spaces/hugging-apps/lingbot-map-v2-streaming/resolve/main/lingbot_map2/utils/rotation.py
1.15 kB
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |
| # All rights reserved. See LICENSE.txt and LICENSES/THIRD_PARTY.md. | |
| import torch | |
| def quat_to_mat(quaternions: torch.Tensor) -> torch.Tensor: | |
| """ | |
| Quaternion Order: XYZW or say ijkr, scalar-last | |
| Convert rotations given as quaternions to rotation matrices. | |
| Args: | |
| quaternions: quaternions with real part last, | |
| as tensor of shape (..., 4). | |
| Returns: | |
| Rotation matrices as tensor of shape (..., 3, 3). | |
| """ | |
| i, j, k, r = torch.unbind(quaternions, -1) | |
| # pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`. | |
| two_s = 2.0 / (quaternions * quaternions).sum(-1) | |
| o = torch.stack( | |
| ( | |
| 1 - two_s * (j * j + k * k), | |
| two_s * (i * j - k * r), | |
| two_s * (i * k + j * r), | |
| two_s * (i * j + k * r), | |
| 1 - two_s * (i * i + k * k), | |
| two_s * (j * k - i * r), | |
| two_s * (i * k - j * r), | |
| two_s * (j * k + i * r), | |
| 1 - two_s * (i * i + j * j), | |
| ), | |
| -1, | |
| ) | |
| return o.reshape(quaternions.shape[:-1] + (3, 3)) | |