Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions kornia/geometry/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,16 @@ def inverse_transformation(trans_12: Tensor) -> Tensor:

if not ((trans_12.dim() in (2, 3)) and (trans_12.shape[-2:] == (4, 4))):
raise ValueError(f"Input size must be a Nx4x4 or 4x4. Got {trans_12.shape}")
# unpack input tensor
rmat_12 = trans_12[..., :3, 0:3] # Nx3x3
tvec_12 = trans_12[..., :3, 3:4] # Nx3x1

# compute the actual inverse
rmat_21 = torch.transpose(rmat_12, -1, -2)
tvec_21 = torch.matmul(-rmat_21, tvec_12)
# Optimized unpacking and computation using more in-place operations
rmat_21 = trans_12[..., :3, 0:3].transpose(-1, -2) # In-place transpose
tvec_21 = -torch.matmul(rmat_21, trans_12[..., :3, 3:4]) # Combine operations

# pack to output tensor
# Pack to output tensor more efficiently
trans_21 = zeros_like(trans_12)
trans_21[..., :3, 0:3] += rmat_21
trans_21[..., :3, -1:] += tvec_21
trans_21[..., -1, -1:] += 1.0
trans_21[..., :3, :3] = rmat_21
trans_21[..., :3, 3:4] = tvec_21
trans_21[..., 3, 3] = 1.0
return trans_21


Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,11 @@ ignore_errors = true

[tool.pydocstyle]
match = '.*\.py'

[tool.codeflash]
# All paths are relative to this pyproject.toml's directory.
module-root = "kornia"
tests-root = "tests"
test-framework = "pytest"
ignore-paths = []
formatter-cmds = ["ruff check --exit-zero --fix $file", "ruff format $file"]
Loading