Skip to content

Commit 56bbe2c

Browse files
committed
Using numba improvements instead of cython for metrics
1 parent 3aeea11 commit 56bbe2c

5 files changed

Lines changed: 42 additions & 125 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ on:
66
- 'v[0-9]+.[0-9]+.[0-9]+'
77

88
jobs:
9-
build_locally:
10-
name: Build locally
9+
deploy-job:
10+
name: Build and deploy
1111
runs-on: ubuntu-latest
12+
environment: pypi
1213
steps:
1314
- name: Check out repository code
1415
uses: actions/checkout@v4
@@ -24,51 +25,6 @@ jobs:
2425
run: |
2526
python -m build
2627
python -m twine check dist/*
27-
28-
build_wheels:
29-
name: Build wheels on ${{ matrix.os }}
30-
runs-on: ${{ matrix.os }}
31-
strategy:
32-
matrix:
33-
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
34-
steps:
35-
- uses: actions/checkout@v4
36-
- name: Build wheels
37-
uses: pypa/cibuildwheel@v2.19.2
38-
- uses: actions/upload-artifact@v4
39-
with:
40-
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
41-
path: ./wheelhouse/*.whl
42-
43-
build_sdist:
44-
name: Build source distribution
45-
runs-on: ubuntu-latest
46-
steps:
47-
- uses: actions/checkout@v4
48-
49-
- name: Build sdist
50-
run: pipx run build --sdist
51-
52-
- uses: actions/upload-artifact@v4
53-
with:
54-
name: cibw-sdist
55-
path: dist/*.tar.gz
56-
57-
upload_pypi:
58-
needs: [build_locally, build_wheels, build_sdist]
59-
runs-on: ubuntu-latest
60-
environment: pypi
61-
permissions:
62-
id-token: write
63-
steps:
64-
- uses: actions/download-artifact@v4
65-
with:
66-
pattern: cibw-*
67-
path: dist
68-
merge-multiple: true
69-
70-
- uses: pypa/gh-action-pypi-publish@release/v1
71-
with:
72-
repository-url: https://test.pypi.org/legacy/
73-
74-
- uses: pypa/gh-action-pypi-publish@release/v1
28+
- name: Upload package to PyPI
29+
run: |
30+
python -m twine upload -r pypi dist/* --verbose

pyproject.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "Cython"]
2+
requires = ["setuptools>=42", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "tda-mapper"
7-
version = "0.7.1"
7+
version = "0.7.2"
88
description = "A simple and efficient Python implementation of Mapper algorithm for Topological Data Analysis"
99
readme = "README.md"
1010
authors = [{ name = "Luca Simi", email = "lucasimi90@gmail.com" }]
@@ -19,10 +19,11 @@ keywords = ["tda", "mapper", "topology", "topological data analysis"]
1919
dependencies = [
2020
"matplotlib>=3.3.4",
2121
"networkx>=2.5",
22+
"numba>=0.54",
2223
"numpy>=1.20.1, <2.0.0",
2324
"plotly>=4.14.3"
2425
]
25-
requires-python = ">=3.7"
26+
requires-python = ">=3.6"
2627

2728
[project.optional-dependencies]
2829
dev = ["coverage", "pandas", "scikit-learn"]
@@ -31,9 +32,3 @@ dev = ["coverage", "pandas", "scikit-learn"]
3132
Homepage = "https://github.com/lucasimi/tda-mapper-python"
3233
Documentation = "https://tda-mapper.readthedocs.io"
3334
Issues = "https://github.com/lucasimi/tda-mapper-python/issues"
34-
35-
[tool.setuptools.package-data]
36-
"tdamapper.utils" = ["_metrics.c", "_metrics.pyx"]
37-
38-
[tool.cibuildwheel]
39-
skip = "cp36-*"

setup.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/tdamapper/utils/_metrics.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
from numba import njit
3+
4+
5+
@njit(fastmath=True)
6+
def euclidean(x, y):
7+
return np.linalg.norm(x - y)
8+
9+
10+
@njit(fastmath=True)
11+
def manhattan(x, y):
12+
return np.linalg.norm(x - y, ord=1)
13+
14+
15+
16+
@njit(fastmath=True)
17+
def chebyshev(x, y):
18+
return np.linalg.norm(x - y, ord=np.inf)
19+
20+
21+
@njit(fastmath=True)
22+
def minkowski(p, x, y):
23+
return np.linalg.norm(x - y, ord=p)
24+
25+
26+
@njit(fastmath=True)
27+
def cosine(x, y):
28+
xy = np.dot(x, y)
29+
xx = np.linalg.norm(x)
30+
yy = np.linalg.norm(y)
31+
similarity = xy / (xx * yy)
32+
return np.sqrt(2.0 * (1.0 - similarity))

src/tdamapper/utils/_metrics.pyx

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)