improver.ensemble_copula_coupling.numba_utilities module

improver.ensemble_copula_coupling.numba_utilities module#

This module defines the optional numba utilities for Ensemble Copula Coupling plugins.

fast_interp_same_x(x, xp, fp)#

For each row i of fp, do the equivalent of np.interp(x, xp, fp[i, :]). :type x: ndarray :param x: 1-D array :type xp: ndarray :param xp: 1-D array, sorted in non-decreasing order :type fp: ndarray :param fp: 2-D array with len(xp) columns

Return type:

ndarray

Returns:

2-D array with shape (len(fp), len(x)), with each row i equal to

np.interp(x, xp, fp[i, :])

Raises:

ValueError – if the input arrays do not have the expected dimensions.

fast_interp_same_y(x, xp, fp)#

For each row i of xp, do the equivalent of np.interp(x, xp[i], fp). :type x: ndarray :param x: 1-d array :type xp: ndarray :param xp: n * m array, each row must be in non-decreasing order :type fp: ndarray :param fp: 1-d array with length m

Return type:

ndarray

Returns:

n * len(x) array where each row i is equal to np.interp(x, xp[i], fp)

Raises:

ValueError – if the input arrays do not have the expected dimensions.

fast_interp_same_y_2d(x, xp, fp)#

For each row i of xp, do the equivalent of np.interp(x[i], xp[i], fp). This function is distinct from fast_interp_same_y for compatibility with numba. The function is essentially the same as fast_interp_same_y but with an additional loop over rows to handle a 2-D x array.

Parameters:
  • x (ndarray) – 2-D array with one row per xp row (shape: n * k)

  • xp (ndarray) – n * m array, each row must be in non-decreasing order

  • fp (ndarray) – 1-D array with length m

Return type:

ndarray

Returns:

n * k array where each row i is equal to np.interp(x[i], xp[i], fp)

Raises:

ValueError – if the input arrays do not have the expected dimensions.

fast_interp_same_y_nd(x, xp, fp)[source]#

Dispatch to 1D or 2D numba kernels.

Parameters:
  • x (ndarray) – 1-D or 2-D array

  • xp (ndarray) – n * m array, each row must be in non-decreasing order

  • fp (ndarray) – 1-D array with length m

Return type:

ndarray

Returns:

If x is 1-D, returns n * len(x) array where each row i is equal to

np.interp(x, xp[i], fp).

If x is 2-D, returns n * k array where each row i is equal to

np.interp(x[i], xp[i], fp).

Raises:

ValueError – If x is not 1-D or 2-D.