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


Python numba.int32方法代碼示例

本文整理匯總了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 
開發者ID:gaxler,項目名稱:dataset_agnostic_segmentation,代碼行數:22,代碼來源:augmentations.py

示例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 
開發者ID:SanPen,項目名稱:GridCal,代碼行數:27,代碼來源:csc_numba.py

示例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 
開發者ID:SanPen,項目名稱:GridCal,代碼行數:19,代碼來源:csc_numba.py

示例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 
開發者ID:SanPen,項目名稱:GridCal,代碼行數:19,代碼來源:csc_numba.py

示例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 
開發者ID:SanPen,項目名稱:GridCal,代碼行數:19,代碼來源:numba_functions.py

示例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) 
開發者ID:jni,項目名稱:skan,代碼行數:8,代碼來源:csr.py

示例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 
開發者ID:svip-lab,項目名稱:PPGNet,代碼行數:14,代碼來源:utils.py

示例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 
開發者ID:lmcinnes,項目名稱:pynndescent,代碼行數:37,代碼來源:rp_trees.py

示例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) 
開發者ID:lmcinnes,項目名稱:pynndescent,代碼行數:38,代碼來源:rp_trees.py

示例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 
開發者ID:lmcinnes,項目名稱:pynndescent,代碼行數:17,代碼來源:rp_trees.py

示例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) 
開發者ID:lmcinnes,項目名稱:pynndescent,代碼行數:29,代碼來源:rp_trees.py

示例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 ) 
開發者ID:MouseLand,項目名稱:suite2p,代碼行數:42,代碼來源:nonrigid.py

示例13: nfloor

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import int32 [as 別名]
def nfloor(y):
    return math.floor(y) #np.int32(np.floor(y)) 
開發者ID:MouseLand,項目名稱:suite2p,代碼行數:4,代碼來源:nonrigid.py

示例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 
開發者ID:gaxler,項目名稱:dataset_agnostic_segmentation,代碼行數:16,代碼來源:augmentations.py

示例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 
開發者ID:gaxler,項目名稱:dataset_agnostic_segmentation,代碼行數:14,代碼來源:augmentations.py


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