当前位置: 首页>>代码示例>>Python>>正文


Python numba.prange方法代码示例

本文整理汇总了Python中numba.prange方法的典型用法代码示例。如果您正苦于以下问题:Python numba.prange方法的具体用法?Python numba.prange怎么用?Python numba.prange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numba的用法示例。


在下文中一共展示了numba.prange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _update_gradients_hessians_binary_crossentropy

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def _update_gradients_hessians_binary_crossentropy(gradients, hessians,
                                                   y_true, raw_predictions):
    # Note: using LightGBM version (first mapping {0, 1} into {-1, 1})
    # will cause overflow issues in the exponential as we're using float32
    # precision.

    # shape (n_samples, 1) --> (n_samples,). reshape(-1) is more likely to
    # return a view.
    raw_predictions = raw_predictions.reshape(-1)
    n_samples = raw_predictions.shape[0]
    starts, ends, n_threads = get_threads_chunks(total_size=n_samples)
    for thread_idx in prange(n_threads):
        for i in range(starts[thread_idx], ends[thread_idx]):
            gradients[i] = _expit(raw_predictions[i]) - y_true[i]
            gradient_abs = np.abs(gradients[i])
            hessians[i] = gradient_abs * (1. - gradient_abs) 
开发者ID:ogrisel,项目名称:pygbm,代码行数:18,代码来源:loss.py

示例2: _update_raw_predictions

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def _update_raw_predictions(leaves_data, raw_predictions):
    """Update raw_predictions by reading the predictions of the ith tree
    directly form the leaves.

    Can only be used for predicting the training data. raw_predictions
    contains the sum of the tree values from iteration 0 to i - 1. This adds
    the predictions of the ith tree to raw_predictions.

    Parameters
    ----------
    leaves_data: list of tuples (leaf.value, leaf.sample_indices)
        The leaves data used to update raw_predictions.
    raw_predictions : array-like, shape=(n_samples,)
        The raw predictions for the training data.
    """
    for leaf_idx in prange(len(leaves_data)):
        leaf_value, sample_indices = leaves_data[leaf_idx]
        for sample_idx in sample_indices:
            raw_predictions[sample_idx] += leaf_value 
开发者ID:ogrisel,项目名称:pygbm,代码行数:21,代码来源:gradient_boosting.py

示例3: _diamond_step

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def _diamond_step(DS_array, step_size, roughness):
    half_step = step_size // 2

    for i in nb.prange(0, DS_array.shape[0] // step_size):
        i = i * step_size + half_step
        for j in nb.prange(0, DS_array.shape[0] // step_size):
            j = j * step_size + half_step

            if DS_array[i,j] == -1.0:
                ul = DS_array[i - half_step, j - half_step]
                ur = DS_array[i - half_step, j + half_step]
                ll = DS_array[i + half_step, j - half_step]
                lr = DS_array[i + half_step, j + half_step]

                ave = (ul + ur + ll + lr) / 4.0
                rand_val = random.uniform(0, 1)
                DS_array[i, j] = roughness * rand_val + (1.0 - roughness) * ave 
开发者ID:airware,项目名称:buzzard,代码行数:19,代码来源:dsm_generation.py

示例4: _rmatvec_numba_table

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def _rmatvec_numba_table(x, y, dims, dimsd, interp, table, dtable):
    """numba implementation of adjoint mode with table.
    See official documentation for description of variables
    """
    dim0, dim1 = dims
    x = x.reshape(dimsd)
    for ix0 in prange(dim0):
        for it in range(dim1):
            indices = table[ix0, it]
            if interp:
                dindices = dtable[ix0, it]

            for i, indexfloat in enumerate(indices):
                index = int(indexfloat)
                if index != -9223372036854775808: # =int(np.nan)
                    if not interp:
                        y[ix0, it] += x[i, index]
                    else:
                        y[ix0, it] += x[i, index]*(1 - dindices[i]) + \
                                      x[i, index + 1]*dindices[i]
    return y.ravel() 
开发者ID:equinor,项目名称:pylops,代码行数:23,代码来源:_Spread_numba.py

示例5: _rmatvec_numba_onthefly

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def _rmatvec_numba_onthefly(x, y, dims, dimsd, interp, fh):
    """numba implementation of adjoint mode with on-the-fly computations.
    See official documentation for description of variables
    """
    dim0, dim1 = dims
    x = x.reshape(dimsd)
    for ix0 in prange(dim0):
        for it in range(dim1):
            if interp:
                indices, dindices = fh(ix0, it)
            else:
                indices, dindices = fh(ix0, it)
            for i, indexfloat in enumerate(indices):
                index = int(indexfloat)
                if index != -9223372036854775808: # =int(np.nan)
                    if not interp:
                        y[ix0, it] += x[i, index]
                    else:
                        y[ix0, it] += x[i, index]*(1 - dindices[i]) + \
                                      x[i, index + 1]*dindices[i]
    return y.ravel() 
开发者ID:equinor,项目名称:pylops,代码行数:23,代码来源:_Spread_numba.py

示例6: jacobian_2d_numba

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def jacobian_2d_numba(east, north, force_east, force_north, mindist, poisson, jac):
    "Calculate the Jacobian matrix using numba to speed things up."
    nforces = force_east.size
    npoints = east.size
    for i in numba.prange(npoints):  # pylint: disable=not-an-iterable
        for j in range(nforces):
            green_ee, green_nn, green_ne = GREENS_FUNC_2D_JIT(
                east[i] - force_east[j], north[i] - force_north[j], mindist, poisson
            )
            jac[i, j] = green_ee
            jac[i + npoints, j + nforces] = green_nn
            jac[i, j + nforces] = green_ne
            jac[i + npoints, j] = green_ne  # J is symmetric
    return jac


# JIT compile the Greens functions for use in numba functions 
开发者ID:fatiando,项目名称:verde,代码行数:19,代码来源:vector.py

示例7: _snn_imp

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def _snn_imp(ind, ref_set_):
    """Internal function for fast snn calculation

    Parameters
    ----------
    ind : int
        Indices return by kNN.

    ref_set_ : int, optional (default=10)
        specifies the number of shared nearest neighbors to create the
        reference set. Note that ref_set must be smaller than n_neighbors.

    """
    n = ind.shape[0]
    _count = np.zeros(shape=(n, ref_set_), dtype=np.uint32)
    for i in nb.prange(n):
        temp = np.empty(n, dtype=np.uint32)
        test_element_set = set(ind[i])
        for j in nb.prange(n):
            temp[j] = len(set(ind[j]).intersection(test_element_set))
        temp[i] = np.iinfo(np.uint32).max
        _count[i] = np.argsort(temp)[::-1][1:ref_set_ + 1]

    return _count 
开发者ID:yzhao062,项目名称:pyod,代码行数:26,代码来源:sod.py

示例8: min_max_parallel

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def min_max_parallel(A):
    """
    Standardise data by scaling data points by the sample minimum and maximum
    such that all data points lie in the range 0 to 1, equivalent to sklearn
    MinMaxScaler.

    Uses explicit parallel loop; may offer improved performance in some
    cases.
    """
    assert A.ndim > 1

    n = A.shape[1]
    res = empty_like(A, dtype=np_float64)

    for i in prange(n):
        data_i = A[:, i]
        data_min = np_min(data_i)
        res[:, i] = (data_i - data_min) / (np_max(data_i) - data_min)

    return res 
开发者ID:fastats,项目名称:fastats,代码行数:22,代码来源:scaling.py

示例9: demean_parallel

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def demean_parallel(A):
    """
    Subtract the mean from the supplied data column-wise.

    Uses explicit parallel loop; may offer improved performance in some
    cases.
    """
    assert A.ndim > 1

    n = A.shape[1]
    res = empty_like(A, dtype=np_float64)

    for i in prange(n):
        data_i = A[:, i]
        res[:, i] = data_i - mean(data_i)

    return res 
开发者ID:fastats,项目名称:fastats,代码行数:19,代码来源:scaling.py

示例10: map_neighbors

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [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 
开发者ID:kunaldahiya,项目名称:pyxclib,代码行数:20,代码来源:shortlist.py

示例11: numba_loop_sparse_dist_with_geometry

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def numba_loop_sparse_dist_with_geometry(waveform, centers,  possibles_cluster_idx, rms_waveform_channel,channel_adjacency):
    
    nb_total_clus, width, nb_chan = centers.shape
    nb_clus = possibles_cluster_idx.size
    
    #rms_waveform_channel = np.sum(waveform**2, axis=0)#.astype('float32')
    waveform_distance = np.zeros((nb_clus,), dtype=np.float32)
    
    for clus in prange(len(possibles_cluster_idx)):
        cluster_idx = possibles_cluster_idx[clus]
        sum = 0
        for c in channel_adjacency:
            #~ if mask[cluster_idx, c]:
            for s in range(width):
                d = waveform[s, c] - centers[cluster_idx, s, c]
                sum += d*d
            #~ else:
                #~ sum +=rms_waveform_channel[c]
        waveform_distance[clus] = sum
    
    return waveform_distance 
开发者ID:tridesclous,项目名称:tridesclous,代码行数:23,代码来源:numba_tools.py

示例12: numba_explore_shifts

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def numba_explore_shifts(long_waveform, one_center,  one_mask, maximum_jitter_shift):
    width, nb_chan = one_center.shape
    n = maximum_jitter_shift*2 +1
    
    all_dist = np.zeros((n, ), dtype=np.float32)
    
    for shift in prange(n):
        sum = 0
        for c in range(nb_chan):
            if one_mask[c]:
                for s in range(width):
                    d = long_waveform[shift+s, c] - one_center[s, c]
                    sum += d*d
        all_dist[shift] = sum
    
    return all_dist 
开发者ID:tridesclous,项目名称:tridesclous,代码行数:18,代码来源:numba_tools.py

示例13: peak_loop_plus

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def peak_loop_plus(sigs, sig_center, mask_peaks, n_span, thresh, peak_sign, neighbours):
    for chan in prange(sig_center.shape[1]):
        for s in range(mask_peaks.shape[0]):
            if not mask_peaks[s, chan]:
                continue
            for neighbour in neighbours[chan, :]:
                if neighbour<0:
                    continue
                for i in range(n_span):
                    if chan != neighbour:
                        mask_peaks[s, chan] &= sig_center[s, chan] >= sig_center[s, neighbour]
                    mask_peaks[s, chan] &= sig_center[s, chan] > sigs[s+i, neighbour]
                    mask_peaks[s, chan] &= sig_center[s, chan]>=sigs[n_span+s+i+1, neighbour]
                    if not mask_peaks[s, chan]:
                        break
                if not mask_peaks[s, chan]:
                    break
    return mask_peaks 
开发者ID:tridesclous,项目名称:tridesclous,代码行数:20,代码来源:numba_tools.py

示例14: peak_loop_minus

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def peak_loop_minus(sigs, sig_center, mask_peaks, n_span, thresh, peak_sign, neighbours):
    for chan in prange(sig_center.shape[1]):
        for s in range(mask_peaks.shape[0]):
            if not mask_peaks[s, chan]:
                continue
            for neighbour in neighbours[chan, :]:
                if neighbour<0:
                    continue
                for i in range(n_span):
                    if chan != neighbour:
                        mask_peaks[s, chan] &= sig_center[s, chan] <= sig_center[s, neighbour]
                    mask_peaks[s, chan] &= sig_center[s, chan] < sigs[s+i, neighbour]
                    mask_peaks[s, chan] &= sig_center[s, chan]<=sigs[n_span+s+i+1, neighbour]                        
                    if not mask_peaks[s, chan]:
                        break
                if not mask_peaks[s, chan]:
                    break
    return mask_peaks 
开发者ID:tridesclous,项目名称:tridesclous,代码行数:20,代码来源:numba_tools.py

示例15: generate_leaf_updates

# 需要导入模块: import numba [as 别名]
# 或者: from numba import prange [as 别名]
def generate_leaf_updates(leaf_block, dist_thresholds, data, dist):

    updates = [[(-1, -1, np.inf)] for i in range(leaf_block.shape[0])]

    for n in numba.prange(leaf_block.shape[0]):
        for i in range(leaf_block.shape[1]):
            p = leaf_block[n, i]
            if p < 0:
                break

            for j in range(i + 1, leaf_block.shape[1]):
                q = leaf_block[n, j]
                if q < 0:
                    break

                d = dist(data[p], data[q])
                if d < dist_thresholds[p] or d < dist_thresholds[q]:
                    updates[n].append((p, q, d))

    return updates 
开发者ID:lmcinnes,项目名称:pynndescent,代码行数:22,代码来源:pynndescent_.py


注:本文中的numba.prange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。