urschrei / simplification

Very fast Python line simplification using either the RDP or Visvalingam-Whyatt algorithm implemented in Rust
Other
168 stars 18 forks source link

Don't require numpy #24

Closed utapyngo closed 2 years ago

utapyngo commented 2 years ago

Is there a way to make the numpy dependency optional? As far as I understand, the algorithm itself is implemented in Rust, and numpy is required just to make it possible to pass numpy arrays to simplify_coords() and return them back. numpy is a heavyweight library, and I don't want my project to depend on it.

urschrei commented 2 years ago

Most users' geospatial stacks require at least one other library with a numpy dependency, or numpy itself. I'm happy to look at a PR that makes it optional, but I won't be implementing this myself.

utapyngo commented 2 years ago

I can imagine a separate library without this requirement, but is it possible to make numpy optional?

utapyngo commented 2 years ago

@urschrei I could try, but I am not good at Cython. These lines look too cryptic to me:

cdef double[:,::1] ncoords = np.array(arr, dtype=np.float64)

cdef double[:, ::1] view = <double[:result.len,:2:1]>incoming_ptr

Could you please give me a link to the docs explaining this?

Google gives this but two-dimensional arrays are not mentioned there.

urschrei commented 2 years ago

That's typed memoryview syntax: https://cython.readthedocs.io/en/latest/src/userguide/memoryviews.html

The syntax is described here: https://cython.readthedocs.io/en/stable/src/userguide/memoryviews.html#specifying-more-general-memory-layouts

And the array syntax here: https://cython.readthedocs.io/en/stable/src/userguide/memoryviews.html#cython-arrays

e.g. The ::1 means that the memory is contiguous.

utapyngo commented 2 years ago

Thank you @urschrei I have created a draft PR #25, please take a look.

urschrei commented 2 years ago

Released to PyPI: https://pypi.org/project/simplification/0.6.0/

Sorry about the delay, and thanks for the contribution!