Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cython handling of 0-length arrays feels awkward #105

Open
ajfriend opened this issue May 10, 2020 · 1 comment
Open

Cython handling of 0-length arrays feels awkward #105

ajfriend opened this issue May 10, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@ajfriend
Copy link
Contributor

See: #99 (comment)

@ajfriend ajfriend added the enhancement New feature or request label May 29, 2020
@ajfriend
Copy link
Contributor Author

ajfriend commented Jun 5, 2020

h3-py/src/h3/_cy/cells.pyx

Lines 178 to 197 in 72db3f7

cpdef H3int[:] compact(const H3int[:] hu):
# todo: the Clib can handle 0-len arrays because it **avoids**
# dereferencing the pointer, but Cython's syntax of
# `&hu[0]` **requires** a dereference. For Cython, checking for array
# length of zero and returning early seems like the easiest solution.
# note: open to better ideas!
if len(hu) == 0:
return empty_memory_view()
for h in hu: ## todo: should we have an array version? would that be faster?
check_cell(h)
ptr = create_ptr(len(hu))
flag = h3lib.compact(&hu[0], ptr, len(hu))
mv = create_mv(ptr, len(hu))
if flag != 0:
raise H3ValueError('Could not compact set of hexagons!')
return mv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant