本文整理匯總了Python中numba.jitclass方法的典型用法代碼示例。如果您正苦於以下問題:Python numba.jitclass方法的具體用法?Python numba.jitclass怎麽用?Python numba.jitclass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numba
的用法示例。
在下文中一共展示了numba.jitclass方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: simplify_geometry
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jitclass [as 別名]
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)