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


Python numba.guvectorize方法代码示例

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


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

示例1: calculate_value_functions_and_flow_utilities

# 需要导入模块: import numba [as 别名]
# 或者: from numba import guvectorize [as 别名]
def calculate_value_functions_and_flow_utilities(
    wage, nonpec, continuation_value, draw, delta, value_function, flow_utility
):
    """Calculate the choice-specific value functions and flow utilities.

    To apply :func:`aggregate_keane_wolpin_utility` to arrays with arbitrary dimensions,
    this function uses :func:`numba.guvectorize`. One cannot use :func:`numba.vectorize`
    because it does not support multiple return values.

    See also
    --------
    aggregate_keane_wolpin_utility

    """
    value_function[0], flow_utility[0] = aggregate_keane_wolpin_utility(
        wage, nonpec, continuation_value, draw, delta
    ) 
开发者ID:OpenSourceEconomics,项目名称:respy,代码行数:19,代码来源:shared.py

示例2: tensor_outer_at

# 需要导入模块: import numba [as 别名]
# 或者: from numba import guvectorize [as 别名]
def tensor_outer_at(vtarget, **kwargs):
    @guvectorize(['void(float64[:], float64[:, :], float64[:, :], intp[:], intp[:], float64[:, :])'],
                 '(),(i,m),(j,n),(),()->(m,n)',
                 target=vtarget, nopython=True, **kwargs)
    def tensor_outer_wrapped(val, v, w, i, j, res):
        r1 = v.shape[1]
        r2 = w.shape[1]
        for m in range(r1):
            for n in range(r2):
                res[m, n] = val[0] * v[i[0], m] * w[j[0], n]
    return tensor_outer_wrapped 
开发者ID:evfro,项目名称:polara,代码行数:13,代码来源:sparse.py

示例3: _crps_ensemble_gufunc

# 需要导入模块: import numba [as 别名]
# 或者: from numba import guvectorize [as 别名]
def _crps_ensemble_gufunc(observation, forecasts, weights, result):
    # beware: forecasts are assumed sorted in NumPy's sort order

    # we index the 0th element to get the scalar value from this 0d array:
    # http://numba.pydata.org/numba-doc/0.18.2/user/vectorize.html#the-guvectorize-decorator
    obs = observation[0]

    if np.isnan(obs):
        result[0] = np.nan
        return

    total_weight = 0.0
    for n, weight in enumerate(weights):
        if np.isnan(forecasts[n]):
            # NumPy sorts NaN to the end
            break
        if not weight >= 0:
            # this catches NaN weights
            result[0] = np.nan
            return
        total_weight += weight

    obs_cdf = 0
    forecast_cdf = 0
    prev_forecast = 0
    integral = 0

    for n, forecast in enumerate(forecasts):
        if np.isnan(forecast):
            # NumPy sorts NaN to the end
            if n == 0:
                integral = np.nan
            # reset for the sake of the conditional below
            forecast = prev_forecast
            break

        if obs_cdf == 0 and obs < forecast:
            integral += (obs - prev_forecast) * forecast_cdf ** 2
            integral += (forecast - obs) * (forecast_cdf - 1) ** 2
            obs_cdf = 1
        else:
            integral += ((forecast - prev_forecast)
                         * (forecast_cdf - obs_cdf) ** 2)

        forecast_cdf += weights[n] / total_weight
        prev_forecast = forecast

    if obs_cdf == 0:
        # forecast can be undefined here if the loop body is never executed
        # (because forecasts have size 0), but don't worry about that because
        # we want to raise an error in that case, anyways
        integral += obs - forecast

    result[0] = integral 
开发者ID:TheClimateCorporation,项目名称:properscoring,代码行数:56,代码来源:_gufuncs.py

示例4: calculate_conditional_draws

# 需要导入模块: import numba [as 别名]
# 或者: from numba import guvectorize [as 别名]
def calculate_conditional_draws(
    base_draws, updated_mean, updated_chols, chol_index, max_log_float, conditional_draw
):
    """Calculate the conditional draws from base draws, updated means and updated chols.

    We need to pass ``max_log_float`` to the function, because the global variables
    ``MAX_LOG_FLOAT`` cannot be used directly withing the guvectorize.

    Parameters
    ----------
    base_draws : np.ndarray
        iid standard normal draws
    updated_mean : np.ndarray
        conditional mean, given the observed shock. Contains the observed shock in the
        corresponding position.
    updated_chols : np.ndarray
        cholesky factor of conditional covariance, given the observed shock. If there is
        no measurement error, it contains a zero column and row at the position of the
        observed shock.
    chol_index : float
        index of the relevant updated cholesky factor
    max_log_float : float
        Value at which numbers soon to be exponentiated are clipped.

    Returns
    -------
    conditional draws : np.ndarray
        draws from the conditional distribution of the shocks.

    """
    n_draws, n_choices = base_draws.shape
    n_wages = len(updated_chols) - 1

    for d in range(n_draws):
        for i in range(n_choices):
            cd = updated_mean[i]
            for j in range(i + 1):
                cd += base_draws[d, j] * updated_chols[chol_index, i, j]
            if i < n_wages:
                if cd > max_log_float:
                    cd = max_log_float
                cd = np.exp(cd)
            conditional_draw[d, i] = cd 
开发者ID:OpenSourceEconomics,项目名称:respy,代码行数:45,代码来源:conditional_draws.py


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