| 181 | |
| 182 | |
| 183 | class Frame: |
| 184 | |
| 185 | def __init__( |
| 186 | self, |
| 187 | rotation: Optional[Rotation], |
| 188 | translation: Optional[torch.Tensor], |
| 189 | ): |
| 190 | if rotation is None and translation is None: |
| 191 | rotation = Rotation.identity((0, )) |
| 192 | translation = zero_translation((0, )) |
| 193 | elif translation is None: |
| 194 | translation = zero_translation(rotation.shape, rotation.dtype, |
| 195 | rotation.device, |
| 196 | rotation.requires_grad) |
| 197 | |
| 198 | elif rotation is None: |
| 199 | rotation = Rotation.identity( |
| 200 | translation.shape[:-1], |
| 201 | translation.dtype, |
| 202 | translation.device, |
| 203 | translation.requires_grad, |
| 204 | ) |
| 205 | |
| 206 | if (rotation.shape != translation.shape[:-1]) or (rotation.device |
| 207 | != # noqa W504 |
| 208 | translation.device): |
| 209 | raise ValueError('RotationMatrix and translation incompatible') |
| 210 | |
| 211 | self._r = rotation |
| 212 | self._t = translation |
| 213 | |
| 214 | @staticmethod |
| 215 | def identity( |
| 216 | shape: Iterable[int], |
| 217 | dtype: Optional[torch.dtype] = torch.float, |
| 218 | device: Optional[torch.device] = torch.device('cpu'), |
| 219 | requires_grad: bool = False, |
| 220 | ) -> Frame: |
| 221 | return Frame( |
| 222 | Rotation.identity(shape, dtype, device, requires_grad), |
| 223 | zero_translation(shape, dtype, device, requires_grad), |
| 224 | ) |
| 225 | |
| 226 | def __getitem__( |
| 227 | self, |
| 228 | index: Any, |
| 229 | ) -> Frame: |
| 230 | if type(index) != tuple: |
| 231 | index = (index, ) |
| 232 | |
| 233 | return Frame( |
| 234 | self._r[index], |
| 235 | self._t[index + (slice(None), )], |
| 236 | ) |
| 237 | |
| 238 | def __mul__( |
| 239 | self, |
| 240 | right: torch.Tensor, |
no outgoing calls
no test coverage detected
searching dependent graphs…