Special

Special#

Special functions for neural networks.

nabla.ops.special.softmax(arg, axis=-1)[source]#

Compute softmax function in a numerically stable way.

Parameters:
  • arg (Array) – Input array

  • axis (int) – Axis along which to compute softmax

Returns:

Array containing softmax probabilities

Return type:

Array

nabla.ops.special.logsumexp(arg, axis=None, keep_dims=False)[source]#

Compute log(sum(exp(x))) in a numerically stable way.

Parameters:
  • arg (Array) – Input array

  • axis (int | None) – Axis along which to compute logsumexp. If None, compute over all elements.

  • keep_dims (bool) – Whether to keep reduced dimensions

Returns:

Array containing logsumexp values

Return type:

Array

nabla.ops.special.where(condition, x, y)[source]#

Element-wise selection from x or y based on condition.

Parameters:
  • condition (Array) – Boolean array for selection

  • x (Array) – Array to select from where condition is True

  • y (Array) – Array to select from where condition is False

Returns:

Array with elements selected from x or y

Return type:

Array

nabla.ops.special.cond(condition, true_fn, false_fn, *args, **kwargs)[source]#

Conditional execution based on a boolean condition.

Parameters:
  • condition (Array) – Boolean array determining which function to execute

  • true_fn (Callable) – Function to execute if condition is True

  • false_fn (Callable) – Function to execute if condition is False

  • *args – Arguments passed to the selected function

  • **kwargs

    Arguments passed to the selected function

Returns:

Result of the executed function

Return type:

Array