本文整理汇总了Python中numba.int64方法的典型用法代码示例。如果您正苦于以下问题:Python numba.int64方法的具体用法?Python numba.int64怎么用?Python numba.int64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numba
的用法示例。
在下文中一共展示了numba.int64方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: map_neighbors
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int64 [as 别名]
def map_neighbors(indices, similarity, labels, top_k, pad_ind, pad_val):
m = indices.shape[0]
point_labels = np.full(
(m, top_k), pad_ind, dtype=np.int64)
point_label_sims = np.full(
(m, top_k), pad_val, dtype=np.float32)
for i in nb.prange(m):
unique_point_labels, point_label_sim = map_one(
labels[indices[i]], similarity[i], pad_ind)
if top_k < len(unique_point_labels):
top_indices = np.argsort(
point_label_sim)[-1 * top_k:][::-1]
point_labels[i] = unique_point_labels[top_indices]
point_label_sims[i] = point_label_sim[top_indices]
else:
point_labels[i, :len(unique_point_labels)] = unique_point_labels
point_label_sims[i, :len(unique_point_labels)] = point_label_sim
return point_labels, point_label_sims
示例2: ij_bbox
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int64 [as 别名]
def ij_bbox(self,
xy_bbox: Tuple[float, float, float, float],
xy_border: float = 0.0,
ij_border: int = 0,
gu: bool = False) -> Tuple[int, int, int, int]:
"""
Compute bounding box in i,j pixel coordinates given a bounding box *xy_bbox* in x,y coordinates.
:param xy_bbox: Bounding box (x_min, y_min, x_max, y_max) given in the same CS as x and y.
:param xy_border: If non-zero, grows the bounding box *xy_bbox* before using it for comparisons. Defaults to 0.
:param ij_border: If non-zero, grows the returned i,j bounding box and clips it to size. Defaults to 0.
:param gu: Use generic ufunc for the computation (may be faster). Defaults to False.
:return: Bounding box in (i_min, j_min, i_max, j_max) in pixel coordinates.
Returns ``(-1, -1, -1, -1)`` if *xy_bbox* isn't intersecting any of the x,y coordinates.
"""
xy_bboxes = np.array([xy_bbox], dtype=np.float64)
ij_bboxes = np.full_like(xy_bboxes, -1, dtype=np.int64)
self.ij_bboxes(xy_bboxes, xy_border=xy_border, ij_border=ij_border, ij_bboxes=ij_bboxes, gu=gu)
# noinspection PyTypeChecker
return tuple(map(int, ij_bboxes[0]))
示例3: __init__
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int64 [as 别名]
def __init__(
self, n_fish_max, pos_std, angle_std, n_segments, pred_coef, persist_fish_for
):
self.n_fish = n_fish_max
self.coords = np.full((n_fish_max, 6 + n_segments), np.nan)
self.uncertainties = np.array((pos_std, angle_std, angle_std))
self.def_P = np.zeros((3, 2, 2))
for i, uc in enumerate(self.uncertainties):
self.def_P[i, 0, 0] = uc
self.def_P[i, 1, 1] = uc
self.i_not_updated = np.zeros(n_fish_max, dtype=np.int64)
self.Ps = np.zeros((n_fish_max, 3, 2, 2))
self.F = np.array([[1.0, 1.0], [0.0, 1.0]])
dt = 0.02
self.Q = (
np.array([[0.25 * dt ** 4, 0.5 * dt ** 3], [0.5 * dt ** 3, dt ** 2]])
* pred_coef
)
self.persist_fish_for = persist_fish_for
示例4: gaps_between_hits
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int64 [as 别名]
def gaps_between_hits(hits):
"""Return array of gaps between hits: a hit's 'gap' is the # of samples before that hit free of other hits.
The gap of the first hit is 0 by definition.
Hits should already be sorted by index of maximum; we'll check this and throw an error if not.
"""
n_hits = len(hits)
gaps = np.zeros(n_hits, dtype=np.int64)
if n_hits == 0:
return gaps
# Keep a running right boundary
boundary = hits[0].index_of_maximum
for i, hit in enumerate(hits[1:]):
gaps[i + 1] = max(0, hit.index_of_maximum - boundary - 1)
if hit.index_of_maximum < boundary:
raise ValueError("Hits should be sorted by index_of_maximum")
boundary = max(hit.index_of_maximum, boundary)
return gaps
示例5: __init__
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int64 [as 别名]
def __init__(self, x_qbin, n_bin, m_bin):
self.x_qbin = x_qbin
self.n_bin = n_bin
self.m_bin = m_bin
self.print_log = False
if nb_flag:
logger.debug("SubBinning: NUMBA")
self.p_per_subbins = nb.jit(nb.double[:](nb.double[:], nb.double[:], nb.int64))(self.p_per_subbins_py)
else:
logger.debug("SubBinning: Python")
self.p_per_subbins = self.p_per_subbins_py
示例6: map_centroids
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int64 [as 别名]
def map_centroids(indices, sims, mapping, pad_ind, pad_val):
mapped_indices = np.full(
indices.shape, fill_value=pad_ind, dtype=np.int64)
mapped_sims = np.full(
indices.shape, fill_value=pad_val, dtype=np.float32)
for i in nb.prange(indices.shape[0]):
_ind, _sim = _remap_centroid_one(indices[i], sims[i], mapping)
mapped_indices[i, :len(_ind)] = _ind
mapped_sims[i, :len(_sim)] = _sim
return mapped_indices, mapped_sims
示例7: _as_array
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int64 [as 别名]
def _as_array(self, labels):
n_pos_labels = list(map(len, labels))
_labels = np.full(
(len(labels), max(n_pos_labels)),
self.pad_ind, np.int64)
for ind, _lab in enumerate(labels):
_labels[ind, :n_pos_labels[ind]] = labels[ind]
return _labels
示例8: int2key
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int64 [as 别名]
def int2key(int_key, dim, key_maxs, key_mins):
key = np.empty((dim + 1,), dtype=np.int64)
scales = key_maxs - key_mins + 1
for idx in range(dim, 0, -1):
key[idx] = int_key % scales[idx]
int_key -= key[idx]
int_key //= scales[idx]
key[0] = int_key
key += key_mins
return key
示例9: ij_bboxes
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int64 [as 别名]
def ij_bboxes(self,
xy_bboxes: np.ndarray,
xy_border: float = 0.0,
ij_bboxes: np.ndarray = None,
ij_border: int = 0,
gu: bool = False) -> np.ndarray:
"""
Compute bounding boxes in i,j pixel coordinates given bounding boxes *xy_bboxes* in x,y coordinates.
:param xy_bboxes: Numpy array of x,y bounding boxes [[x_min, y_min, x_max, y_max], ...]
given in the same CS as x and y.
:param xy_border: If non-zero, grows the bounding box *xy_bbox* before using it for comparisons. Defaults to 0.
:param ij_bboxes: Numpy array of pixel i,j bounding boxes [[x_min, y_min, x_max, y_max], ...].
If given, must have same shape as *xy_bboxes*.
:param ij_border: If non-zero, grows the returned i,j bounding box and clips it to size. Defaults to 0.
:param gu: Use generic ufunc for the computation (may be faster). Defaults to False.
:return: Bounding box in (i_min, j_min, i_max, j_max) in pixel coordinates.
Returns None if *xy_bbox* isn't intersecting any of the x,y coordinates.
"""
if self.is_lon_normalized:
xy_bboxes = xy_bboxes.copy()
c0 = xy_bboxes[:, 0]
c2 = xy_bboxes[:, 2]
c0 = np.where(c0 < 0.0, c0 + 360.0, c0)
c2 = np.where(c2 < 0.0, c2 + 360.0, c2)
xy_bboxes[:, 0] = c0
xy_bboxes[:, 2] = c2
c0 = xy_bboxes[:, 0]
c2 = xy_bboxes[:, 2]
cond = c0 > c2
if np.any(cond):
xy_bboxes = xy_bboxes.copy()
xy_bboxes[:, 2] += 360.0
if ij_bboxes is None:
ij_bboxes = np.full_like(xy_bboxes, -1, dtype=np.int64)
else:
ij_bboxes[:, :] = -1
if gu:
gu_compute_ij_bboxes(self.x.values,
self.y.values,
xy_bboxes,
xy_border,
ij_border,
ij_bboxes)
else:
compute_ij_bboxes(self.x.values,
self.y.values,
xy_bboxes,
xy_border,
ij_border,
ij_bboxes)
return ij_bboxes
示例10: _round
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int64 [as 别名]
def _round(mz: np.ndarray, intensity: np.ndarray, decimals: int, combine: str)\
-> Tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
JIT helper function for `MsmsSpectrum.round`.
Parameters
----------
mz : np.ndarray
The mass-to-charge ratios of the spectrum fragment peaks.
intensity : np.ndarray
The intensities of the corresponding spectrum fragment peaks.
decimals : int
Number of decimal places to round the mass-to-charge ratios.
combine : {'sum', 'max'}
Method used to combine intensities from merged fragment peaks.
Returns
-------
Tuple[np.ndarray, np.ndarray, np.ndarray]
A tuple consisting of the rounded mass-to-charge ratios and the
corresponding intensities and peak annotation indexes.
"""
mz_round = np.round_(mz, decimals, np.empty_like(mz, np.float32))
mz_unique = np.unique(mz_round)
# If peaks got merged by rounding the mass-to-charge ratios we need to
# combine their intensities and annotations as well.
if len(mz_unique) < len(mz_round):
intensity_unique = np.zeros_like(mz_unique, np.float32)
annotations_unique_idx = np.zeros_like(mz_unique, np.int64)
combine_is_sum = combine == 'sum'
i_orig = 0
offset = 0
for i_unique in range(len(mz_unique)):
# Check whether subsequent mz values got merged.
while (abs(mz_unique[i_unique] - mz_round[i_orig + offset])
<= 1e-06):
offset += 1
# Select the annotation of the most intense peak.
annotations_unique_idx[i_unique] = i_orig + np.argmax(
intensity[i_orig: i_orig + offset])
# Combine the corresponding intensities.
intensity_unique[i_unique] = (
intensity[i_orig: i_orig + offset].sum() if combine_is_sum else
intensity[annotations_unique_idx[i_unique]])
i_orig += offset
offset = 0
return mz_unique, intensity_unique, annotations_unique_idx
else:
return mz_unique, intensity, np.arange(len(mz))