Skip to content

Commit fd4605c

Browse files
authored
Merge pull request #49 from MunchLab/vectorizedect
Making the ECT so much faster!
2 parents 1f85e0e + e3ce61b commit fd4605c

291 files changed

Lines changed: 12843 additions & 22424 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.9", "3.10", "3.11"]
19+
python-version: ["3.10", "3.11"]
2020

2121
steps:
2222
- uses: actions/checkout@v4
File renamed without changes.
File renamed without changes.

Extra_Notebooks/Mesh.ipynb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"1 0\n",
13+
"4 5\n",
14+
"9 8\n",
15+
"10 1\n"
16+
]
17+
}
18+
],
19+
"source": [
20+
"from CGAL.CGAL_Kernel import Point_2\n",
21+
"from CGAL.CGAL_Triangulation_2 import Triangulation_2\n",
22+
"from CGAL.CGAL_Triangulation_2 import Triangulation_2_Vertex_circulator\n",
23+
"from CGAL.CGAL_Triangulation_2 import Triangulation_2_Vertex_handle\n",
24+
"\n",
25+
"points=[]\n",
26+
"points.append( Point_2(1,0) )\n",
27+
"points.append( Point_2(3,2) )\n",
28+
"points.append( Point_2(4,5) )\n",
29+
"points.append( Point_2(9,8) )\n",
30+
"points.append( Point_2(7,4) )\n",
31+
"points.append( Point_2(5,2) )\n",
32+
"points.append( Point_2(6,3) )\n",
33+
"points.append( Point_2(10,1) )\n",
34+
" \n",
35+
"t=Triangulation_2()\n",
36+
"t.insert(points)\n",
37+
"\n",
38+
"vc = t.incident_vertices(t.infinite_vertex())\n",
39+
"\n",
40+
"if vc.hasNext():\n",
41+
" done = vc.next();\n",
42+
" iter=Triangulation_2_Vertex_handle()\n",
43+
" while(1):\n",
44+
" iter=vc.next()\n",
45+
" print (iter.point())\n",
46+
" if iter == done:\n",
47+
" break\n"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {},
54+
"outputs": [],
55+
"source": []
56+
}
57+
],
58+
"metadata": {
59+
"kernelspec": {
60+
"display_name": "base",
61+
"language": "python",
62+
"name": "python3"
63+
},
64+
"language_info": {
65+
"codemirror_mode": {
66+
"name": "ipython",
67+
"version": 3
68+
},
69+
"file_extension": ".py",
70+
"mimetype": "text/x-python",
71+
"name": "python",
72+
"nbconvert_exporter": "python",
73+
"pygments_lexer": "ipython3",
74+
"version": "3.11.7"
75+
}
76+
},
77+
"nbformat": 4,
78+
"nbformat_minor": 2
79+
}

Extra_Notebooks/Playing_with_Spirals.ipynb

Lines changed: 1891 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ reqs:
1313

1414
clean:
1515
# Running autopep8
16-
@autopep8 -r --in-place ect/
16+
@autopep8 -r --in-place src/ect/
1717

1818
tests:
1919
# Running unittests
@@ -41,4 +41,9 @@ all:
4141
@make html
4242

4343
# Running unittests
44-
@make tests
44+
@make tests
45+
46+
47+
48+
develop:
49+
pip install -e .

benchmarks/benchmark_cw.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Benchmarks for CW complex computations"""
22
import numpy as np
33
import time
4-
from ect import ECT, EmbeddedCW, create_example_cw
4+
from ect import ECT
5+
from ect.utils.examples import create_example_cw
56
import json
67
from pathlib import Path
78

@@ -11,9 +12,9 @@ def benchmark_cw_ect(num_runs=5):
1112
results = {}
1213

1314
configs = [
14-
(8, 10), # Small
15-
(36, 36), # Medium
16-
(360, 360), # Large
15+
(8, 10),
16+
(36, 36),
17+
(360, 360),
1718
]
1819

1920
for num_dir, num_thresh in configs:
@@ -26,7 +27,7 @@ def benchmark_cw_ect(num_runs=5):
2627
start_time = time.time()
2728

2829
myect = ECT(num_dirs=num_dir, num_thresh=num_thresh)
29-
myect.calculateECT(K)
30+
myect.calculate(K)
3031

3132
execution_time = time.time() - start_time
3233
times.append(execution_time)
@@ -45,7 +46,7 @@ def benchmark_cw_ect(num_runs=5):
4546
print("Running CW complex benchmarks...")
4647
results = benchmark_cw_ect()
4748

48-
# Save results
49+
4950
output_dir = Path("benchmark_results")
5051
output_dir.mkdir(exist_ok=True)
5152

benchmarks/benchmark_graph.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ def benchmark_graph_ect(num_runs=5):
2121
"""Benchmark ECT computation on graphs"""
2222
results = {}
2323

24+
# Warmup run to trigger JIT compilation
25+
warmup_shape = create_test_shape(100, 1)
26+
G_warmup = EmbeddedGraph()
27+
G_warmup.add_cycle(warmup_shape)
28+
myect = ECT(num_dirs=360, num_thresh=360)
29+
myect.calculate(G_warmup) # Warmup run
30+
2431
configs = [
2532
(100, 1),
2633
(1000, 1),
2734
(100, 3),
2835
(1000, 3),
2936
(10000, 3),
37+
(100000, 5),
3038
]
3139

3240
for points, complexity in configs:
@@ -41,7 +49,7 @@ def benchmark_graph_ect(num_runs=5):
4149
for _ in range(num_runs):
4250
start_time = time.time()
4351
myect = ECT(num_dirs=360, num_thresh=360)
44-
myect.calculateECT(G)
52+
myect.calculate(G)
4553
times.append(time.time() - start_time)
4654

4755
results[f'points_{points}_complexity_{complexity}'] = {
@@ -50,30 +58,9 @@ def benchmark_graph_ect(num_runs=5):
5058
'min_time': float(np.min(times)),
5159
'max_time': float(np.max(times))
5260
}
61+
print(results)
5362

5463
return results
5564

5665

57-
def benchmark_g_omega(num_runs=5):
58-
"""Benchmark g_omega computation"""
59-
results = {}
60-
61-
sizes = [100, 500, 1000]
62-
for size in sizes:
63-
shape = create_test_shape(size)
64-
G = EmbeddedGraph()
65-
G.add_cycle(shape)
66-
67-
times = []
68-
for _ in range(num_runs):
69-
start_time = time.time()
70-
for theta in np.linspace(0, 2*np.pi, 360):
71-
G.g_omega(theta)
72-
times.append(time.time() - start_time)
73-
74-
results[f'size_{size}'] = {
75-
'mean_time': float(np.mean(times)),
76-
'std_time': float(np.std(times))
77-
}
7866

79-
return results

benchmarks/run_benchmarks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import time
44
from pathlib import Path
55
import json
6-
from benchmark_graph import benchmark_graph_ect, benchmark_g_omega
6+
from benchmark_graph import benchmark_graph_ect
77
from benchmark_cw import benchmark_cw_ect
88
import platform
99

@@ -26,8 +26,7 @@ def run_all_benchmarks(num_runs=5):
2626
print("\nRunning CW complex benchmarks...")
2727
results['benchmarks']['cw_ect'] = benchmark_cw_ect(num_runs=num_runs)
2828

29-
print("\nRunning g_omega benchmarks...")
30-
results['benchmarks']['g_omega'] = benchmark_g_omega(num_runs=num_runs)
29+
3130

3231
return results
3332

doc_source/notebooks/Matisse/example_matisse.ipynb

Lines changed: 389 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)