Backend#

class caskade.backend.Backend(backend=None)[source]#

Unified interface for array operations across torch, jax, and numpy.

Provides a single API for creating and manipulating arrays regardless of the underlying library. Methods such as make_array, concatenate, to, sigmoid, and logit are dynamically bound when the backend is set, delegating to the appropriate library-specific implementation.

Parameters:

backend (str, optional) – Backend name: "torch", "jax", or "numpy". If None, reads from the CASKADE_BACKEND environment variable, defaulting to "torch".

Examples

Use the module-level backend instance to switch backends:

from caskade import backend
backend.backend = "numpy"
arr = backend.make_array([1.0, 2.0, 3.0])
all(array)[source]#

Test whether all elements evaluate to True.

Parameters:

array (ArrayLike) – Input array.

Returns:

Scalar result; True if every element is non-zero.

Return type:

ArrayLike

any(array)[source]#

Test whether any element evaluates to True.

Parameters:

array (ArrayLike) – Input array.

Returns:

Scalar result; True if any element is non-zero.

Return type:

ArrayLike

property array_type#

The array class for the active backend.

Returns torch.Tensor, jax.numpy.ndarray, or numpy.ndarray depending on the current backend. Useful for isinstance checks.

Returns:

The array class used by the active backend.

Return type:

type

Examples

isinstance(my_array, backend.array_type)
Type:

type

property backend#

Name of the active backend ("torch", "jax", or "numpy").

Type:

str

exp(array)[source]#

Compute the exponential element-wise.

Parameters:

array (ArrayLike) – Input array.

Returns:

Element-wise exponential of the input.

Return type:

ArrayLike

log(array)[source]#

Compute the natural logarithm element-wise.

Parameters:

array (ArrayLike) – Input array.

Returns:

Element-wise natural logarithm of the input.

Return type:

ArrayLike

sum(array, axis=None)[source]#

Sum array elements over a given axis.

Parameters:
  • array (ArrayLike) – Input array.

  • axis (int or None, optional) – Axis along which to sum. If None, sums all elements.

Returns:

Sum of elements.

Return type:

ArrayLike

caskade.backend.backend = <caskade.backend.Backend object>#

Module-level Backend instance used as the default entry point. Import and configure this object to switch backends globally:

from caskade import backend
backend.backend = "numpy"