MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / random_quaternions

Function random_quaternions

utils/general_util.py:434–452  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

432
433#from pytorch3d
434def 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

Callers 2

prepare_gt_batchFunction · 0.90
random_rotationsFunction · 0.85

Calls 1

_copysignFunction · 0.85

Tested by

no test coverage detected