Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ect"
version = "1.0.2"
version = "1.0.3"
authors = [
{ name="Liz Munch", email="muncheli@msu.edu" },
]
Expand Down
24 changes: 10 additions & 14 deletions src/ect/ect_graph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
from numba import prange, njit
from numba.typed import List
from typing import Optional, Union

from .embed_cw import EmbeddedCW
Expand Down Expand Up @@ -55,8 +56,7 @@ def _ensure_directions(self, graph_dim, theta=None):
"""Ensures directions is a valid Directions object of correct dimension"""
if self.directions is None:
if self.num_dirs is None:
raise ValueError(
"Either 'directions' or 'num_dirs' must be provided.")
raise ValueError("Either 'directions' or 'num_dirs' must be provided.")
self.directions = Directions.uniform(self.num_dirs, dim=graph_dim)
elif isinstance(self.directions, list):
# if list of vectors, convert to Directions object
Expand Down Expand Up @@ -127,12 +127,10 @@ def calculate(

# override with theta if provided
directions = (
self.directions if theta is None else Directions.from_angles([
theta])
self.directions if theta is None else Directions.from_angles([theta])
)

simplex_projections = self._compute_simplex_projections(
graph, directions)
simplex_projections = self._compute_simplex_projections(graph, directions)

ect_matrix = self._compute_directional_transform(
simplex_projections, self.thresholds, self.shape_descriptor, self.dtype
Expand All @@ -148,7 +146,7 @@ def _compute_simplex_projections(
self, graph: Union[EmbeddedGraph, EmbeddedCW], directions
):
"""Compute projections of each simplex (vertices, edges, faces)"""
simplex_projections = []
simplex_projections = List()
node_projections = self._compute_node_projections(
graph.coord_matrix, directions
)
Expand All @@ -162,11 +160,9 @@ def _compute_simplex_projections(

if isinstance(graph, EmbeddedCW) and len(graph.faces) > 0:
node_to_index = {n: i for i, n in enumerate(graph.node_list)}
face_indices = [[node_to_index[v] for v in face]
for face in graph.faces]
face_indices = [[node_to_index[v] for v in face] for face in graph.faces]
face_maxes = np.array(
[np.max(node_projections[face, :], axis=0)
for face in face_indices]
[np.max(node_projections[face, :], axis=0) for face in face_indices]
)
simplex_projections.append(face_maxes)

Expand All @@ -192,7 +188,7 @@ def _compute_directional_transform(
num_thresh = thresholds.shape[0]
result = np.empty((num_dir, num_thresh), dtype=dtype)

sorted_projections = []
sorted_projections = List()
for proj in simplex_projections_list:
sorted_proj = np.empty_like(proj)
for i in prange(num_dir):
Expand All @@ -202,7 +198,7 @@ def _compute_directional_transform(
for j in prange(num_thresh):
thresh = thresholds[j]
for i in range(num_dir):
simplex_counts_list = []
simplex_counts_list = List()
for k in range(len(sorted_projections)):
projs = sorted_projections[k][:, i]
simplex_counts_list.append(
Expand All @@ -212,7 +208,7 @@ def _compute_directional_transform(
return result

@staticmethod
@njit(parallel=True, fastmath=True)
@njit(fastmath=True)
def shape_descriptor(simplex_counts_list):
"""Calculate shape descriptor from simplex counts (Euler characteristic)"""
chi = 0
Expand Down
Loading