Skip to content

Commit

Permalink
Added documentation with pydoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnstRoell committed Jul 1, 2024
1 parent b1dc966 commit 94e80b8
Show file tree
Hide file tree
Showing 11 changed files with 2,430 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docs:
python -m pdoc --docformat numpy --logo "https://avatars.githubusercontent.com/u/88346553?s=200&v=4" dect -o ./docs
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,22 @@ with or without CUDA support. The DECT implementation also relies on the
of a vector given an index vector.

- First install `torch` and `torch-scatter`.
```{python}

```python
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117
pip install torch-scatter -f https://data.pyg.org/whl/torch-2.1.0+${CUDA}.html
```

- Then install our package in either one of two ways:
- As a git submodule
```{pyton}

```sh
git submodule add https://github.com/aidos-lab/dect.git
```

- Or as a pip installable package.
```{python}

```sh
pip install git+https://github.com/aidos-lab/dect.git
```

Expand All @@ -54,7 +59,7 @@ ECT of the gif of this readme.
The code is provided on an as is basis. You are cordially invited to both contribute and
provide feedback. Do not hesitate to contact us.

```{python}
```python
import torch
from torch_geometric.data import Data, Batch
from dect.ect import EctConfig, EctLayer
Expand Down
3 changes: 3 additions & 0 deletions dect/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
.. include:: ../README.md
"""
28 changes: 25 additions & 3 deletions dect/directions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import torch


def generate_uniform_directions(num_thetas: int = 64, d: int = 3, device: str = "cpu"):
def generate_uniform_directions(
num_thetas: int = 64, d: int = 3, device: str = "cpu"
):
"""
Generate randomly sampled directions from a sphere in d dimensions.
Expand Down Expand Up @@ -49,8 +51,12 @@ def generate_uniform_2d_directions(num_thetas: int = 64, device: str = "cpu"):
"""
v = torch.vstack(
[
torch.sin(torch.linspace(0, 2 * torch.pi, num_thetas, device=device)),
torch.cos(torch.linspace(0, 2 * torch.pi, num_thetas, device=device)),
torch.sin(
torch.linspace(0, 2 * torch.pi, num_thetas, device=device)
),
torch.cos(
torch.linspace(0, 2 * torch.pi, num_thetas, device=device)
),
]
)

Expand Down Expand Up @@ -88,3 +94,19 @@ def generate_multiview_directions(num_thetas: int, bump_steps: int, d: int):
v[idx, idx_pair[1], :] = w[1]

return v


def test_fn():
"""Yields
------
err_code : int
Non-zero value indicates error code, or zero on success.
err_msg : str or None
Human readable error message, or None on success.
Returns
-------
int
Description of anonymous integer return value.
"""
16 changes: 11 additions & 5 deletions dect/ect.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,17 @@ def compute_ecc(
"""
ecc = torch.nn.functional.sigmoid(scale * torch.sub(lin, nh))

# Due to (I believe) a bug in segment_add_coo, we have to first transpose and
# then apply segment add. In the original code movedim was applied after
# Due to (I believe) a bug in segment_add_coo, we have to first transpose
# and then apply segment add. In the original code movedim was applied after
# and that yields an bug in the backwards pass. Will have to be reported to
# pytorch eventually.
ecc = ecc.movedim(0, 2).movedim(0, 1)
return segment_add_coo(ecc, index)


def compute_ect_points(batch: Batch, v: torch.FloatTensor, lin: torch.FloatTensor):
def compute_ect_points(
batch: Batch, v: torch.FloatTensor, lin: torch.FloatTensor
):
"""Computes the Euler Characteristic Transform of a batch of point clouds.
Parameters
Expand All @@ -109,7 +111,9 @@ def compute_ect_points(batch: Batch, v: torch.FloatTensor, lin: torch.FloatTenso
return compute_ecc(nh, batch.batch, lin)


def compute_ect_edges(data: Batch, v: torch.FloatTensor, lin: torch.FloatTensor):
def compute_ect_edges(
data: Batch, v: torch.FloatTensor, lin: torch.FloatTensor
):
"""Computes the Euler Characteristic Transform of a batch of graphs.
Parameters
Expand Down Expand Up @@ -145,7 +149,9 @@ def compute_ect_edges(data: Batch, v: torch.FloatTensor, lin: torch.FloatTensor)
)


def compute_ect_faces(data: Batch, v: torch.FloatTensor, lin: torch.FloatTensor):
def compute_ect_faces(
data: Batch, v: torch.FloatTensor, lin: torch.FloatTensor
):
"""Computes the Euler Characteristic Transform of a batch of meshes.
Parameters
Expand Down
409 changes: 409 additions & 0 deletions docs/dect.html

Large diffs are not rendered by default.

596 changes: 596 additions & 0 deletions docs/dect/directions.html

Large diffs are not rendered by default.

1,320 changes: 1,320 additions & 0 deletions docs/dect/ect.html

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=./dect.html"/>
</head>
</html>
46 changes: 46 additions & 0 deletions docs/search.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/test_ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
class TestEct:
"""
1. When normalized, the ect needs to be normalized.
2. The dimensions need to correspond. e.g. the batches need not to be mixed up.
2. The dimensions need to correspond. e.g. the batches need not to
be mixed up.
3. Test that when one of the inputs has a gradient the out has one too.
"""

Expand Down

0 comments on commit 94e80b8

Please sign in to comment.