Skip to content

Commit

Permalink
Merge pull request #46 from pyt-team/frantzen/toponetx-imports
Browse files Browse the repository at this point in the history
Adapt to new TopoNetX import convention
  • Loading branch information
ffl096 authored Jul 8, 2024
2 parents 6d9791c + c030861 commit c05bf47
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
5 changes: 3 additions & 2 deletions topoembedx/classes/cell2vec.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Cell2Vec: a class that extends the Node2Vec class."""

from typing import Literal

import networkx as nx
import numpy as np
import toponetx as tnx
from karateclub import Node2Vec
from toponetx.classes import Complex

from topoembedx.neighborhood import neighborhood_from_complex

Expand Down Expand Up @@ -54,7 +55,7 @@ class Cell2Vec(Node2Vec):

def fit(
self,
complex: Complex,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim={"rank": 0, "via_rank": -1},
) -> None:
Expand Down
5 changes: 3 additions & 2 deletions topoembedx/classes/cell_diff2vec.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Class CellDiff2Vec."""

from typing import Literal

import networkx as nx
import numpy as np
import toponetx as tnx
from karateclub import Diff2Vec
from toponetx.classes.complex import Complex

from topoembedx.neighborhood import neighborhood_from_complex

Expand Down Expand Up @@ -39,7 +40,7 @@ class CellDiff2Vec(Diff2Vec):

def fit(
self,
complex: Complex,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim={"rank": 0, "via_rank": -1},
) -> None:
Expand Down
5 changes: 3 additions & 2 deletions topoembedx/classes/deepcell.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""DeepCell class for embedding complex networks using DeepWalk."""

from typing import Literal

import networkx as nx
import numpy as np
import toponetx as tnx
from karateclub import DeepWalk
from toponetx.classes import Complex

from topoembedx.neighborhood import neighborhood_from_complex

Expand Down Expand Up @@ -39,7 +40,7 @@ class DeepCell(DeepWalk):

def fit(
self,
complex: Complex,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim={"rank": 0, "via_rank": -1},
) -> None:
Expand Down
5 changes: 3 additions & 2 deletions topoembedx/classes/higher_order_laplacian_eigenmaps.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Higher Order Laplacian Eigenmaps."""

from typing import Literal

import networkx as nx
import numpy as np
import toponetx as tnx
from karateclub import LaplacianEigenmaps
from toponetx.classes import Complex

from topoembedx.neighborhood import neighborhood_from_complex

Expand Down Expand Up @@ -36,7 +37,7 @@ def __init__(

def fit(
self,
complex: Complex,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim={"rank": 0, "via_rank": -1},
) -> None:
Expand Down
5 changes: 3 additions & 2 deletions topoembedx/classes/hoglee.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Higher Order Geometric Laplacian EigenMaps (HOGLEE) class."""

from typing import Literal

import networkx as nx
import numpy as np
import toponetx as tnx
from karateclub import GLEE
from toponetx.classes import Complex

from topoembedx.neighborhood import neighborhood_from_complex

Expand All @@ -25,7 +26,7 @@ class HOGLEE(GLEE):

def fit(
self,
complex: Complex,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim={"rank": 0, "via_rank": -1},
) -> None:
Expand Down
5 changes: 3 additions & 2 deletions topoembedx/classes/hope.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Higher Order Laplacian Positional Encoder (HOPE) class."""

from typing import Literal, overload

import numpy as np
import toponetx as tnx
from scipy import sparse
from toponetx.classes import Complex

from topoembedx.neighborhood import neighborhood_from_complex

Expand Down Expand Up @@ -113,7 +114,7 @@ def _laplacian_pe(

def fit(
self,
complex: Complex,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim: dict = {"rank": 0, "to_rank": -1},
) -> None:
Expand Down
16 changes: 5 additions & 11 deletions topoembedx/neighborhood.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
"""Functions for computing neighborhoods of a complex."""

from typing import Literal

import numpy as np
from toponetx.classes import (
CellComplex,
ColoredHyperGraph,
CombinatorialComplex,
Complex,
PathComplex,
SimplicialComplex,
)
import toponetx as tnx


def neighborhood_from_complex(
complex: Complex,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim={"rank": 0, "via_rank": -1},
) -> tuple[list, np.ndarray]:
Expand Down Expand Up @@ -65,12 +59,12 @@ def neighborhood_from_complex(
f"Input neighborhood_type must be `adj` or `coadj`, got {neighborhood_type}."
)

if isinstance(complex, SimplicialComplex | CellComplex | PathComplex):
if isinstance(complex, tnx.SimplicialComplex | tnx.CellComplex | tnx.PathComplex):
if neighborhood_type == "adj":
ind, A = complex.adjacency_matrix(neighborhood_dim["rank"], index=True)
else:
ind, A = complex.coadjacency_matrix(neighborhood_dim["rank"], index=True)
elif isinstance(complex, CombinatorialComplex | ColoredHyperGraph):
elif isinstance(complex, tnx.CombinatorialComplex | tnx.ColoredHyperGraph):
if neighborhood_type == "adj":
ind, A = complex.adjacency_matrix(
neighborhood_dim["rank"], neighborhood_dim["via_rank"], index=True
Expand Down

0 comments on commit c05bf47

Please sign in to comment.