本文整理匯總了Python中numba.float32方法的典型用法代碼示例。如果您正苦於以下問題:Python numba.float32方法的具體用法?Python numba.float32怎麽用?Python numba.float32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numba
的用法示例。
在下文中一共展示了numba.float32方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: quadrilateral_intersection
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def quadrilateral_intersection(pts1, pts2, int_pts):
num_of_inter = 0
for i in range(4):
if point_in_quadrilateral(pts1[2 * i], pts1[2 * i + 1], pts2):
int_pts[num_of_inter * 2] = pts1[2 * i]
int_pts[num_of_inter * 2 + 1] = pts1[2 * i + 1]
num_of_inter += 1
if point_in_quadrilateral(pts2[2 * i], pts2[2 * i + 1], pts1):
int_pts[num_of_inter * 2] = pts2[2 * i]
int_pts[num_of_inter * 2 + 1] = pts2[2 * i + 1]
num_of_inter += 1
temp_pts = cuda.local.array((2, ), dtype=numba.float32)
for i in range(4):
for j in range(4):
has_pts = line_segment_intersection(pts1, pts2, i, j, temp_pts)
if has_pts:
int_pts[num_of_inter * 2] = temp_pts[0]
int_pts[num_of_inter * 2 + 1] = temp_pts[1]
num_of_inter += 1
return num_of_inter
示例2: rbbox_to_corners
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def rbbox_to_corners(corners, rbbox):
# generate clockwise corners and rotate it clockwise
angle = rbbox[4]
a_cos = math.cos(angle)
a_sin = math.sin(angle)
center_x = rbbox[0]
center_y = rbbox[1]
x_d = rbbox[2]
y_d = rbbox[3]
corners_x = cuda.local.array((4, ), dtype=numba.float32)
corners_y = cuda.local.array((4, ), dtype=numba.float32)
corners_x[0] = -x_d / 2
corners_x[1] = -x_d / 2
corners_x[2] = x_d / 2
corners_x[3] = x_d / 2
corners_y[0] = -y_d / 2
corners_y[1] = y_d / 2
corners_y[2] = y_d / 2
corners_y[3] = -y_d / 2
for i in range(4):
corners[2 *
i] = a_cos * corners_x[i] + a_sin * corners_y[i] + center_x
corners[2 * i
+ 1] = -a_sin * corners_x[i] + a_cos * corners_y[i] + center_y
示例3: quadrilateral_intersection
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def quadrilateral_intersection(pts1, pts2, int_pts):
num_of_inter = 0
for i in range(4):
if point_in_quadrilateral(pts1[2 * i], pts1[2 * i + 1], pts2):
int_pts[num_of_inter * 2] = pts1[2 * i]
int_pts[num_of_inter * 2 + 1] = pts1[2 * i + 1]
num_of_inter += 1
if point_in_quadrilateral(pts2[2 * i], pts2[2 * i + 1], pts1):
int_pts[num_of_inter * 2] = pts2[2 * i]
int_pts[num_of_inter * 2 + 1] = pts2[2 * i + 1]
num_of_inter += 1
temp_pts = cuda.local.array((2,), dtype=numba.float32)
for i in range(4):
for j in range(4):
has_pts = line_segment_intersection(pts1, pts2, i, j, temp_pts)
if has_pts:
int_pts[num_of_inter * 2] = temp_pts[0]
int_pts[num_of_inter * 2 + 1] = temp_pts[1]
num_of_inter += 1
return num_of_inter
示例4: rbbox_to_corners
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def rbbox_to_corners(corners, rbbox):
# generate clockwise corners and rotate it clockwise
angle = rbbox[4]
a_cos = math.cos(angle)
a_sin = math.sin(angle)
center_x = rbbox[0]
center_y = rbbox[1]
x_d = rbbox[2]
y_d = rbbox[3]
corners_x = cuda.local.array((4,), dtype=numba.float32)
corners_y = cuda.local.array((4,), dtype=numba.float32)
corners_x[0] = -x_d / 2
corners_x[1] = -x_d / 2
corners_x[2] = x_d / 2
corners_x[3] = x_d / 2
corners_y[0] = -y_d / 2
corners_y[1] = y_d / 2
corners_y[2] = y_d / 2
corners_y[3] = -y_d / 2
for i in range(4):
corners[2 *
i] = a_cos * corners_x[i] + a_sin * corners_y[i] + center_x
corners[2 * i
+ 1] = -a_sin * corners_x[i] + a_cos * corners_y[i] + center_y
示例5: map_neighbors
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [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
示例6: rbbox_to_corners
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def rbbox_to_corners(corners, rbbox):
# generate clockwise corners and rotate it clockwise
angle = rbbox[4]
a_cos = math.cos(angle)
a_sin = math.sin(angle)
center_x = rbbox[0]
center_y = rbbox[1]
x_d = rbbox[2]
y_d = rbbox[3]
corners_x = cuda.local.array((4,), dtype=numba.float32)
corners_y = cuda.local.array((4,), dtype=numba.float32)
corners_x[0] = -x_d / 2
corners_x[1] = -x_d / 2
corners_x[2] = x_d / 2
corners_x[3] = x_d / 2
corners_y[0] = -y_d / 2
corners_y[1] = y_d / 2
corners_y[2] = y_d / 2
corners_y[3] = -y_d / 2
for i in range(4):
corners[2 * i] = a_cos * corners_x[i] + a_sin * corners_y[i] + center_x
corners[2 * i + 1] = -a_sin * corners_x[i] + a_cos * corners_y[i] + center_y
示例7: _process
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def _process(
self,
im,
learning_rate: Param(0.04, (0.0, 1.0)),
learn_every: Param(400, (1, 10000)),
only_darker: Param(True),
):
messages = []
if self.background_image is None:
self.background_image = im.astype(np.float32)
messages.append("I:New backgorund image set")
elif self.i == 0:
self.background_image[:, :] = im.astype(np.float32) * np.float32(
learning_rate
) + self.background_image * np.float32(1 - learning_rate)
self.i = (self.i + 1) % learn_every
if only_darker:
return NodeOutput(messages, negdif(self.background_image, im))
else:
return NodeOutput(messages, absdif(self.background_image, im))
示例8: rbbox_to_corners
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def rbbox_to_corners(corners, rbbox):
# generate clockwise corners and rotate it clockwise
angle = rbbox[4]
a_cos = math.cos(angle)
a_sin = math.sin(angle)
center_x = rbbox[0]
center_y = rbbox[1]
x_d = rbbox[2]
y_d = rbbox[3]
corners_x = cuda.local.array((4, ), dtype=numba.float32)
corners_y = cuda.local.array((4, ), dtype=numba.float32)
corners_x[0] = -x_d / 2
corners_x[1] = -x_d / 2
corners_x[2] = x_d / 2
corners_x[3] = x_d / 2
corners_y[0] = -y_d / 2
corners_y[1] = y_d / 2
corners_y[2] = y_d / 2
corners_y[3] = -y_d / 2
for i in range(4):
corners[2 * i] = a_cos * corners_x[i] + a_sin * corners_y[i] + center_x
corners[2 * i +
1] = -a_sin * corners_x[i] + a_cos * corners_y[i] + center_y
示例9: get_bio_span
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def get_bio_span(exprs, ndim, svd_mode, var_subset=None, **kwargs):
centred = exprs - np.mean(exprs, axis=0)
if var_subset is not None:
subsetter = [True] * centred.shape[1]
keeper = [False] * centred.shape[1]
for i in var_subset:
subsetter[i] = False
keeper[i] = True
leftovers = centred[:, subsetter].T
centred = centred[:, keeper]
ndim = min(ndim, *centred.shape)
singular = svd_internal(centred.T, ndim, svd_mode, **kwargs)
if var_subset is None:
return singular[0]
output = np.zeros((exprs.shape[1], ndim), dtype=np.float32)
output[keeper,] = singular[0]
output[subsetter,] = np.divide(np.dot(leftovers, singular[2]), singular[1][range(ndim)])
return output
示例10: linear_interp
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def linear_interp(iy, ix, yb, xb, f):
""" 2d interpolation of f on grid of yb, xb into grid of iy, ix
assumes f is 3D and last two dimensions are yb,xb """
fup = f.copy().astype(np.float32)
Lax = [iy.size, ix.size]
for n in range(2):
fup = np.transpose(fup,(1,2,0)).copy()
if n==0:
ds = np.abs(iy[:,np.newaxis] - yb[:,np.newaxis].T)
else:
ds = np.abs(ix[:,np.newaxis] - xb[:,np.newaxis].T)
im1 = np.argmin(ds, axis=1)
w1 = ds[np.arange(0,Lax[n],1,int),im1]
ds[np.arange(0,Lax[n],1,int),im1] = np.inf
im2 = np.argmin(ds, axis=1)
w2 = ds[np.arange(0,Lax[n],1,int),im2]
wnorm = w1+w2
w1 /= wnorm
w2 /= wnorm
fup = (1-w1[:,np.newaxis,np.newaxis]) * fup[im1] + (1-w2[:,np.newaxis,np.newaxis]) * fup[im2]
fup = np.transpose(fup, (1,2,0))
return fup
示例11: _get_scaled_intensity_root
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def _get_scaled_intensity_root(intensity: np.ndarray, degree: int)\
-> np.ndarray:
"""
JIT helper function for `MsmsSpectrum.scale_intensity`.
Parameters
----------
intensity : np.ndarray
The intensities of the spectrum fragment peaks.
degree : int
The degree of the root scaling.
Returns
-------
np.ndarray
The root-scaled intensities.
"""
return np.power(intensity, 1 / degree).astype(np.float32)
示例12: _get_scaled_intensity_log
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def _get_scaled_intensity_log(intensity: np.ndarray, base: int) -> np.ndarray:
"""
JIT helper function for `MsmsSpectrum.scale_intensity`.
Parameters
----------
intensity : np.ndarray
The intensities of the spectrum fragment peaks.
base : int
The base of the log scaling.
Returns
-------
np.ndarray
The log-scaled intensities.
"""
return (np.log1p(intensity) / np.log(base)).astype(np.float32)
示例13: _get_scaled_intensity_rank
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def _get_scaled_intensity_rank(intensity: np.ndarray, max_rank: int)\
-> np.ndarray:
"""
JIT helper function for `MsmsSpectrum.scale_intensity`.
Parameters
----------
intensity : np.ndarray
The intensities of the spectrum fragment peaks.
max_rank : int
The maximum rank of the rank scaling.
Returns
-------
np.ndarray
The rank-scaled intensities.
"""
return ((max_rank - np.argsort(np.argsort(intensity)[::-1]))
.astype(np.float32))
示例14: sort_vertex_in_convex_polygon
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def sort_vertex_in_convex_polygon(int_pts, num_of_inter):
if num_of_inter > 0:
center = cuda.local.array((2, ), dtype=numba.float32)
center[:] = 0.0
for i in range(num_of_inter):
center[0] += int_pts[2 * i]
center[1] += int_pts[2 * i + 1]
center[0] /= num_of_inter
center[1] /= num_of_inter
v = cuda.local.array((2, ), dtype=numba.float32)
vs = cuda.local.array((16, ), dtype=numba.float32)
for i in range(num_of_inter):
v[0] = int_pts[2 * i] - center[0]
v[1] = int_pts[2 * i + 1] - center[1]
d = math.sqrt(v[0] * v[0] + v[1] * v[1])
v[0] = v[0] / d
v[1] = v[1] / d
if v[1] < 0:
v[0] = -2 - v[0]
vs[i] = v[0]
j = 0
temp = 0
for i in range(1, num_of_inter):
if vs[i - 1] > vs[i]:
temp = vs[i]
tx = int_pts[2 * i]
ty = int_pts[2 * i + 1]
j = i
while j > 0 and vs[j - 1] > temp:
vs[j] = vs[j - 1]
int_pts[j * 2] = int_pts[j * 2 - 2]
int_pts[j * 2 + 1] = int_pts[j * 2 - 1]
j -= 1
vs[j] = temp
int_pts[j * 2] = tx
int_pts[j * 2 + 1] = ty
示例15: line_segment_intersection
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float32 [as 別名]
def line_segment_intersection(pts1, pts2, i, j, temp_pts):
A = cuda.local.array((2, ), dtype=numba.float32)
B = cuda.local.array((2, ), dtype=numba.float32)
C = cuda.local.array((2, ), dtype=numba.float32)
D = cuda.local.array((2, ), dtype=numba.float32)
A[0] = pts1[2 * i]
A[1] = pts1[2 * i + 1]
B[0] = pts1[2 * ((i + 1) % 4)]
B[1] = pts1[2 * ((i + 1) % 4) + 1]
C[0] = pts2[2 * j]
C[1] = pts2[2 * j + 1]
D[0] = pts2[2 * ((j + 1) % 4)]
D[1] = pts2[2 * ((j + 1) % 4) + 1]
BA0 = B[0] - A[0]
BA1 = B[1] - A[1]
DA0 = D[0] - A[0]
CA0 = C[0] - A[0]
DA1 = D[1] - A[1]
CA1 = C[1] - A[1]
acd = DA1 * CA0 > CA1 * DA0
bcd = (D[1] - B[1]) * (C[0] - B[0]) > (C[1] - B[1]) * (D[0] - B[0])
if acd != bcd:
abc = CA1 * BA0 > BA1 * CA0
abd = DA1 * BA0 > BA1 * DA0
if abc != abd:
DC0 = D[0] - C[0]
DC1 = D[1] - C[1]
ABBA = A[0] * B[1] - B[0] * A[1]
CDDC = C[0] * D[1] - D[0] * C[1]
DH = BA1 * DC0 - BA0 * DC1
Dx = ABBA * DC0 - BA0 * CDDC
Dy = ABBA * DC1 - BA1 * CDDC
temp_pts[0] = Dx / DH
temp_pts[1] = Dy / DH
return True
return False