Skip to content

Commit

Permalink
Merge branch 'weighted' of github.com:arnaudon/simplicial-kuramoto in…
Browse files Browse the repository at this point in the history
…to weighted
  • Loading branch information
arnaudon committed Mar 21, 2022
2 parents 3be682b + 7c4690c commit 4fcd66a
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions simplicial_kuramoto/simplicial_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ def W1(self):
@property
def W2(self):
"""Create face weight matrix."""
if self._W2 is None:
if self.faces is not None:
self._W2 = sc.sparse.spdiags(self.face_weights, 0, self.n_faces, self.n_faces)
if self._W2 is None and self.faces is not None:
self._W2 = sc.sparse.spdiags(self.face_weights, 0, self.n_faces, self.n_faces)
return self._W2

@property
Expand Down Expand Up @@ -164,21 +163,20 @@ def N0s(self):
@property
def B1(self):
"""Create edge incidence matrix."""
if self._B1 is None:
if self.faces is not None:
self._B1 = sc.sparse.lil_matrix((self.n_faces, self.n_edges))
for face_index, face in enumerate(self.faces):
for i in range(3):
edge = tuple(np.roll(face, i)[:2])
edge_rev = tuple(np.roll(face, i)[1::-1])
if edge in self.edgelist:
edge_index = self.edgelist.index(edge)
self._B1[face_index, edge_index] = 1.0
elif edge_rev in self.edgelist:
edge_index = self.edgelist.index(edge_rev)
self._B1[face_index, edge_index] = -1.0
else:
raise Exception("The face is not a triangle in the graph")
if self._B1 is None and self.faces is not None:
self._B1 = sc.sparse.lil_matrix((self.n_faces, self.n_edges))
for face_index, face in enumerate(self.faces):
for i in range(3):
edge = tuple(np.roll(face, i)[:2])
edge_rev = tuple(np.roll(face, i)[1::-1])
if edge in self.edgelist:
edge_index = self.edgelist.index(edge)
self._B1[face_index, edge_index] = 1.0
elif edge_rev in self.edgelist:
edge_index = self.edgelist.index(edge_rev)
self._B1[face_index, edge_index] = -1.0
else:
raise Exception("The face is not a triangle in the graph")
return self._B1

@property
Expand Down

0 comments on commit 4fcd66a

Please sign in to comment.