Skip to content

Commit

Permalink
Merge branch 'main' into josef-fix-incidence-to-adjacency
Browse files Browse the repository at this point in the history
  • Loading branch information
ninamiolane committed May 23, 2023
2 parents 5a0fdcd + f39a2ae commit 4e16bbf
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 301 deletions.
12 changes: 12 additions & 0 deletions test/utils/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ def test_neighborhood_list_to_neighborhood_dict(self):
)
assert out == d

def test_neighborhood_list_to_neighborhood_with_dict(self):
"""Test that neighborhood_list_to_neighborhood_dict works correctly with specified node dictionary."""
node_dict = {1: "a", 2: "b", 3: "c"}
neigh_list = [(1, 2), (2, 1), (2, 3), (3, 2)]
neigh_dict = neighborhood_list_to_neighborhood_dict(
neigh_list, node_dict, node_dict
)
assert len(neigh_dict) == 3
assert neigh_dict["a"] == ["b"]
assert set(neigh_dict["b"]) == {"a", "c"} # order irrelevant
assert neigh_dict["c"] == ["b"]

def test_sparse_array_to_neighborhood_dict(self):
"""Test the sparse_array_to_neighborhood_dict function."""
c = CellComplex()
Expand Down
29 changes: 12 additions & 17 deletions toponetx/algorithms/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def laplacian_spectrum(matrix, weight="weight"):
----------
matrix : scipy sparse matrix
weight : string or None, optional (default='weight')
weight : str or None, optional (default='weight')
If None, then each cell has weight 1.
Returns
Expand All @@ -203,17 +203,16 @@ def cell_complex_hodge_laplacian_spectrum(CX: CellComplex, rank: int, weight="we
Parameters
----------
matrix : scipy sparse matrix
weight : string or None, optional (default='weight')
weight : str or None, optional (default='weight')
If None, then each cell has weight 1.
Returns
-------
evals : NumPy array
Eigenvalues.
Example
-------
Examples
--------
>>> CX = CellComplex()
>>> CX.add_cell([1,2,3,4],rank=2)
>>> CX.add_cell([2,3,4,5],rank=2)
Expand All @@ -231,16 +230,15 @@ def simplicial_complex_hodge_laplacian_spectrum(
Parameters
----------
matrix : scipy sparse matrix
weight : string or None, optional (default='weight')
weight : str or None, optional (default='weight')
If None, then each cell has weight 1.
Returns
-------
evals : NumPy array
Eigenvalues.
Example
Examples
--------
>>> SC=SimplicialComplex([[1,2,3],[2,3,5],[0,1]])
>>> spectrum=simplicial_complex_hodge_laplacian_spectrum(SC,1)
Expand All @@ -254,7 +252,6 @@ def cell_complex_adjacency_spectrum(CX: CellComplex, rank):
Parameters
----------
matrix : scipy sparse matrix
up : bool, default False
whether to take the upper or lower adjacency
Expand All @@ -263,8 +260,8 @@ def cell_complex_adjacency_spectrum(CX: CellComplex, rank):
evals : NumPy array
Eigenvalues
Example
-------
Examples
--------
>>> CX = CellComplex()
>>> CX.add_cell([1,2,3,4],rank=2)
>>> CX.add_cell([2,3,4,5],rank=2)
Expand All @@ -282,8 +279,7 @@ def simplicial_complex_adjacency_spectrum(
Parameters
----------
matrix : scipy sparse matrix
weight : string or None, optional (default='weight')
weight : str or None, optional (default='weight')
If None, then each cell has weight 1.
Returns
Expand All @@ -300,17 +296,16 @@ def combinatorial_complex_adjacency_spectrum(CC: CombinatorialComplex, r, k):
Parameters
----------
matrix : scipy sparse matrix
weight : string or None, optional (default='weight')
weight : str or None, default='weight'
If None, then each cell has weight 1.
Returns
-------
evals : NumPy array
Eigenvalues
Example
-------
Examples
--------
>>> CC = CombinatorialComplex(cells=[[1,2,3],[2,3], [0] ],ranks=[2,1,0] )
>>> s = laplacian_spectrum( CC.adjacency_matrix( 0,2) )
"""
Expand Down
25 changes: 11 additions & 14 deletions toponetx/classes/cell.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"""Cell and CellView classes."""

try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable
from collections import Counter, deque
from collections.abc import Iterable
from itertools import zip_longest

import numpy as np
Expand All @@ -13,7 +10,7 @@


class Cell:
r"""Class representing a 2D cell.
"""Class representing a 2D cell.
A 2D cell is an elementary building block used to build a 2D cell complex, whether regular or non-regular.
Expand Down Expand Up @@ -96,7 +93,7 @@ def __init__(self, elements, name=None, regular=True, **attr):
self.properties.update(attr)

def __getitem__(self, item):
r"""Retrieve the value associated with the given key in the properties dictionary.
"""Retrieve the value associated with the given key in the properties dictionary.
Parameters
----------
Expand All @@ -118,7 +115,7 @@ def __getitem__(self, item):
return self.properties[item]

def __setitem__(self, key, item):
r"""Set the value associated with the given key in the properties dictionary.
"""Set the value associated with the given key in the properties dictionary.
Parameters
----------
Expand All @@ -135,7 +132,7 @@ def __setitem__(self, key, item):

@property
def is_regular(self):
r"""Check if a cell is regular.
"""Check if a cell is regular.
Return true is the Cell is a regular cell, and False otherwise
"""
Expand All @@ -151,7 +148,7 @@ def is_regular(self):
return True

def __len__(self):
r"""Get the number of elements in the cell.
"""Get the number of elements in the cell.
Returns
-------
Expand All @@ -161,7 +158,7 @@ def __len__(self):
return len(self._elements)

def __iter__(self):
r"""Iterate over the elements in the cell.
"""Iterate over the elements in the cell.
Returns
-------
Expand All @@ -171,7 +168,7 @@ def __iter__(self):
return iter(self._elements)

def sign(self, edge):
r"""Compute the sign of the edge with respect to the cell.
"""Compute the sign of the edge with respect to the cell.
This takes an edge as input and computes the sign of the edge with respect to the cell.
Expand Down Expand Up @@ -218,7 +215,7 @@ def __repr__(self):

@property
def boundary(self):
r"""Boundary.
"""Boundary.
A 2d cell is characterized by its boundary edges.
Expand All @@ -238,7 +235,7 @@ def reverse(self):
Returns
-------
_ : Cell
Cell
New cell with the new reversed elements.
"""
c = Cell(self._elements[::-1], name=self.name, regular=self._regular)
Expand All @@ -254,7 +251,7 @@ def is_homotopic_to(self, cell):
Returns
-------
_ : bool
bool
Return True is self is homotopic to input cell and False otherwise.
"""
return Cell._are_homotopic(self, cell) or Cell._are_homotopic(
Expand Down

0 comments on commit 4e16bbf

Please sign in to comment.