spine.math.base

Numba JIT compiled implementation of basic functions.

Most of these functions are implemented here because vanilla numba does not support optional arguments, such as axis for most functions or return_counts for the unique function.

Functions

all(x, axis)

Numba implementation of np.all(x, axis).

amax(x, axis)

Numba implementation of np.amax(x, axis).

amin(x, axis)

Numba implementation of np.amin(x, axis).

argmax(x, axis)

Numba implementation of np.argmax(x, axis).

argmin(x, axis)

Numba implementation of np.argmin(x, axis).

log_loss(label, pred)

Numba implementation of cross-entropy loss.

mean(x, axis)

Numba implementation of np.mean(x, axis).

mode(x)

Numba implementation of scipy.stats.mode(x).

seed(seed_value)

Sets the numpy random seed for all Numba jitted functions.

softmax(x, axis)

Numba implementation of scipy.special.softmax(x, axis).

sum(x, axis)

Numba implementation of np.sum(x, axis).

unique(x)

Numba implementation of np.unique(x, return_counts=True).

spine.math.base.seed(seed_value: int) None[source]

Sets the numpy random seed for all Numba jitted functions.

Note that setting the seed using np.random.seed outside a Numba jitted function does not set the seed of Numba functions.

Parameters:

seed_value (int) – Random number generator seed

spine.math.base.unique(x: ndarray) tuple[ndarray, ndarray][source]

Numba implementation of np.unique(x, return_counts=True).

Parameters:

x (np.ndarray) – (N,) array of values

Returns:

  • np.ndarray – (U,) array of unique values

  • np.ndarray – (U,) array of counts of each unique value in the original array

spine.math.base.sum(x: ndarray, axis: int) ndarray[source]

Numba implementation of np.sum(x, axis).

Parameters:
  • x (np.ndarray) – (N, M) array of values

  • axis (int) – Array axis ID

Returns:

(N,) or (M,) array of sum values

Return type:

np.ndarray

spine.math.base.mean(x: ndarray, axis: int) ndarray[source]

Numba implementation of np.mean(x, axis).

Parameters:
  • x (np.ndarray) – (N, M) array of values

  • axis (int) – Array axis ID

Returns:

(N,) or (M,) array of mean values

Return type:

np.ndarray

spine.math.base.mode(x: ndarray) int[source]

Numba implementation of scipy.stats.mode(x).

Parameters:

x (np.ndarray) – (N,) array of values

Returns:

Most-probable value in the array

Return type:

int

spine.math.base.argmax(x: ndarray, axis: int) ndarray[source]

Numba implementation of np.argmax(x, axis).

Parameters:
  • x (np.ndarray) – (N, M) array of values

  • axis (int) – Array axis ID

Returns:

(N,) or (M,) array of argmax values

Return type:

np.ndarray

spine.math.base.argmin(x: ndarray, axis: int) ndarray[source]

Numba implementation of np.argmin(x, axis).

Parameters:
  • x (np.ndarray) – (N, M) array of values

  • axis (int) – Array axis ID

Returns:

(N,) or (M,) array of argmin values

Return type:

np.ndarray

spine.math.base.amax(x: ndarray, axis: int) ndarray[source]

Numba implementation of np.amax(x, axis).

Parameters:
  • x (np.ndarray) – (N, M) array of values

  • axis (int) – Array axis ID

Returns:

(N,) or (M,) array of max values

Return type:

np.ndarray

spine.math.base.amin(x: ndarray, axis: int) ndarray[source]

Numba implementation of np.amin(x, axis).

Parameters:
  • x (np.ndarray) – (N, M) array of values

  • axis (int) – Array axis ID

Returns:

(N,) or (M,) array of min values

Return type:

np.ndarray

spine.math.base.all(x: ndarray, axis: int) ndarray[source]

Numba implementation of np.all(x, axis).

Parameters:
  • x (np.ndarray) – (N, M) Array of values

  • axis (int) – Array axis ID

Returns:

(N,) or (M,) array of all outputs

Return type:

np.ndarray

spine.math.base.softmax(x: ndarray, axis: int) ndarray[source]

Numba implementation of scipy.special.softmax(x, axis).

Parameters:
  • x (np.ndarray) – (N, M) array of values

  • axis (int) – Array axis ID

Returns:

(N, M) array of softmax scores

Return type:

np.ndarray

spine.math.base.log_loss(label: ndarray, pred: ndarray) float[source]

Numba implementation of cross-entropy loss.

Parameters:
  • label (np.ndarray) – (N,) array of boolean labels (0 or 1)

  • pred (np.ndarray) – (N,) array of float scores (between 0 and 1)

Returns:

Cross-entropy loss

Return type:

float