-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose cython API for external use (#234)
* Expose cython API for internal use * fix typeo * Expose Cython API for external use * Add Cython test * Install cython in tests * fix syntax for 2.7 and 3.5 * Fix lint check * Call pytest on directory * Build cython test in coverage-lint * Only run cython test if import succeeds * No bare except
- Loading branch information
1 parent
3d09da1
commit f59a1ea
Showing
9 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,10 @@ jobs: | |
run: pylint --disable=all --enable=import-error tests/ | ||
|
||
- name: Coverage | ||
run: pytest --cov=h3 --full-trace --cov-report=xml | ||
run: | | ||
pip install Cython | ||
cythonize -i tests/cython_example.pyx | ||
pytest --cov=h3 --full-trace --cov-report=xml | ||
- name: Upload coverage to Codecov | ||
uses: codecov/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ h3c/ | |
.cache/ | ||
h3/out/ | ||
|
||
# Generated C code from Cython test | ||
tests/*.c | ||
# Cython HTML annotations | ||
*.html | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from cython cimport boundscheck, wraparound | ||
|
||
from h3._cy.h3lib cimport H3int | ||
from h3._cy.geo cimport geo_to_h3 | ||
|
||
@boundscheck(False) | ||
@wraparound(False) | ||
cpdef void geo_to_h3_vect( | ||
const double[:] lat, | ||
const double[:] lng, | ||
int res, | ||
H3int[:] out | ||
): | ||
|
||
cdef Py_ssize_t i | ||
|
||
for i in range(len(lat)): | ||
out[i] = geo_to_h3(lat[i], lng[i], res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import numpy as np | ||
|
||
# Avoid checking for import-error here because cython_example may not have | ||
# been compiled yet. | ||
try: | ||
from .cython_example import geo_to_h3_vect # pylint: disable=import-error | ||
except ImportError: | ||
geo_to_h3_vect = None | ||
|
||
np.random.seed(0) | ||
|
||
|
||
def test_cython_api(): | ||
if geo_to_h3_vect is None: | ||
print("Not running Cython test because cython example was not compiled") | ||
return | ||
|
||
N = 100000 | ||
|
||
lats, lngs = np.random.uniform(0, 90, N), np.random.uniform(0, 90, N) | ||
res = 9 | ||
|
||
lats = np.array(lats, dtype=np.float64) | ||
lngs = np.array(lngs, dtype=np.float64) | ||
out = np.zeros(len(lats), dtype="uint64") | ||
geo_to_h3_vect(lats, lngs, res, out) | ||
|
||
assert out[0] == 617284541015654399 |