当前位置: 首页>>代码示例>>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;未经允许,请勿转载。