本文整理汇总了Python中numba.int32方法的典型用法代码示例。如果您正苦于以下问题:Python numba.int32方法的具体用法?Python numba.int32怎么用?Python numba.int32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numba
的用法示例。
在下文中一共展示了numba.int32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def apply(self, image, boxes, meta_image):
if np.random.rand() < self.skip_gray_prob:
return image, boxes, meta_image
# tic = time.time()
gray_scale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# toc1 = time.time() - tic
# print ('Gray Scale: %4.3f' % toc1)
if np.random.rand() > self.apply_prob:
gray_scale = expand(gray_scale)
return gray_scale, boxes, meta_image
kernel = np.ones((5, 5), np.uint8)
gray_scale = augment_boxes(gray_scale, boxes.astype(np.int32), kernel, self.dialation_prob)
# toc2 = time.time() - tic - toc1
# print('Agument: %4.3f' % toc2)
# gray_scale = np.repeat(gray_scale[:,:, np.newaxis], 3, axis=2)
gray_scale = expand(gray_scale)
q = 0.4 + 0.2*np.random.rand()
gray_scale = np.array(q*gray_scale + (1-q)*image, dtype=np.uint8)
# print('expand: %4.3f' % toc3)
return gray_scale, boxes, meta_image
示例2: csc_sprealloc_f
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def csc_sprealloc_f(An, Aindptr, Aindices, Adata, nzmax):
"""
Change the max # of entries a sparse matrix can hold.
:param An: number of columns
:param Aindptr: csc column pointers
:param Aindices: csc row indices
:param Adata: csc data
:param nzmax:new maximum number of entries
:return: indices, data, nzmax
"""
if nzmax <= 0:
nzmax = Aindptr[An]
length = min(nzmax, len(Aindices))
Ainew = np.empty(nzmax, dtype=nb.int32)
for i in range(length):
Ainew[i] = Aindices[i]
length = min(nzmax, len(Adata))
Axnew = np.empty(nzmax, dtype=nb.float64)
for i in range(length):
Axnew[i] = Adata[i]
return Ainew, Axnew, nzmax
示例3: csc_diagonal
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def csc_diagonal(m, value=1.0):
"""
Build CSC diagonal matrix of the given value
:param m: size
:param value: value
:return: CSC matrix
"""
indptr = np.empty(m + 1, dtype=np.int32)
indices = np.empty(m, dtype=np.int32)
data = np.empty(m, dtype=np.float64)
for i in range(m):
indptr[i] = i
indices[i] = i
data[i] = value
indptr[m] = m
return indices, indptr, data
示例4: csc_diagonal_from_array
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def csc_diagonal_from_array(m, array):
"""
:param m:
:param array:
:return:
"""
indptr = np.empty(m + 1, dtype=np.int32)
indices = np.empty(m, dtype=np.int32)
data = np.empty(m, dtype=np.float64)
for i in range(m):
indptr[i] = i
indices[i] = i
data[i] = array[i]
indptr[m] = m
return indices, indptr, data
示例5: csc_diagonal_from_array
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def csc_diagonal_from_array(m, array):
"""
:param m:
:param array:
:return:
"""
indptr = np.empty(m + 1, dtype=nb.int32)
indices = np.empty(m, dtype=nb.int32)
data = np.empty(m, dtype=nb.complex128)
for i in range(m):
indptr[i] = i
indices[i] = i
data[i] = array[i]
indptr[m] = m
return indices, indptr, data
示例6: csr_to_nbgraph
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def csr_to_nbgraph(csr, node_props=None):
if node_props is None:
node_props = np.broadcast_to(1., csr.shape[0])
node_props.flags.writeable = True
return NBGraph(csr.indptr, csr.indices, csr.data,
np.array(csr.shape, dtype=np.int32), node_props)
示例7: gen_gaussian_map
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def gen_gaussian_map(centers, shape, sigma):
centers = np.float32(centers)
sigma = np.float32(sigma)
accumulate_confid_map = np.zeros(shape, dtype=np.float32)
y_range = np.arange(accumulate_confid_map.shape[0], dtype=np.int32)
x_range = np.arange(accumulate_confid_map.shape[1], dtype=np.int32)
xx, yy = np.meshgrid(x_range, y_range)
accumulate_confid_map = apply_gaussian(accumulate_confid_map, centers, xx, yy, sigma)
accumulate_confid_map[accumulate_confid_map > 1.0] = 1.0
return accumulate_confid_map
示例8: make_dense_tree
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def make_dense_tree(data, rng_state, leaf_size=30, angular=False):
indices = np.arange(data.shape[0]).astype(np.int32)
hyperplanes = numba.typed.List.empty_list(dense_hyperplane_type)
offsets = numba.typed.List.empty_list(offset_type)
children = numba.typed.List.empty_list(children_type)
point_indices = numba.typed.List.empty_list(point_indices_type)
if angular:
make_angular_tree(
data,
indices,
hyperplanes,
offsets,
children,
point_indices,
rng_state,
leaf_size,
)
else:
make_euclidean_tree(
data,
indices,
hyperplanes,
offsets,
children,
point_indices,
rng_state,
leaf_size,
)
# print("Completed a tree")
result = FlatTree(hyperplanes, offsets, children, point_indices, leaf_size)
# print("Tree type is:", numba.typeof(result))
return result
示例9: make_sparse_tree
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def make_sparse_tree(inds, indptr, spdata, rng_state, leaf_size=30, angular=False):
indices = np.arange(indptr.shape[0] - 1).astype(np.int32)
hyperplanes = numba.typed.List.empty_list(sparse_hyperplane_type)
offsets = numba.typed.List.empty_list(offset_type)
children = numba.typed.List.empty_list(children_type)
point_indices = numba.typed.List.empty_list(point_indices_type)
if angular:
make_sparse_angular_tree(
inds,
indptr,
spdata,
indices,
hyperplanes,
offsets,
children,
point_indices,
rng_state,
leaf_size,
)
else:
make_sparse_euclidean_tree(
inds,
indptr,
spdata,
indices,
hyperplanes,
offsets,
children,
point_indices,
rng_state,
leaf_size,
)
return FlatTree(hyperplanes, offsets, children, point_indices, leaf_size)
示例10: get_leaves_from_tree
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def get_leaves_from_tree(tree):
n_leaves = 0
for i in range(len(tree.children)):
if tree.children[i][0] == -1 and tree.children[i][1] == -1:
n_leaves += 1
result = -1 * np.ones((n_leaves, tree.leaf_size), dtype=np.int32)
leaf_index = 0
for i in range(len(tree.indices)):
if tree.children[i][0] == -1 or tree.children[i][1] == -1:
leaf_size = tree.indices[i].shape[0]
result[leaf_index, :leaf_size] = tree.indices[i]
leaf_index += 1
return result
示例11: convert_tree_format
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def convert_tree_format(tree, data_size):
n_nodes, n_leaves = num_nodes_and_leaves(tree)
is_sparse = False
if tree.hyperplanes[0].ndim == 1:
# dense hyperplanes
hyperplane_dim = dense_hyperplane_dim(tree.hyperplanes)
hyperplanes = np.zeros((n_nodes, hyperplane_dim), dtype=np.float32)
else:
# sparse hyperplanes
is_sparse = True
hyperplane_dim = sparse_hyperplane_dim(tree.hyperplanes)
hyperplanes = np.zeros((n_nodes, 2, hyperplane_dim), dtype=np.float32)
hyperplanes[:, 0, :] = -1
offsets = np.zeros(n_nodes, dtype=np.float32)
children = np.int32(-1) * np.ones((n_nodes, 2), dtype=np.int32)
indices = np.int32(-1) * np.ones(data_size, dtype=np.int32)
if is_sparse:
recursive_convert_sparse(
tree, hyperplanes, offsets, children, indices, 0, 0, len(tree.children) - 1
)
else:
recursive_convert(
tree, hyperplanes, offsets, children, indices, 0, 0, len(tree.children) - 1
)
return FlatTree(hyperplanes, offsets, children, indices, tree.leaf_size)
示例12: map_coordinates
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def map_coordinates(I, yc, xc, Y):
""" bilinear transform of image with ycoordinates yc and xcoordinates xc to Y
Parameters
-------------
I : int16 or float32, 2D array
size [Ly x Lx]
yc : 2D array
size [Ly x Lx], new y coordinates
xc : 2D array
size [Ly x Lx], new x coordinates
Returns
-----------
Y : float32, 2D array
size [Ly x Lx], shifted I
"""
Ly,Lx = I.shape
yc_floor = yc.copy().astype(np.int32)
xc_floor = xc.copy().astype(np.int32)
yc -= yc_floor
xc -= xc_floor
for i in range(yc_floor.shape[0]):
for j in range(yc_floor.shape[1]):
yf = min(Ly-1, max(0, yc_floor[i,j]))
xf = min(Lx-1, max(0, xc_floor[i,j]))
yf1= min(Ly-1, yf+1)
xf1= min(Lx-1, xf+1)
y = yc[i,j]
x = xc[i,j]
Y[i,j] = (np.float32(I[yf, xf]) * (1 - y) * (1 - x) +
np.float32(I[yf, xf1]) * (1 - y) * x +
np.float32(I[yf1, xf]) * y * (1 - x) +
np.float32(I[yf1, xf1]) * y * x )
示例13: nfloor
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def nfloor(y):
return math.floor(y) #np.int32(np.floor(y))
示例14: box_filter
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def box_filter(boxes, limits, size, border=20):
z = PartilPage.sq_size(limits, size)
# Pick boxes that fall inside new image boundaries
good_idx = np.where((boxes[:, 0] > z[0]) & (boxes[:, 1] > z[1]) & (boxes[:, 2] < z[2]) & (boxes[:, 3] < z[3]))[0]
# If boundaries are empty...
if good_idx.shape[0] < 1:
return [], (0, 0, 0, 0)
good_boxes = boxes[good_idx, :]
limits_of_good_boxes = np.concatenate((good_boxes[:, :2].min(0), good_boxes[:, 2:].max(0)))
new_z = np.array([max(limits_of_good_boxes[0] - border, 0), max(limits_of_good_boxes[1] - border, 0),
min(limits_of_good_boxes[2] + border, limits[1]), min(limits_of_good_boxes[3] + border, limits[0])])\
.astype(np.int32)
return good_idx, new_z
示例15: pick_random_size
# 需要导入模块: import numba [as 别名]
# 或者: from numba import int32 [as 别名]
def pick_random_size(self):
ratio = self._low_bound + (self._high_bound - self._low_bound) * np.random.rand()
tw = np.int32(ratio * self._tw)
th = np.int32(ratio * self._th)
x0 = np.random.randint(0, self._tw)
y0 = np.random.randint(0, self._th)
while not (x0 + tw < self._tw and y0 + th < self._th):
x0 = np.random.randint(0, self._tw)
y0 = np.random.randint(0, self._th)
return tw, th, x0, y0