Skip to content

Commit

Permalink
Add cython bindings to cuproj
Browse files Browse the repository at this point in the history
  • Loading branch information
isVoid committed Jul 13, 2023
1 parent 2d5e228 commit 28fefc1
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/cuproj/cuproj/_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# =============================================================================

set(cython_sources
transform.pyx)

)
set(linked_libraries cuproj::cuproj)

rapids_cython_create_modules(
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions python/cuproj/cuproj/_lib/cpp/ellipsoid.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cdef extern from "cuproj/ellipsoid.hpp" namespace "cuproj" nogil:
cdef cppclass ellipsoid[T]:
ellipsoid() except+
ellipsoid(T, T) except+
12 changes: 12 additions & 0 deletions python/cuproj/cuproj/_lib/cpp/operation.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

cdef extern from "cuproj/operation/operation.cuh" namespace "cuproj" nogil:
cdef enum operation_type:
AXIS_SWAP = 0
DEGREES_TO_RADIANS = 1
CLAMP_ANGULAR_COORDINATES = 2
OFFSET_SCALE_CARTESIAN_COORDINATES = 3
TRANSVERSE_MERCATOR = 4

cdef enum direction:
FORWARD = 0
INVERSE = 1
13 changes: 9 additions & 4 deletions python/cuproj/cuproj/_lib/cpp/projection.pxd
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from cuproj._lib.cpp.operation cimport operation_type, direction
from cuproj._lib.cpp.projection_parameters cimport projection_parameters

from libcpp.vector cimport vector

cdef extern from "cuproj/projection.cuh" namespace "cuproj" nogil:
cdef cppclass projection[Coordinate]:
projection(# vector of operation_type
# projection parameters
# constructed direction)
cdef cppclass projection[Coordinate, T=*]:
projection()
projection(vector[operation_type],
projection_parameters[T],
direction=direction.FORWARD)

void transform[CoordIter](CoordIter, CoordIter, CoordIter, direction)
8 changes: 8 additions & 0 deletions python/cuproj/cuproj/_lib/cpp/projection_factories.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from cuproj._lib.cpp.projection cimport projection

from libcpp.string cimport string

cdef extern from "cuproj/projection_factories.hpp" namespace "cuproj" nogil:
projection[Coordinate] make_projection[Coordinate](
string, string
)
15 changes: 15 additions & 0 deletions python/cuproj/cuproj/_lib/cpp/projection_parameters.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from cuproj._lib.cpp.ellipsoid cimport ellipsoid

cdef extern from "cuproj/projection_parameters.hpp" namespace "cuproj" nogil:
cdef enum hemisphere:
NORTH = 0
SOUTH = 1

cdef cppclass projection_parameters[T]:
projection_parameters(
ellipsoid[T],
int,
hemisphere,
T,
T
) except+
28 changes: 28 additions & 0 deletions python/cuproj/cuproj/_lib/transform.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import cupy as cp

from cuproj._lib.cpp.projection cimport projection
from cuproj._lib.cpp.projection_factories cimport make_projection
from cuproj._lib.cpp.operation cimport direction

def wgs84_to_utm(srcarr):
result = cp.array(srcarr.shape, dtype=cp.float64)
cdef projection[double] proj = make_projection[double](
b"epsg:4326", b"epsg:32633"
)

srcarr_data = cp.ascontiguousarray(srcarr, dtype=cp.float64)
result_data = cp.ascontiguousarray(result, dtype=cp.float64)

cdef double[::1] srcarr_arr_memview = srcarr_data
cdef int size = srcarr_data.shape[0]
cdef double[::1] result_arr_memview = result_data

with nogil:
proj.transform(
&srcarr_arr_memview[0],
&srcarr_arr_memview[0] + size,
&result_arr_memview[0],
direction.FORWARD
)

return result

0 comments on commit 28fefc1

Please sign in to comment.