Skip to content

Commit fc969a8

Browse files
committed
fixing cpp names camelCase + adding wheel actions
1 parent fa39c09 commit fc969a8

File tree

5 files changed

+274
-12
lines changed

5 files changed

+274
-12
lines changed

.github/workflows/publish_pypi.yml

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Build wheel
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types:
7+
- published
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build_wheels:
14+
name: Build wheel for ${{ matrix.python }}-${{ matrix.buildplat[1] }}
15+
runs-on: ${{ matrix.buildplat[0] }}
16+
strategy:
17+
matrix:
18+
# From wheel.yml of numpy (https://github.com/numpy/numpy/blob/main/.github/workflows/wheels.yml):
19+
# Github Actions doesn't support pairing matrix values together, let's improvise
20+
# https://github.com/github/feedback/discussions/7835#discussioncomment-1769026
21+
buildplat:
22+
- [ubuntu-22.04, manylinux_x86_64]
23+
- [ubuntu-22.04, musllinux_x86_64]
24+
- [ubuntu-22.04, manylinux_aarch64]
25+
- [ubuntu-22.04, musllinux_aarch64]
26+
- [macos-12, macosx_x86_64]
27+
- [macos-12, macosx_arm64]
28+
- [windows-2022, win_amd64]
29+
- [windows-2022, win32]
30+
python: ["cp38", "cp39", "cp310", "cp311", "cp312", "pp39"]
31+
exclude:
32+
- buildplat: [windows-2022, win32]
33+
python: "pp39"
34+
- buildplat: [ ubuntu-22.04, musllinux_x86_64 ]
35+
python: "pp39"
36+
- buildplat: [ ubuntu-22.04, musllinux_aarch64 ]
37+
python: "pp39"
38+
- buildplat: [macos-12, macosx_arm64]
39+
python: "pp39"
40+
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
with:
45+
submodules: recursive
46+
47+
- name: Set up QEMU
48+
if: ${{ contains(matrix.buildplat[1], 'linux_aarch64') }}
49+
uses: docker/setup-qemu-action@v3
50+
with:
51+
platforms: all
52+
53+
- name: Setup MSVC (32-bit)
54+
if: ${{ matrix.buildplat[1] == 'win32' }}
55+
uses: bus1/cabuild/action/msdevshell@e22aba57d6e74891d059d66501b6b5aed8123c4d # v1
56+
with:
57+
architecture: 'x86'
58+
59+
- name: Build wheels for manylinux x86_64
60+
if: ${{ matrix.buildplat[1] == 'manylinux_x86_64' }}
61+
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
62+
env:
63+
CIBW_PRERELEASE_PYTHONS: True
64+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
65+
CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64
66+
CIBW_ARCHS: 'all'
67+
68+
- name: Build wheels for manylinux aarch64
69+
if: ${{ matrix.buildplat[1] == 'manylinux_aarch64' }}
70+
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
71+
env:
72+
CIBW_PRERELEASE_PYTHONS: True
73+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
74+
CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64
75+
CIBW_ARCHS: 'all'
76+
77+
- name: Build wheels for musllinux x86_64
78+
if: ${{ matrix.buildplat[1] == 'musllinux_x86_64' }}
79+
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
80+
env:
81+
CIBW_PRERELEASE_PYTHONS: True
82+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
83+
CIBW_MUSLLINUX_X86_64_IMAGE: quay.io/pypa/musllinux_1_2_x86_64
84+
CIBW_ARCHS: 'all'
85+
86+
- name: Build wheels for musllinux aarch64
87+
if: ${{ matrix.buildplat[1] == 'musllinux_aarch64' }}
88+
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
89+
env:
90+
CIBW_PRERELEASE_PYTHONS: True
91+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
92+
CIBW_MUSLLINUX_AARCH64_IMAGE: quay.io/pypa/musllinux_1_2_aarch64
93+
CIBW_ARCHS: 'all'
94+
95+
- name: Build wheels
96+
if: ${{ !contains(matrix.buildplat[1], 'linux') }}
97+
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
98+
env:
99+
CIBW_PRERELEASE_PYTHONS: True
100+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
101+
CIBW_ARCHS: 'all'
102+
103+
- uses: actions/upload-artifact@v3
104+
with:
105+
path: ./wheelhouse/*.whl
106+
107+
build_sdist:
108+
name: Build source distribution
109+
runs-on: ubuntu-latest
110+
steps:
111+
- name: Checkout
112+
uses: actions/checkout@v4
113+
with:
114+
submodules: recursive
115+
116+
- name: Build sdist
117+
run: pipx run build --sdist
118+
119+
- uses: actions/upload-artifact@v3
120+
with:
121+
path: dist/*.tar.gz
122+
123+
upload_pypi:
124+
needs: [build_wheels, build_sdist]
125+
runs-on: ubuntu-latest
126+
environment:
127+
name: pypi
128+
url: https://pypi.org/p/lcsvec
129+
permissions:
130+
id-token: write
131+
steps:
132+
- uses: actions/download-artifact@v3
133+
with:
134+
# unpacks default artifact into dist/
135+
# if `name: artifact` is omitted, the action will create extra parent dir
136+
name: artifact
137+
path: dist
138+
139+
- uses: pypa/gh-action-pypi-publish@release/v1
140+
#with:
141+
# To test: repository-url: https://test.pypi.org/legacy/

.github/workflows/test_wheel.yml

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Test build wheel
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
build_wheels:
12+
name: Build wheel for ${{ matrix.python }}-${{ matrix.buildplat[1] }}
13+
runs-on: ${{ matrix.buildplat[0] }}
14+
strategy:
15+
matrix:
16+
# From wheel.yml of numpy (https://github.com/numpy/numpy/blob/main/.github/workflows/wheels.yml):
17+
# Github Actions doesn't support pairing matrix values together, let's improvise
18+
# https://github.com/github/feedback/discussions/7835#discussioncomment-1769026
19+
buildplat:
20+
- [ubuntu-22.04, manylinux_x86_64]
21+
- [ubuntu-22.04, musllinux_x86_64]
22+
- [ubuntu-22.04, manylinux_aarch64]
23+
- [ubuntu-22.04, musllinux_aarch64]
24+
- [macos-12, macosx_x86_64]
25+
- [macos-12, macosx_arm64]
26+
- [windows-2022, win_amd64]
27+
- [windows-2022, win32]
28+
python: ["cp38", "cp39", "cp310", "cp311", "cp312", "pp39"]
29+
exclude:
30+
- buildplat: [windows-2022, win32]
31+
python: "pp39"
32+
- buildplat: [ ubuntu-22.04, musllinux_x86_64 ]
33+
python: "pp39"
34+
- buildplat: [ ubuntu-22.04, musllinux_aarch64 ]
35+
python: "pp39"
36+
- buildplat: [macos-12, macosx_arm64]
37+
python: "pp39"
38+
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
with:
43+
submodules: recursive
44+
45+
- name: Set up QEMU
46+
if: ${{ contains(matrix.buildplat[1], 'linux_aarch64') }}
47+
uses: docker/setup-qemu-action@v3
48+
with:
49+
platforms: all
50+
51+
- name: Setup MSVC (32-bit)
52+
if: ${{ matrix.buildplat[1] == 'win32' }}
53+
uses: bus1/cabuild/action/msdevshell@e22aba57d6e74891d059d66501b6b5aed8123c4d # v1
54+
with:
55+
architecture: 'x86'
56+
57+
- name: Build wheels for manylinux x86_64
58+
if: ${{ matrix.buildplat[1] == 'manylinux_x86_64' }}
59+
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
60+
env:
61+
CIBW_PRERELEASE_PYTHONS: True
62+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
63+
CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64
64+
CIBW_ARCHS: 'all'
65+
66+
- name: Build wheels for manylinux aarch64
67+
if: ${{ matrix.buildplat[1] == 'manylinux_aarch64' }}
68+
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
69+
env:
70+
CIBW_PRERELEASE_PYTHONS: True
71+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
72+
CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64
73+
CIBW_ARCHS: 'all'
74+
75+
- name: Build wheels for musllinux x86_64
76+
if: ${{ matrix.buildplat[1] == 'musllinux_x86_64' }}
77+
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
78+
env:
79+
CIBW_PRERELEASE_PYTHONS: True
80+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
81+
CIBW_MUSLLINUX_X86_64_IMAGE: quay.io/pypa/musllinux_1_2_x86_64
82+
CIBW_ARCHS: 'all'
83+
84+
- name: Build wheels for musllinux aarch64
85+
if: ${{ matrix.buildplat[1] == 'musllinux_aarch64' }}
86+
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
87+
env:
88+
CIBW_PRERELEASE_PYTHONS: True
89+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
90+
CIBW_MUSLLINUX_AARCH64_IMAGE: quay.io/pypa/musllinux_1_2_aarch64
91+
CIBW_ARCHS: 'all'
92+
93+
- name: Build wheels
94+
if: ${{ !contains(matrix.buildplat[1], 'linux') }}
95+
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
96+
env:
97+
CIBW_PRERELEASE_PYTHONS: True
98+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
99+
CIBW_ARCHS: 'all'
100+
101+
- uses: actions/upload-artifact@v4
102+
with:
103+
name: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
104+
path: ./wheelhouse/*.whl
105+
106+
build_sdist:
107+
name: Build source distribution
108+
runs-on: ubuntu-latest
109+
steps:
110+
- name: Checkout
111+
uses: actions/checkout@v4
112+
with:
113+
submodules: recursive
114+
115+
- name: Build sdist
116+
run: pipx run build --sdist
117+
118+
- uses: actions/upload-artifact@v3
119+
with:
120+
path: dist/*.tar.gz

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ You can install the package with pip: `pip install lcsvec`.
2121
Here we will use numpy, the usage for other deep learning libraries is the same.
2222

2323
```Python
24-
from lcsvec import lcs, lcs_length, lccs_length
24+
from lcsvec import lccs, lccs_length, lcs, lcs_length
2525
import numpy as np
2626

2727
seq1 = np.arange(0, 12)
@@ -30,7 +30,8 @@ seq2 = np.array([8, 0, 1, 2, 8, 2, 3, 4, 5, 6], dtype=np.int64)
3030
lcs_ = lcs(seq1, seq2) # [0, 1, 2, 3, 4, 5, 6]
3131
lcs_len = lcs_length(seq1, seq2) # 7, more efficient than calling len(lcs(seq1, seq2))
3232

33-
lccs_len = lccs_length(seq1, seq2) # 5, [2, 3, 4, 5, 6]
33+
lccs = lccs(seq1, seq2) # [2, 3, 4, 5, 6]
34+
lccs_len = lccs_length(seq1, seq2) # 5, more efficient than calling len(lccs(seq1, seq2))
3435
```
3536

3637
## TODOs

src/cpu/lccs_cpu_dyn.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using namespace nb::literals;
77

88

99
// Returns the length of the longest common subsequence and the idx of its end in s1
10-
std::vector<int> lccs_length_idx(
10+
std::vector<int> lccsLengthIdx(
1111
const nb::ndarray<double, nb::ndim<1>>& s1,
1212
const nb::ndarray<double, nb::ndim<1>>& s2
1313
) {
@@ -33,18 +33,18 @@ std::vector<int> lccs_length_idx(
3333
}
3434
}
3535
}
36-
std::vector<int> lccs_len_idx = {max_length, imax};
37-
return lccs_len_idx;
36+
std::vector<int> lccsLenIdx = {max_length, imax};
37+
return lccsLenIdx;
3838
}
3939

4040

4141
// Calculating the length of the longest common contiguous subsequence with dynamic programming
42-
int lccs_length(
42+
int lccsLength(
4343
const nb::ndarray<double, nb::ndim<1>>& s1,
4444
const nb::ndarray<double, nb::ndim<1>>& s2
4545
) {
46-
std::vector<int> lccs_len_idx = lccs_length_idx(s1, s2);
47-
return lccs_len_idx[0];
46+
std::vector<int> lccsLenIdx = lccsLengthIdx(s1, s2);
47+
return lccsLenIdx[0];
4848
}
4949

5050

@@ -53,12 +53,12 @@ std::vector<int> lccs(
5353
const nb::ndarray<double, nb::ndim<1>>& s1,
5454
const nb::ndarray<double, nb::ndim<1>>& s2
5555
) {
56-
std::vector<int> lccs_len_idx = lccs_length_idx(s1, s2);
56+
std::vector<int> lccsLenIdx = lccsLengthIdx(s1, s2);
5757

5858
// Extract the longest common substring from s1
59-
std::vector<int> longestSubseq(lccs_len_idx[0]);
59+
std::vector<int> longestSubseq(lccsLenIdx[0]);
6060
int idx = 0;
61-
for (int i = lccs_len_idx[1] - lccs_len_idx[0] + 1; i <= lccs_len_idx[1]; ++i)
61+
for (int i = lccsLenIdx[1] - lccsLenIdx[0] + 1; i <= lccsLenIdx[1]; ++i)
6262
longestSubseq[idx++] = s1(i);
6363

6464
return longestSubseq;

src/lcs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ NB_MODULE(lcsvec_ext, m) {
1515

1616
m.def("lccs", &lccs, "seq1"_a, "seq2"_a,
1717
"Returns the longest common contiguous subsequence (lccs) from `seq1` and `seq2`.");
18-
m.def("lccs_length", &lccs_length, "seq1"_a, "seq2"_a,
18+
m.def("lccs_length", &lccsLength, "seq1"_a, "seq2"_a,
1919
"Returns the length of the longest common contiguous subsequence (lccs) from `seq1` and `seq2`.");
2020
}

0 commit comments

Comments
 (0)