Skip to content

Commit 70b668b

Browse files
committed
Clean pydocstyle CI/CD
1 parent 8b048b3 commit 70b668b

File tree

20 files changed

+130
-153
lines changed

20 files changed

+130
-153
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858

5959
# Check docstrings are in Google style
6060
- name: Check docstrings are in Google style
61-
run: pydocstyle manify/ --convention=google
61+
run: pydocstyle --add-ignore=D107 --convention=google manify/
6262
continue-on-error: true
6363

6464
# Code coverage

manify/curvature_estimation/delta_hyperbolicity.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Methods for computing $\delta$-hyperbolicity of a metric space.
1+
r"""Methods for computing $\delta$-hyperbolicity of a metric space.
22
33
The $\delta$-hyperbolicity measures how close a metric space is to a tree. The value $\delta \geq 0$ is a global
44
property; smaller values indicate the space is more hyperbolic.
@@ -83,7 +83,6 @@ def delta_hyperbolicity(
8383
Returns:
8484
delta: Either the maximum $\delta$ value (if full=False) or the full $\delta$ tensor.
8585
"""
86-
8786
n = D.shape[0]
8887
w = reference_idx
8988

manify/embedders/_losses.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def distortion_loss(
4040
This is similar to the `square_loss` in HazyResearch hyperbolics repository:
4141
https://github.com/HazyResearch/hyperbolics/blob/master/pytorch/hyperbolic_models.py#L178
4242
"""
43-
4443
# Turn into flat vectors of pairwise distances. For pairwise distances, we only consider the upper triangle.
4544
if pairwise:
4645
n = D_true.shape[0]
@@ -67,15 +66,13 @@ def d_avg(
6766
r"""Computes the average relative distance error (D_avg).
6867
6968
The average distance error is the mean relative error between the estimated and true distances:
70-
7169
$$
7270
D_{\text{avg}} = \frac{1}{N} \sum_{i,j} \frac{
7371
|D_{\text{est}}(i,j) - D_{\text{true}}(i,j)|
7472
}{
7573
D_{\text{true}}(i,j)
7674
},
7775
$$
78-
7976
where $N$ is the number of distances being considered. This metric provides a normalized measure of how accurately
8077
the embedding preserves the original distances.
8178
@@ -87,7 +84,6 @@ def d_avg(
8784
Returns:
8885
d_avg: Scalar tensor representing the average relative distance error.
8986
"""
90-
9187
if pairwise:
9288
n = D_true.shape[0]
9389
idx = torch.triu_indices(n, n, offset=1)

manify/embedders/coordinate_learning.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929

3030

3131
class CoordinateLearning(BaseEmbedder):
32-
"""
33-
This embedder implements the approach described in Gu et al., "Learning Mixed-Curvature
34-
Representations in Product Spaces". It directly optimizes point coordinates to preserve
35-
a given distance matrix, using Riemannian optimization techniques.
32+
"""Coordinate learning method class.
33+
34+
This embedder implements the approach described in Gu et al., "Learning Mixed-Curvature Representations in Product
35+
Spaces". It directly optimizes point coordinates to preserve a given distance matrix, using Riemannian optimization
36+
techniques.
3637
3738
Trains point coordinates in a product manifold to match target distances.
3839
@@ -222,8 +223,9 @@ def transform(self, X: None = None) -> Float[torch.Tensor, "n_points embedding_d
222223
def fit_transform( # type: ignore[override]
223224
self, X: None, D: Float[torch.Tensor, "n_points n_points"], **fit_kwargs: Any
224225
) -> Float[torch.Tensor, "n_points embedding_dim"]:
225-
"""Transform data using learned embedding based on the provided distance matrix D. Overrides the base class
226-
method `BaseEmbedder.fit_transform()` to not use the input data X.
226+
"""Transform data using learned embedding based on the provided distance matrix D.
227+
228+
This method overrides the base class method `BaseEmbedder.fit_transform()` to not use the input data X.
227229
228230
Args:
229231
X: Ignored.

manify/embedders/vae.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ def transform(
371371
Returns:
372372
embeddings: Learned embeddings.
373373
"""
374-
375374
# Set random state
376375
if self.random_state is not None:
377376
torch.manual_seed(self.random_state)

manify/manifolds.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def log_likelihood(
263263
mu: Optional[Float[torch.Tensor, "n_points n_ambient_dim"]] = None,
264264
sigma: Optional[Float[torch.Tensor, "n_points n_dim n_dim"]] = None,
265265
) -> Float[torch.Tensor, "n_points,"]:
266-
"""Compute probability density function for $\\mathcal{WN}(\\mathbf{z}; \\mu, \\Sigma)$ on the manifold.
266+
r"""Compute probability density function for $\mathcal{WN}(\mathbf{z}; \mu, \Sigma)$ on the manifold.
267267
268268
Args:
269269
z: Tensor of points on the manifold for which to compute the likelihood.
@@ -274,7 +274,6 @@ def log_likelihood(
274274
log_likelihoods: Tensor containing the log-likelihood of the points `z` under the distribution with mean
275275
`mu` and covariance `sigma`.
276276
"""
277-
278277
# Default to mu=self.mu0 and sigma=I
279278
if mu is None:
280279
mu = self.mu0
@@ -364,7 +363,6 @@ def stereographic(self, *points: Float[torch.Tensor, "n_points n_dim"]) -> Tuple
364363
stereo_manifold: The manifold in stereographic coordinates.
365364
stereo_points: The provided points converted to stereographic coordinates (if any).
366365
"""
367-
368366
if self.is_stereographic:
369367
print("Manifold is already in stereographic coordinates.")
370368
return self, *points

manify/predictors/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
r"""
2-
Initialize predictors in the product space.
1+
r"""Initialize predictors in the product space.
32
43
Implemented predictors include:
54
## Decision Trees and Random Forests: Use geodesic splits in product manifolds via projection angles and manifold-specific geodesic midpoints.

manify/predictors/_kernel.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Implementation for kernel matrix calculation"""
1+
"""Implementation for kernel matrix calculation."""
22

33
from __future__ import annotations
44

@@ -15,8 +15,7 @@ def compute_kernel_and_norm_manifold(
1515
X_source: Float[torch.Tensor, "n_points_source n_dim"],
1616
X_target: Optional[Float[torch.Tensor, "n_points_target n_dim"]],
1717
) -> Tuple[Float[torch.Tensor, "n_points_source n_points_target"], Float[torch.Tensor, ""]]:
18-
"""
19-
Compute the kernel matrix between two sets of points in a given manifold.
18+
"""Compute the kernel matrix between two sets of points in a given manifold.
2019
2120
Args:
2221
manifold: The manifold in which the computation occurs.
@@ -67,8 +66,7 @@ def product_kernel(
6766
List[Float[torch.Tensor, "n_points_source n_points_target"]],
6867
List[Float[torch.Tensor, ""]],
6968
]:
70-
"""
71-
Compute the kernel matrix between two sets of points in a product manifold.
69+
"""Compute the kernel matrix between two sets of points in a product manifold.
7270
7371
Args:
7472
pm: The product manifold in which the computation occurs.

manify/predictors/_midpoint.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Compute the angular midpoints between two angular coordinates in different geometric spaces"""
1+
"""Compute the angular midpoints between two angular coordinates in different geometric spaces."""
22

33
from __future__ import annotations
44

@@ -9,8 +9,7 @@
99

1010

1111
def hyperbolic_midpoint(u: float, v: float, assert_hyperbolic: bool = False) -> Float[torch.Tensor, ""]:
12-
"""
13-
Compute the hyperbolic midpoint between two angular coordinates u and v.
12+
"""Compute the hyperbolic midpoint between two angular coordinates u and v.
1413
1514
Args:
1615
u: The first angular coordinate.
@@ -31,8 +30,7 @@ def hyperbolic_midpoint(u: float, v: float, assert_hyperbolic: bool = False) ->
3130

3231

3332
def is_hyperbolic_midpoint(u: float, v: float, m: float) -> bool:
34-
"""
35-
Verifies if m is the true hyperbolic midpoint between u and v.
33+
r"""Verify if $\mathbf{m}$ is the true hyperbolic midpoint between $\mathbf{u}$ and $\mathbf{v}$.
3634
3735
Args:
3836
u (torch.Tensor): The first angular coordinate.
@@ -48,8 +46,7 @@ def is_hyperbolic_midpoint(u: float, v: float, m: float) -> bool:
4846

4947

5048
def spherical_midpoint(u: float, v: float) -> Float[torch.Tensor, ""]:
51-
"""
52-
Compute the spherical midpoint between two angular coordinates u and v.
49+
"""Compute the spherical midpoint between two angular coordinates u and v.
5350
5451
Args:
5552
u (torch.Tensor): The first angular coordinate.
@@ -62,24 +59,20 @@ def spherical_midpoint(u: float, v: float) -> Float[torch.Tensor, ""]:
6259

6360

6461
def euclidean_midpoint(u: float, v: float) -> Float[torch.Tensor, ""]:
65-
"""
66-
Compute the euclidean midpoint between two angular coordinates u and v.
62+
"""Compute the euclidean midpoint between two angular coordinates u and v.
6763
6864
Args:
6965
u (torch.Tensor): The first angular coordinate.
7066
v (torch.Tensor): The second angular coordinate.
7167
7268
Returns:
73-
torch.Tensor: The computed spherical midpoint between u and v.
69+
torch.Tensor: The computed euclidean midpoint between u and v.
7470
"""
7571
return torch.arctan2(torch.tensor(2.0), (1.0 / torch.tan(u) + 1.0 / torch.tan(v)))
7672

7773

7874
def midpoint(
79-
u: Float[torch.Tensor, ""],
80-
v: Float[torch.Tensor, ""],
81-
manifold: Manifold,
82-
special_first: bool = False,
75+
u: Float[torch.Tensor, ""], v: Float[torch.Tensor, ""], manifold: Manifold, special_first: bool = False
8376
) -> Float[torch.Tensor, ""]:
8477
"""Compute the midpoint between two angular coordinates given the manifold type.
8578

0 commit comments

Comments
 (0)