本文整理汇总了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)