Skip to content

fix(torch-transform): inverse_transform computes wrong (+1 more) - #55

Draft
andrewwhitecdw wants to merge 1 commit into
NVlabs:mainfrom
andrewwhitecdw:bugfix/torch-transform-assorted-d51d5445
Draft

fix(torch-transform): inverse_transform computes wrong (+1 more)#55
andrewwhitecdw wants to merge 1 commit into
NVlabs:mainfrom
andrewwhitecdw:bugfix/torch-transform-assorted-d51d5445

Conversation

@andrewwhitecdw

@andrewwhitecdw andrewwhitecdw commented Jul 27, 2026

Copy link
Copy Markdown

Small fixes in lib/utils/torch_transform.py:

fix: inverse_transform computes wrong inverse translation

Fix: Replace:

    transform_inv[..., :3, 3] = -torch.matmul(transform_mat[..., :3, 3].unsqueeze(-2), transform_mat[..., :3, :3]).squeeze(-2)

with:

    transform_inv[..., :3, 3] = -torch.matmul(transform_mat[..., :3, :3].transpose(-2, -1), transform_mat[..., :3, 3].unsqueeze(-1)).squeeze(-1)

fix: quaternion helper uses hard-coded float64 dtype

Fix: Replace:

    out[sind] = torch.tensor([1., 0., 0., 0.], device=v1.device)
    # handle v1 & v2 with opposite direction
    nind = dot < -1 + eps
    if torch.any(nind):
        vx = torch.tensor([1., 0., 0.], device=v1.device)
        vxdot = (v1 * vx).sum(-1).abs()
        nxind = nind & (vxdot < 1 - eps)
        if torch.any(nxind):
            out[nxind] = angle_axis_to_quaternion(normalize(torch.cross(vx.expand_as(v1[nxind]), v1[nxind], dim=-1)) * np.pi)
        # handle v1 & v2 with opposite direction and they are parallel to x axis
        pind = nind & (vxdot >= 1 - eps)
        if torch.any(pind):
            vy = torch.tensor([0., 1., 0.], device=v1.device)
            out[pind] = angle_axis_to_quaternion(normalize(torch.cross(vy.expand_as(v1[pind]), v1[pind], dim=-1)) * np.pi)

with:

    out[sind] = torch.tensor([1., 0., 0., 0.], device=v1.device, dtype=v1.dtype)
    # handle v1 & v2 with opposite direction
    nind = dot < -1 + eps
    if torch.any(nind):
        vx = torch.tensor([1., 0., 0.], device=v1.device, dtype=v1.dtype)
        vxdot = (v1 * vx).sum(-1).abs()
        nxind = nind & (vxdot < 1 - eps)
        if torch.any(nxind):
            out[nxind] = angle_axis_to_quaternion(normalize(torch.cross(vx.expand_as(v1[nxind]), v1[nxind], dim=-1)) * np.pi)
        # handle v1 & v2 with opposite direction and they are parallel to x axis
        pind = nind & (vxdot >= 1 - eps)
        if torch.any(pind):
            vy = torch.tensor([0., 1., 0.], device=v1.device, dtype=v1.dtype)
            out[pind] = angle_axis_to_quaternion(normalize(torch.cross(vy.expand_as(v1[pind]), v1[pind], dim=-1)) * np.pi)

Files changed

  • lib/utils/torch_transform.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant