Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docformatter pre-commit hook #201

Merged
merged 3 commits into from
Dec 15, 2023
Merged
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
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@ repos:
- id: ruff
exclude: (thirdparty|cpp/sophus)/.*$
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
args: [--in-place, --wrap-summaries=115, --wrap-descriptions=120]
4 changes: 2 additions & 2 deletions cpp/sophus/sympy/sophus/affine_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class AffineCamera:
"""Affine camera transform"""
"""Affine camera transform."""

def __init__(self, focal_length, center):
assert isinstance(focal_length, sympy.Matrix)
Expand All @@ -22,7 +22,7 @@ def __init__(self, focal_length, center):
self.center = center

def pixel_from_z1_plane(self, point_in_camera_z1_plane):
"""Map point from z1-plane to"""
"""Map point from z1-plane to."""
assert isinstance(point_in_camera_z1_plane, sympy.Matrix)
assert point_in_camera_z1_plane.shape == (
2,
Expand Down
2 changes: 1 addition & 1 deletion cpp/sophus/sympy/sophus/brown_conrady_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class BrownConradyCamera:
"""Brown Conrady camera transform"""
"""Brown Conrady camera transform."""

def __init__(self, focal_length, center, distortion):
assert isinstance(focal_length, sympy.Matrix)
Expand Down
14 changes: 7 additions & 7 deletions cpp/sophus/sympy/sophus/complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@


class Complex:
"""Complex class"""
"""Complex class."""

def __init__(self, real, imag):
self.real = real
self.imag = imag

def __mul__(self, right):
"""complex multiplication"""
"""Complex multiplication."""
return Complex(
self.real * right.real - self.imag * right.imag,
self.imag * right.real + self.real * right.imag,
Expand All @@ -34,15 +34,15 @@ def __getitem__(self, key):
return self.imag

def squared_norm(self):
"""squared norm when considering the complex number as tuple"""
"""Squared norm when considering the complex number as tuple."""
return self.real**2 + self.imag**2

def conj(self):
"""complex conjugate"""
"""Complex conjugate."""
return Complex(self.real, -self.imag)

def inv(self):
"""complex inverse"""
"""Complex inverse."""
return Complex(
self.conj().real / self.squared_norm(),
self.conj().imag / self.squared_norm(),
Expand Down Expand Up @@ -75,12 +75,12 @@ def simplify(self):

@staticmethod
def da_a_mul_b(_a, b):
"""derivative of complex multiplication wrt left multiplier a"""
"""Derivative of complex multiplication wrt left multiplier a."""
return sympy.Matrix([[b.real, -b.imag], [b.imag, b.real]])

@staticmethod
def db_a_mul_b(a, _b):
"""derivative of complex multiplication wrt right multiplicand b"""
"""Derivative of complex multiplication wrt right multiplicand b."""
return sympy.Matrix([[a.real, -a.imag], [a.imag, a.real]])


Expand Down
15 changes: 7 additions & 8 deletions cpp/sophus/sympy/sophus/dual_quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@


class DualQuaternion:
"""Dual quaternion class"""
"""Dual quaternion class."""

def __init__(self, real_q, inf_q):
"""Dual quaternion consists of a real quaternion, and an infinitesimal
quaternion"""
"""Dual quaternion consists of a real quaternion, and an infinitesimal quaternion."""
self.real_q = real_q
self.inf_q = inf_q

def __mul__(self, right):
"""dual quaternion multiplication"""
"""Dual quaternion multiplication."""
return DualQuaternion(
self.real_q * right.real_q,
self.real_q * right.inf_q + self.inf_q * right.real_q,
)

def __truediv__(self, scalar):
"""scalar division"""
"""Scalar division."""
return DualQuaternion(self.real_q / scalar, self.inf_q / scalar)

def __repr__(self):
Expand All @@ -37,15 +36,15 @@ def __getitem__(self, key):
return self.inf_q[key - 4]

def squared_norm(self):
"""squared norm when considering the dual quaternion as 8-tuple"""
"""Squared norm when considering the dual quaternion as 8-tuple."""
return self.real_q.squared_norm() + self.inf_q.squared_norm()

def conj(self):
"""dual quaternion conjugate"""
"""Dual quaternion conjugate."""
return DualQuaternion(self.real_q.conj(), self.inf_q.conj())

def inv(self):
"""dual quaternion inverse"""
"""Dual quaternion inverse."""
return DualQuaternion(
self.real_q.inv(), -self.real_q.inv() * self.inf_q * self.real_q.inv()
)
Expand Down
2 changes: 1 addition & 1 deletion cpp/sophus/sympy/sophus/inverse_depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def translation():


class InverseDepth:
"""Affine camera transform"""
"""Affine camera transform."""

def __init__(self, ab_and_psi):
assert isinstance(ab_and_psi, sympy.Matrix)
Expand Down
2 changes: 1 addition & 1 deletion cpp/sophus/sympy/sophus/kannala_brandt_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class KannalaBrandtTransformCamera:
"""KannalaBrandt camera transform"""
"""KannalaBrandt camera transform."""

def __init__(self, focal_length, center, distortion):
assert isinstance(focal_length, sympy.Matrix)
Expand Down
20 changes: 10 additions & 10 deletions cpp/sophus/sympy/sophus/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@


class Quaternion:
"""Quaternion class"""
"""Quaternion class."""

def __init__(self, real, vec):
"""Quaternion consists of a real scalar, and an imaginary 3-vector"""
"""Quaternion consists of a real scalar, and an imaginary 3-vector."""
assert isinstance(vec, sympy.Matrix)
assert vec.shape == (3, 1), vec.shape
self.real = real
self.vec = vec

def __mul__(self, right):
"""quaternion multiplication"""
"""Quaternion multiplication."""
return Quaternion(
self[3] * right[3] - self.vec.dot(right.vec),
self[3] * right.vec + right[3] * self.vec + self.vec.cross(right.vec),
)

def __add__(self, right):
"""quaternion multiplication"""
"""Quaternion multiplication."""
return Quaternion(self[3] + right[3], self.vec + right.vec)

def __neg__(self):
return Quaternion(-self[3], -self.vec)

def __truediv__(self, scalar):
"""scalar division"""
"""Scalar division."""
return Quaternion(self.real / scalar, self.vec / scalar)

def __repr__(self):
Expand All @@ -47,15 +47,15 @@ def __getitem__(self, key):
return self.vec[key]

def squared_norm(self):
"""squared norm when considering the quaternion as 4-tuple"""
"""Squared norm when considering the quaternion as 4-tuple."""
return squared_norm(self.vec) + self.real**2

def conj(self):
"""quaternion conjugate"""
"""Quaternion conjugate."""
return Quaternion(self.real, -self.vec)

def inv(self):
"""quaternion inverse"""
"""Quaternion inverse."""
return self.conj() / self.squared_norm()

@staticmethod
Expand Down Expand Up @@ -87,7 +87,7 @@ def __eq__(self, other):

@staticmethod
def da_a_mul_b(_a, b):
"""derivative of quaternion multiplication wrt left multiplier a"""
"""Derivative of quaternion multiplication wrt left multiplier a."""
v0 = b.vec[0]
v1 = b.vec[1]
v2 = b.vec[2]
Expand All @@ -98,7 +98,7 @@ def da_a_mul_b(_a, b):

@staticmethod
def db_a_mul_b(a, _b):
"""derivative of quaternion multiplication wrt right multiplicand b"""
"""Derivative of quaternion multiplication wrt right multiplicand b."""
u0 = a.vec[0]
u1 = a.vec[1]
u2 = a.vec[2]
Expand Down
12 changes: 5 additions & 7 deletions cpp/sophus/sympy/sophus/se2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@


class Isometry2:
"""2 dimensional group of rigid body transformations"""
"""2 dimensional group of rigid body transformations."""

def __init__(self, so2, t):
"""internally represented by a unit complex number z and a translation
2-vector"""
"""Internally represented by a unit complex number z and a translation 2-vector."""
self.so2 = so2
self.t = t

@staticmethod
def exp(v):
"""exponential map"""
"""Exponential map."""
theta = v[2]
so2 = Rotation2.exp(theta)

Expand Down Expand Up @@ -62,13 +61,12 @@ def hat(v):
return Rotation2.hat(theta).row_join(upsilon).col_join(sympy.Matrix.zeros(1, 3))

def matrix(self):
"""returns matrix representation"""
"""Returns matrix representation."""
mat_r = self.so2.matrix()
return (mat_r.row_join(self.t)).col_join(sympy.Matrix(1, 3, [0, 0, 1]))

def __mul__(self, right):
"""left-multiplication
either rotation concatenation or point-transform"""
"""Left-multiplication either rotation concatenation or point-transform."""
if isinstance(right, sympy.Matrix):
assert right.shape == (2, 1), right.shape
return self.so2 * right + self.t
Expand Down
20 changes: 8 additions & 12 deletions cpp/sophus/sympy/sophus/se3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@


class Isometry3:
"""3 dimensional group of rigid body transformations"""
"""3 dimensional group of rigid body transformations."""

def __init__(self, so3, t):
"""internally represented by a unit quaternion q and a translation
3-vector"""
"""Internally represented by a unit quaternion q and a translation 3-vector."""
assert isinstance(so3, Rotation3)
assert isinstance(t, sympy.Matrix)
assert t.shape == (3, 1), t.shape
Expand All @@ -32,7 +31,7 @@ def __init__(self, so3, t):

@staticmethod
def exp(v):
"""exponential map"""
"""Exponential map."""
upsilon = v[0:3, :]
omega = vector3(v[3], v[4], v[5])
so3 = Rotation3.exp(omega)
Expand Down Expand Up @@ -79,31 +78,28 @@ def inverse(self):

@staticmethod
def hat(v):
"""mat_r^6 => mat_r^4x4
returns 4x4-matrix representation ``mat_omega``"""
"""mat_r^6 => mat_r^4x4 returns 4x4-matrix representation ``mat_omega``"""
upsilon = vector3(v[0], v[1], v[2])
omega = vector3(v[3], v[4], v[5])
return Rotation3.hat(omega).row_join(upsilon).col_join(sympy.Matrix.zeros(1, 4))

@staticmethod
def vee(mat_omega):
"""mat_r^4x4 => mat_r^6
returns 6-vector representation of Lie algebra
This is the inverse of the hat-operator"""
"""mat_r^4x4 => mat_r^6 returns 6-vector representation of Lie algebra This is the inverse of the hat-
operator."""

head = vector3(mat_omega[0, 3], mat_omega[1, 3], mat_omega[2, 3])
tail = Rotation3.vee(mat_omega[0:3, 0:3])
upsilon_omega = vector6(head[0], head[1], head[2], tail[0], tail[1], tail[2])
return upsilon_omega

def matrix(self):
"""returns matrix representation"""
"""Returns matrix representation."""
mat_r = self.so3.matrix()
return (mat_r.row_join(self.t)).col_join(sympy.Matrix(1, 4, [0, 0, 0, 1]))

def __mul__(self, right):
"""left-multiplication
either rotation concatenation or point-transform"""
"""Left-multiplication either rotation concatenation or point-transform."""
if isinstance(right, sympy.Matrix):
assert right.shape == (3, 1), right.shape
return self.so3 * right + self.t
Expand Down
13 changes: 6 additions & 7 deletions cpp/sophus/sympy/sophus/so2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@


class Rotation2:
"""2 dimensional group of orthogonal matrices with determinant 1"""
"""2 dimensional group of orthogonal matrices with determinant 1."""

def __init__(self, z):
"""internally represented by a unit complex number z"""
"""Internally represented by a unit complex number z."""
self.z = z

@staticmethod
def exp(theta):
"""exponential map"""
"""Exponential map."""
return Rotation2(Complex(sympy.cos(theta), sympy.sin(theta)))

def log(self):
"""logarithmic map"""
"""Logarithmic map."""
return sympy.atan2(self.z.imag, self.z.real)

def calc_dx_log_this(self):
Expand All @@ -44,12 +44,11 @@ def hat(theta):
return sympy.Matrix([[0, -theta], [theta, 0]])

def matrix(self):
"""returns matrix representation"""
"""Returns matrix representation."""
return sympy.Matrix([[self.z.real, -self.z.imag], [self.z.imag, self.z.real]])

def __mul__(self, right):
"""left-multiplication
either rotation concatenation or point-transform"""
"""Left-multiplication either rotation concatenation or point-transform."""
if isinstance(right, sympy.Matrix):
assert right.shape == (2, 1), right.shape
return self.matrix() * right
Expand Down
Loading