當前位置: 首頁>>代碼示例>>Python>>正文


Python numba.f8方法代碼示例

本文整理匯總了Python中numba.f8方法的典型用法代碼示例。如果您正苦於以下問題:Python numba.f8方法的具體用法?Python numba.f8怎麽用?Python numba.f8使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numba的用法示例。


在下文中一共展示了numba.f8方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: all_the_same

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def all_the_same(pointer, length, id_list):
    """
    :param pointer: starting from that element the list is being checked for equality of its elements
    :param length:
    :param id_list: List mustn't be empty or Null. There has to be at least one element
    :return: returns the first encountered element if starting from the pointer all elements are the same,
     otherwise it returns -1
    """
    element = id_list[pointer]
    pointer += 1
    while pointer < length:
        if element != id_list[pointer]:
            return -1
        pointer += 1
    return element


# @cc.export('cartesian2rad', dtype_2float_tuple(f8, f8, f8)) 
開發者ID:MrMinimal64,項目名稱:timezonefinder,代碼行數:20,代碼來源:helpers_numba.py

示例2: rolling_min_1d_nb

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def rolling_min_1d_nb(a, window, minp=None):
    """Return rolling min.

    Numba equivalent to `pd.Series(a).rolling(window, min_periods=minp).min()`."""
    if minp is None:
        minp = window
    if minp > window:
        raise Exception("minp must be <= window")
    result = np.empty_like(a, dtype=f8)
    for i in range(a.shape[0]):
        minv = a[i]
        cnt = 0
        for j in range(max(i-window+1, 0), i+1):
            if np.isnan(a[j]):
                continue
            if np.isnan(minv) or a[j] < minv:
                minv = a[j]
            cnt += 1
        if cnt < minp:
            result[i] = np.nan
        else:
            result[i] = minv
    return result 
開發者ID:polakowo,項目名稱:vectorbt,代碼行數:25,代碼來源:nb.py

示例3: rolling_max_1d_nb

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def rolling_max_1d_nb(a, window, minp=None):
    """Return rolling max.

    Numba equivalent to `pd.Series(a).rolling(window, min_periods=minp).max()`."""
    if minp is None:
        minp = window
    if minp > window:
        raise Exception("minp must be <= window")
    result = np.empty_like(a, dtype=f8)
    for i in range(a.shape[0]):
        maxv = a[i]
        cnt = 0
        for j in range(max(i-window+1, 0), i+1):
            if np.isnan(a[j]):
                continue
            if np.isnan(maxv) or a[j] > maxv:
                maxv = a[j]
            cnt += 1
        if cnt < minp:
            result[i] = np.nan
        else:
            result[i] = maxv
    return result 
開發者ID:polakowo,項目名稱:vectorbt,代碼行數:25,代碼來源:nb.py

示例4: expanding_min_1d_nb

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def expanding_min_1d_nb(a, minp=1):
    """Return expanding min.

    Numba equivalent to `pd.Series(a).expanding(min_periods=minp).min()`."""
    result = np.empty_like(a, dtype=f8)
    minv = a[0]
    cnt = 0
    for i in range(a.shape[0]):
        if np.isnan(minv) or a[i] < minv:
            minv = a[i]
        if ~np.isnan(a[i]):
            cnt += 1
        if cnt < minp:
            result[i] = np.nan
        else:
            result[i] = minv
    return result 
開發者ID:polakowo,項目名稱:vectorbt,代碼行數:19,代碼來源:nb.py

示例5: describe_reduce_nb

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def describe_reduce_nb(col, a, percentiles, ddof):
    """Return descriptive statistics.

    Numba equivalent to `pd.Series(a).describe(percentiles)`."""
    a = a[~np.isnan(a)]
    result = np.empty(5 + len(percentiles), dtype=f8)
    result[0] = len(a)
    if len(a) > 0:
        result[1] = np.mean(a)
        result[2] = nanstd_1d_nb(a, ddof=ddof)
        result[3] = np.min(a)
        result[4:-1] = np.percentile(a, percentiles * 100)
        result[4+len(percentiles)] = np.max(a)
    else:
        result[1:] = np.nan
    return result 
開發者ID:polakowo,項目名稱:vectorbt,代碼行數:18,代碼來源:nb.py

示例6: map_reduce_between_two_nb

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def map_reduce_between_two_nb(a, b, map_func_nb, reduce_func_nb, *args):
    """Map using `map_func_nb` and reduce using `reduce_func_nb` each consecutive 
    pair of `True` values between `a` and `b`.

    Iterates over `b`, and for each found `True` value, looks for the preceding `True` value in `a`.

    `map_func_nb` and `reduce_func_nb` are same as for `map_reduce_between_nb`."""
    result = np.full((a.shape[1],), np.nan, dtype=f8)

    for col in range(a.shape[1]):
        a_idxs = np.flatnonzero(a[:, col])
        if a_idxs.shape[0] > 0:
            b_idxs = np.flatnonzero(b[:, col])
            if b_idxs.shape[0] > 0:
                map_res = np.empty(b_idxs.shape)
                k = 0
                for j, to_i in enumerate(b_idxs):
                    valid_a_idxs = a_idxs[a_idxs < to_i]
                    if len(valid_a_idxs) > 0:
                        from_i = valid_a_idxs[-1]  # preceding in a
                        map_res[k] = map_func_nb(col, from_i, to_i, *args)
                        k += 1
                if k > 0:
                    result[col] = reduce_func_nb(col, map_res[:k], *args)
    return result 
開發者ID:polakowo,項目名稱:vectorbt,代碼行數:27,代碼來源:nb.py

示例7: reduce_records_nb

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def reduce_records_nb(records, n_cols, default_val, reduce_func_nb, *args):
    """Reduce records by column.

    Faster than `map_records_to_matrix_nb` and `vbt.tseries.*` used together, and also
    requires less memory. But does not take advantage of caching.

    `reduce_func_nb` must accept an array of records and `*args`, and return a single value."""
    result = np.full(n_cols, default_val, dtype=f8)
    from_r = 0
    col = -1
    for r in range(records.shape[0]):
        record_col = records['col'][r]
        if record_col != col:
            if col != -1:
                # At the beginning of second column do reduce on the first
                result[col] = reduce_func_nb(records[from_r:r], *args)
            from_r = r
            col = record_col
        if r == len(records) - 1:
            result[col] = reduce_func_nb(records[from_r:r + 1], *args)
    return result 
開發者ID:polakowo,項目名稱:vectorbt,代碼行數:23,代碼來源:nb.py

示例8: cartesian2rad

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def cartesian2rad(x, y, z):
    return atan2(y, x), asin(z)


# @cc.export('cartesian2coords', dtype_2float_tuple(f8, f8, f8)) 
開發者ID:MrMinimal64,項目名稱:timezonefinder,代碼行數:7,代碼來源:helpers_numba.py

示例9: cartesian2coords

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def cartesian2coords(x, y, z):
    return degrees(atan2(y, x)), degrees(asin(z))


# @cc.export('x_rotate', dtype_3float_tuple(f8, dtype_3float_tuple)) 
開發者ID:MrMinimal64,項目名稱:timezonefinder,代碼行數:7,代碼來源:helpers_numba.py

示例10: x_rotate

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def x_rotate(rad, point):
    # Attention: this rotation uses radians!
    # x stays the same
    sin_rad = sin(rad)
    cos_rad = cos(rad)
    return point[0], point[1] * cos_rad + point[2] * sin_rad, point[2] * cos_rad - point[1] * sin_rad


# @cc.export('y_rotate', dtype_3float_tuple(f8, dtype_3float_tuple)) 
開發者ID:MrMinimal64,項目名稱:timezonefinder,代碼行數:11,代碼來源:helpers_numba.py

示例11: y_rotate

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def y_rotate(rad, point):
    # y stays the same
    # this is actually a rotation with -rad (use symmetry of sin/cos)
    sin_rad = sin(rad)
    cos_rad = cos(rad)
    return point[0] * cos_rad + point[2] * sin_rad, point[1], point[2] * cos_rad - point[0] * sin_rad


# @cc.export('coords2cartesian', dtype_3float_tuple(f8, f8)) 
開發者ID:MrMinimal64,項目名稱:timezonefinder,代碼行數:11,代碼來源:helpers_numba.py

示例12: distance_to_point_on_equator

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def distance_to_point_on_equator(lng_rad, lat_rad, lng_rad_p1):
    """
    uses the simplified haversine formula for this special case (lat_p1 = 0)
    :param lng_rad: the longitude of the point in radians
    :param lat_rad: the latitude of the point
    :param lng_rad_p1: the latitude of the point1 on the equator (lat=0)
    :return: distance between the point and p1 (lng_rad_p1,0) in km
    this is only an approximation since the earth is not a real sphere
    """
    # 2* for the distance in rad and * 12742 (mean diameter of earth) for the distance in km
    return 12742 * asin(sqrt(((sin(lat_rad / 2)) ** 2 + cos(lat_rad) * (sin((lng_rad - lng_rad_p1) / 2)) ** 2)))


# @cc.export('haversine', f8(f8, f8, f8, f8)) 
開發者ID:MrMinimal64,項目名稱:timezonefinder,代碼行數:16,代碼來源:helpers_numba.py

示例13: haversine

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def haversine(lng_p1, lat_p1, lng_p2, lat_p2):
    """
    :param lng_p1: the longitude of point 1 in radians
    :param lat_p1: the latitude of point 1 in radians
    :param lng_p2: the longitude of point 1 in radians
    :param lat_p2: the latitude of point 1 in radians
    :return: distance between p1 and p2 in km
    this is only an approximation since the earth is not a real sphere
    """
    # 2* for the distance in rad and * 12742(mean diameter of earth) for the distance in km
    return 12742 * asin(
        sqrt(((sin((lat_p1 - lat_p2) / 2)) ** 2 + cos(lat_p2) * cos(lat_p1) * (sin((lng_p1 - lng_p2) / 2)) ** 2)))


# @cc.export('compute_min_distance', f8(f8, f8, f8, f8, f8, f8, f8, f8)) 
開發者ID:MrMinimal64,項目名稱:timezonefinder,代碼行數:17,代碼來源:helpers_numba.py

示例14: int2coord

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def int2coord(i4):
    return float(i4 * INT2COORD_FACTOR)


# @cc.export('coord2int', i4(f8)) 
開發者ID:MrMinimal64,項目名稱:timezonefinder,代碼行數:7,代碼來源:helpers_numba.py

示例15: coord2int

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import f8 [as 別名]
def coord2int(double):
    return int(double * COORD2INT_FACTOR)


# @cc.export('distance_to_polygon_exact', f8(f8, f8, i4, i4[:, :], f8[:, :])) 
開發者ID:MrMinimal64,項目名稱:timezonefinder,代碼行數:7,代碼來源:helpers_numba.py


注:本文中的numba.f8方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。