Skip to content

Commit

Permalink
geometric transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
0x00b1 committed Apr 29, 2024
1 parent 3e4ffd0 commit 3fd05b8
Show file tree
Hide file tree
Showing 90 changed files with 4,945 additions and 3 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ jobs:
with:
name: "python-package-distributions"
path: "dist/"
pytest:
strategy:
matrix:
platform:
- "macos-latest"
- "ubuntu-latest"
- "windows-latest"
python:
- "3.10"
- "3.11"
runs-on: ${{ matrix.platform }}
steps:
- uses: "actions/checkout@v4"
- uses: "actions/setup-python@v5"
with:
python-version: ${{ matrix.python }}
- run: "python -m pip install --editable '.[test]'"
- run: "python -m pytest"
- env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: "codecov/codecov-action@v3"
pypi:
environment:
name: "pypi.org"
Expand Down Expand Up @@ -58,7 +79,7 @@ jobs:
- uses: "chartboost/ruff-action@v1"
with:
args: "format --check"
test-pypi:
testpypi:
environment:
name: "test.pypi.org"
url: "https://test.pypi.org/project/beignet"
Expand Down
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- hooks:
- id: "check-toml"
- id: "check-yaml"
repo: "https://github.com/pre-commit/pre-commit-hooks"
rev: "v4.5.0"
- hooks:
- args:
- "--fix"
id: "ruff"
- id: "ruff-format"
repo: "https://github.com/astral-sh/ruff-pre-commit"
rev: "v0.3.5"
11 changes: 11 additions & 0 deletions docs/beignet.ops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# beignet.ops

## Geometry

### Transformations

#### Rotations

#### Translations

## Interpolation
23 changes: 21 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,33 @@ requires = [

[project]
authors = [{ email = "[email protected]", name = "Allen Goodman" }]
dependencies = ["torch"]
dynamic = ["version"]
license = { file = "LICENSE" }
name = "beignet"
readme = "README.md"
requires-python = ">=3.10"

[tool.ruff.format]
docstring-code-format = true
[project.optional-dependencies]
test = [
"hypothesis",
"pytest",
"scipy",
]

[tool.ruff]
select = [
"B", # FLAKE8-BUGBEAR
"E", # PYCODESTYLE ERRORS
"F", # PYFLAKES
"I", # ISORT
"W", # PYCODESTYLE WARNINGS
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = [
"F401", # MODULE IMPORTED BUT UNUSED
]

[tool.setuptools_scm]
local_scheme = "no-local-version"
89 changes: 89 additions & 0 deletions src/beignet/ops/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from ._geometry import (
apply_euler_angle,
apply_quaternion,
apply_rotation_matrix,
apply_rotation_vector,
compose_euler_angle,
compose_quaternion,
compose_rotation_matrix,
compose_rotation_vector,
euler_angle_identity,
euler_angle_magnitude,
euler_angle_mean,
euler_angle_to_quaternion,
euler_angle_to_rotation_matrix,
euler_angle_to_rotation_vector,
invert_euler_angle,
invert_quaternion,
invert_rotation_matrix,
invert_rotation_vector,
quaternion_identity,
quaternion_magnitude,
quaternion_mean,
quaternion_slerp,
quaternion_to_euler_angle,
quaternion_to_rotation_matrix,
quaternion_to_rotation_vector,
random_euler_angle,
random_quaternion,
random_rotation_matrix,
random_rotation_vector,
rotation_matrix_identity,
rotation_matrix_magnitude,
rotation_matrix_mean,
rotation_matrix_to_euler_angle,
rotation_matrix_to_quaternion,
rotation_matrix_to_rotation_vector,
rotation_vector_identity,
rotation_vector_magnitude,
rotation_vector_mean,
rotation_vector_to_euler_angle,
rotation_vector_to_quaternion,
rotation_vector_to_rotation_matrix,
translation_identity,
)

__all__ = [
"apply_euler_angle",
"apply_quaternion",
"apply_rotation_matrix",
"apply_rotation_vector",
"compose_euler_angle",
"compose_quaternion",
"compose_rotation_matrix",
"compose_rotation_vector",
"euler_angle_identity",
"euler_angle_magnitude",
"euler_angle_mean",
"euler_angle_to_quaternion",
"euler_angle_to_rotation_matrix",
"euler_angle_to_rotation_vector",
"invert_euler_angle",
"invert_quaternion",
"invert_rotation_matrix",
"invert_rotation_vector",
"quaternion_identity",
"quaternion_magnitude",
"quaternion_mean",
"quaternion_to_euler_angle",
"quaternion_to_rotation_matrix",
"quaternion_to_rotation_vector",
"random_euler_angle",
"random_quaternion",
"random_rotation_matrix",
"random_rotation_vector",
"rotation_matrix_identity",
"rotation_matrix_magnitude",
"rotation_matrix_mean",
"rotation_matrix_to_euler_angle",
"rotation_matrix_to_quaternion",
"rotation_matrix_to_rotation_vector",
"rotation_vector_identity",
"rotation_vector_magnitude",
"rotation_vector_mean",
"rotation_vector_to_euler_angle",
"rotation_vector_to_quaternion",
"rotation_vector_to_rotation_matrix",
"quaternion_slerp",
"translation_identity",
]
44 changes: 44 additions & 0 deletions src/beignet/ops/_geometry/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from ._transformations import (
apply_euler_angle,
apply_quaternion,
apply_rotation_matrix,
apply_rotation_vector,
compose_euler_angle,
compose_quaternion,
compose_rotation_matrix,
compose_rotation_vector,
euler_angle_identity,
euler_angle_magnitude,
euler_angle_mean,
euler_angle_to_quaternion,
euler_angle_to_rotation_matrix,
euler_angle_to_rotation_vector,
invert_euler_angle,
invert_quaternion,
invert_rotation_matrix,
invert_rotation_vector,
quaternion_identity,
quaternion_magnitude,
quaternion_mean,
quaternion_slerp,
quaternion_to_euler_angle,
quaternion_to_rotation_matrix,
quaternion_to_rotation_vector,
random_euler_angle,
random_quaternion,
random_rotation_matrix,
random_rotation_vector,
rotation_matrix_identity,
rotation_matrix_magnitude,
rotation_matrix_mean,
rotation_matrix_to_euler_angle,
rotation_matrix_to_quaternion,
rotation_matrix_to_rotation_vector,
rotation_vector_identity,
rotation_vector_magnitude,
rotation_vector_mean,
rotation_vector_to_euler_angle,
rotation_vector_to_quaternion,
rotation_vector_to_rotation_matrix,
translation_identity,
)
60 changes: 60 additions & 0 deletions src/beignet/ops/_geometry/_transformations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from ._apply_euler_angle import apply_euler_angle
from ._apply_quaternion import (
apply_quaternion,
)
from ._apply_rotation_matrix import apply_rotation_matrix
from ._apply_rotation_vector import apply_rotation_vector
from ._compose_euler_angle import compose_euler_angle
from ._compose_quaternion import compose_quaternion
from ._compose_rotation_matrix import compose_rotation_matrix
from ._compose_rotation_vector import compose_rotation_vector
from ._euler_angle_identity import euler_angle_identity
from ._euler_angle_magnitude import euler_angle_magnitude
from ._euler_angle_mean import euler_angle_mean
from ._euler_angle_to_quaternion import (
euler_angle_to_quaternion,
)
from ._euler_angle_to_rotation_matrix import euler_angle_to_rotation_matrix
from ._euler_angle_to_rotation_vector import euler_angle_to_rotation_vector
from ._invert_euler_angle import invert_euler_angle
from ._invert_quaternion import invert_quaternion
from ._invert_rotation_matrix import invert_rotation_matrix
from ._invert_rotation_vector import invert_rotation_vector
from ._quaternion_identity import quaternion_identity
from ._quaternion_magnitude import quaternion_magnitude
from ._quaternion_mean import quaternion_mean
from ._quaternion_slerp import quaternion_slerp
from ._quaternion_to_euler_angle import (
quaternion_to_euler_angle,
)
from ._quaternion_to_rotation_matrix import (
quaternion_to_rotation_matrix,
)
from ._quaternion_to_rotation_vector import (
quaternion_to_rotation_vector,
)
from ._random_euler_angle import random_euler_angle
from ._random_quaternion import random_quaternion
from ._random_rotation_matrix import random_rotation_matrix
from ._random_rotation_vector import random_rotation_vector
from ._rotation_matrix_identity import rotation_matrix_identity
from ._rotation_matrix_magnitude import rotation_matrix_magnitude
from ._rotation_matrix_mean import rotation_matrix_mean
from ._rotation_matrix_to_euler_angle import rotation_matrix_to_euler_angle
from ._rotation_matrix_to_quaternion import (
rotation_matrix_to_quaternion,
)
from ._rotation_matrix_to_rotation_vector import (
rotation_matrix_to_rotation_vector,
)
from ._rotation_vector_identity import rotation_vector_identity
from ._rotation_vector_magnitude import rotation_vector_magnitude
from ._rotation_vector_mean import rotation_vector_mean
from ._rotation_vector_to_euler_angle import rotation_vector_to_euler_angle
from ._rotation_vector_to_quaternion import (
rotation_vector_to_quaternion,
)
from ._rotation_vector_to_rotation_matrix import (
rotation_vector_to_rotation_matrix,
)
from ._translation_identity import translation_identity
63 changes: 63 additions & 0 deletions src/beignet/ops/_geometry/_transformations/_apply_euler_angle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from torch import Tensor

from ._apply_rotation_matrix import apply_rotation_matrix
from ._euler_angle_to_rotation_matrix import euler_angle_to_rotation_matrix


def apply_euler_angle(
input: Tensor,
rotation: Tensor,
axes: str,
degrees: bool = False,
inverse: bool = False,
) -> Tensor:
r"""
Rotates vectors in three-dimensional space using Euler angles.
Note
----
This function interprets the rotation of the original frame to the final
frame as either a projection, where it maps the components of vectors from
the final frame to the original frame, or as a physical rotation,
integrating the vectors into the original frame during the rotation
process. Consequently, the vector components are maintained in the original
frame’s perspective both before and after the rotation.
Parameters
----------
input : Tensor
Vectors in three-dimensional space with the shape $(\ldots \times 3)$.
Euler angles and vectors must conform to PyTorch broadcasting rules.
rotation : Tensor
Euler angles with the shape $(\ldots \times 3)$, specifying the
rotation in three-dimensional space.
axes : str
Specifies the sequence of axes for the rotations, using one to three
characters from the set ${X, Y, Z}$ for intrinsic rotations, or
${x, y, z}$ for extrinsic rotations. Mixing extrinsic and intrinsic
rotations raises a `ValueError`.
degrees : bool, optional
Indicates whether the Euler angles are provided in degrees. If `False`,
angles are assumed to be in radians. Default, `False`.
inverse : bool, optional
If `True`, applies the inverse rotation using the Euler angles to the
input vectors. Default, `False`.
Returns
-------
output : Tensor
A tensor of the same shape as `input`, containing the rotated vectors.
"""
return apply_rotation_matrix(
input,
euler_angle_to_rotation_matrix(
rotation,
axes,
degrees,
),
inverse,
)
Loading

0 comments on commit 3fd05b8

Please sign in to comment.