Python numba.jitclass() Examples
The following are 1
code examples of numba.jitclass().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numba
, or try the search function
.
Example #1
Source File: geojson.py From cate with MIT License | 4 votes |
def simplify_geometry(x_data: np.ndarray, y_data: np.ndarray, conservation_ratio: float) \ -> Tuple[np.ndarray, np.ndarray]: """ Simplify a ring or line-string given by its coordinates *x_data* and *y_data* from *x_data.size* points to int(*conservation_ratio* * *x_data*.size + 0.5) points. A ring is detected by same start and end points. The first and last coordinates will always be maintained therefore the minimum number of resulting points is 3 for rings and 2 for line-strings. :param x_data: The x coordinates. :param y_data: The x coordinates. :param conservation_ratio: The ratio of coordinates to be conserved, 0 <= *conservation_ratio* <= 1. :return: A pair comprising the simplified *x_data* and *y_data*. """ is_ring = x_data[0] == x_data[-1] and y_data[0] == y_data[-1] old_point_count = int(x_data.size) new_point_count = int(conservation_ratio * old_point_count + 0.5) min_point_count = 4 if is_ring else 2 if new_point_count < min_point_count: new_point_count = min_point_count if old_point_count <= new_point_count: return x_data, y_data point_heap = PointHeap(x_data, y_data) while point_heap.size > new_point_count: point_heap.pop() new_x_data = np.zeros(new_point_count, dtype=x_data.dtype) new_y_data = np.zeros(new_point_count, dtype=y_data.dtype) point = point_heap.first_point i = 0 while point is not None: index = point[1] new_x_data[i] = x_data[index] new_y_data[i] = y_data[index] point = point[3] i += 1 return new_x_data, new_y_data # TODO (forman): Optimize me! # This is an non-optimised version of PointHeap for testing only. # It uses the pure Python heapq implementation of a min-heap. # We should ASAP replace heapq by the jit-compiled cate.webapi.minheap implementation # so that we can compile the PointHeap class using @numba.jitclass(). # See http://numba.pydata.org/numba-doc/dev/user/jitclass.html # PointHeapSpec = [ # ('_x_data', np.float64[:]), # ('_y_data', np.float64[:]), # ('_point_heap', np.int64[:]), # ('_size', np.int64), # ] # @numba.jitclass(PointHeapSpec)