Backend API#
Backend classes define the execution layer used by spaces and linear operators.
Backend-agnostic numerical ops interface (portable core). |
|
BackendOps implementation for the NumPy/SciPy ecosystem. |
|
BackendOps implementation for the JAX ecosystem. |
|
BackendOps implementation for PyTorch tensors. |
BackendOps#
- class spacecore.backend.BackendOps[source]#
Bases:
ABCBackend-agnostic numerical ops interface (portable core).
- Contract:
This base class exposes only the portable subset used by library internals.
Concrete backends (NumPy/JAX/Torch) may extend these methods with additional optional keyword parameters (e.g., order=, out=, where=, like=, …).
- property family: str#
Generic backend-agnostic wrapper to backend family identifier.
- Input:
None.
- Output:
String naming the concrete backend family.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- property allow_sparse: bool#
Generic backend-agnostic wrapper to sparse-array support flag.
- Input:
None.
- Output:
Boolean indicating whether this backend supports sparse arrays.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- abstract property dense_array: Type[Any]#
Generic backend-agnostic wrapper to dense array type.
- Input:
None.
- Output:
Concrete dense array class accepted by this backend.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- abstract property sparse_array: Tuple[Type[Any], ...] | None#
Generic backend-agnostic wrapper to sparse array type tuple.
- Input:
None.
- Output:
Concrete sparse array classes accepted by this backend, or None.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- abstractmethod sanitize_dtype(dtype)[source]#
Generic backend-agnostic wrapper to normalize a dtype specifier.
- Input:
dtype: Optional dtype requested by SpaceCore or the caller.
- Output:
Backend dtype object accepted by array constructors.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
dtype (Any | None)
- Return type:
Any
- is_dense(x)[source]#
Generic backend-agnostic wrapper to test for a dense backend array.
- Input:
x: Object to test.
- Output:
True when x is an instance of the backend dense array type.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
bool
- is_sparse(x)[source]#
Generic backend-agnostic wrapper to test for a sparse backend array.
- Input:
x: Object to test.
- Output:
True when x is an instance of a backend sparse array type.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
bool
- is_array(x)[source]#
Generic backend-agnostic wrapper to test for any backend array.
- Input:
x: Object to test.
- Output:
True when x is dense or sparse for this backend.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
bool
- abstractmethod get_dtype(x)[source]#
Generic backend-agnostic wrapper to return an array dtype.
- Input:
x: Dense or sparse backend array.
- Output:
Backend dtype associated with x.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
Any
- abstractmethod shape(x)[source]#
Generic backend-agnostic wrapper to return array shape metadata.
- Input:
x: Dense or sparse backend array.
- Output:
Tuple describing the logical shape of x.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
tuple[int, …]
- abstractmethod ndim(x)[source]#
Generic backend-agnostic wrapper to return array rank metadata.
- Input:
x: Dense or sparse backend array.
- Output:
Number of dimensions in x.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
int
- abstractmethod size(x)[source]#
Generic backend-agnostic wrapper to return logical element count.
- Input:
x: Dense or sparse backend array.
- Output:
Total number of logical dense elements.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
int
- abstract property inf: DenseArray#
Generic backend-agnostic wrapper to positive infinity scalar.
- Input:
None.
- Output:
Backend scalar representing positive infinity.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- abstract property nan: DenseArray#
Generic backend-agnostic wrapper to access a NaN scalar.
- Input:
None.
- Output:
Backend scalar representing NaN.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- abstract property pi: DenseArray#
Generic backend-agnostic wrapper to pi scalar.
- Input:
None.
- Output:
Backend scalar representing pi.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- abstract property e: DenseArray#
Generic backend-agnostic wrapper to access Euler’s number scalar.
- Input:
None.
- Output:
Backend scalar representing Euler’s number.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- abstract property eps: DenseArray#
Generic backend-agnostic wrapper to machine epsilon scalar.
- Input:
None.
- Output:
Backend scalar for float64 machine epsilon.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- abstractmethod asarray(x, dtype=None)[source]#
Generic backend-agnostic wrapper to convert input to a dense array.
- Input:
x/a: Array-like input and optional dtype or backend conversion parameters.
- Output:
Dense backend array.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod astype(x, dtype)[source]#
Generic backend-agnostic wrapper to cast an array to a dtype.
- Input:
x: Dense backend array; dtype: target dtype and optional casting controls.
- Output:
Dense backend array with the requested dtype.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
dtype (Any)
- Return type:
DenseArray
- abstractmethod assparse(x, dtype=None)[source]#
Generic backend-agnostic wrapper to convert input to a sparse array.
- Input:
x: Dense, sparse, or array-like input plus sparse-format options.
- Output:
Sparse backend array.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
dtype (Any | None)
- Return type:
SparseArray
- abstractmethod empty(shape, dtype=None)[source]#
Generic backend-agnostic wrapper to create an uninitialized dense array.
- Input:
shape: Output shape; dtype and placement options are backend-specific.
- Output:
Dense backend array with uninitialized values.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
shape (Tuple[int, ...])
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod zeros(shape, dtype=None)[source]#
Generic backend-agnostic wrapper to create a zero-filled dense array.
- Input:
shape: Output shape; dtype and placement options are backend-specific.
- Output:
Dense backend array filled with zeros.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
shape (Tuple[int, ...])
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod ones(shape, dtype=None)[source]#
Generic backend-agnostic wrapper to create a one-filled dense array.
- Input:
shape: Output shape; dtype and placement options are backend-specific.
- Output:
Dense backend array filled with ones.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
shape (Tuple[int, ...])
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod zeros_like(x, dtype=None)[source]#
Generic backend-agnostic wrapper to create zeros shaped like another array.
- Input:
x: Prototype dense array; dtype, shape, and placement options are backend-specific.
- Output:
Dense backend array of zeros.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod ones_like(x, dtype=None)[source]#
Generic backend-agnostic wrapper to create ones shaped like another array.
- Input:
x: Prototype dense array; dtype, shape, and placement options are backend-specific.
- Output:
Dense backend array of ones.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod full_like(x, value, dtype=None)[source]#
Generic backend-agnostic wrapper to create filled values shaped like another array.
- Input:
x: Prototype dense array; value/fill_value and dtype options are backend-specific.
- Output:
Dense backend array filled with the requested value.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
value (Any)
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod arange(start, stop=None, step=None, dtype=None)[source]#
Generic backend-agnostic wrapper to create evenly spaced integer-range values.
- Input:
start, stop, step: Range parameters; dtype and placement options are backend-specific.
- Output:
One-dimensional dense backend array.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
start (int)
stop (int | None)
step (int | None)
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod full(shape, fill_value, dtype=None)[source]#
Generic backend-agnostic wrapper to create a filled dense array.
- Input:
shape: Output shape; fill_value and dtype options are backend-specific.
- Output:
Dense backend array filled with fill_value.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
shape (Tuple[int, ...])
fill_value (Any)
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod eye(n, m=None, dtype=None)[source]#
Generic backend-agnostic wrapper to create a dense identity-like matrix.
- Input:
n and optional m: Matrix dimensions; dtype and placement options are backend-specific.
- Output:
Two-dimensional dense backend array.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
n (int)
m (int | None)
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod ravel(x)[source]#
Generic backend-agnostic wrapper to flatten an array.
- Input:
x: Dense backend array plus optional order parameters.
- Output:
One-dimensional dense backend array view or copy.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod reshape(x, shape)[source]#
Generic backend-agnostic wrapper to reshape an array.
- Input:
x: Dense backend array; shape: New shape plus backend-specific options.
- Output:
Dense backend array with the requested shape.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
shape (Tuple[int, ...] | int)
- Return type:
DenseArray
- abstractmethod transpose(x, axes=None)[source]#
Generic backend-agnostic wrapper to permute array axes.
- Input:
x: Dense backend array; axes: Optional axis order.
- Output:
Dense backend array with permuted axes.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axes (Sequence[int] | None)
- Return type:
DenseArray
- abstractmethod swapaxes(x, axis1, axis2)[source]#
Generic backend-agnostic wrapper to interchange two axes.
- Input:
x: Dense backend array; axis1 and axis2: Axes to swap.
- Output:
Dense backend array with the two axes exchanged.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis1 (int)
axis2 (int)
- Return type:
DenseArray
- abstractmethod broadcast_to(x, shape)[source]#
Generic backend-agnostic wrapper to broadcast an array to a shape.
- Input:
x: Dense backend array; shape: Target broadcast shape.
- Output:
Dense backend array with broadcast shape.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
shape (Tuple[int, ...])
- Return type:
DenseArray
- abstractmethod expand_dims(x, axis)[source]#
Generic backend-agnostic wrapper to insert length-one axes.
- Input:
x: Dense backend array; axis: Position or positions to insert.
- Output:
Dense backend array with expanded rank.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int | Sequence[int])
- Return type:
DenseArray
- abstractmethod squeeze(x, axis=None)[source]#
Generic backend-agnostic wrapper to remove length-one axes.
- Input:
x: Dense backend array; axis: Optional axes to squeeze.
- Output:
Dense backend array with selected singleton dimensions removed.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
- Return type:
DenseArray
- abstractmethod moveaxis(x, source, destination)[source]#
Generic backend-agnostic wrapper to move axes to new positions.
- Input:
x: Dense backend array; source and destination: Axis positions.
- Output:
Dense backend array with moved axes.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
source (int | Sequence[int])
destination (int | Sequence[int])
- Return type:
DenseArray
- abstractmethod stack(arrays, axis=0)[source]#
Generic backend-agnostic wrapper to stack arrays along a new axis.
- Input:
arrays: Sequence of dense backend arrays; axis: New axis position.
- Output:
Dense backend array containing stacked inputs.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
arrays (Sequence[DenseArray])
axis (int)
- Return type:
DenseArray
- abstractmethod conj(x)[source]#
Generic backend-agnostic wrapper to compute complex conjugates.
- Input:
x: Dense backend array.
- Output:
Dense backend array with conjugated values.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod real(x)[source]#
Generic backend-agnostic wrapper to extract real components.
- Input:
x: Dense backend array.
- Output:
Dense backend array containing real components.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod imag(x)[source]#
Generic backend-agnostic wrapper to extract imaginary components.
- Input:
x: Dense backend array.
- Output:
Dense backend array containing imaginary components.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod abs(x)[source]#
Generic backend-agnostic wrapper to compute absolute values.
- Input:
x: Dense backend array.
- Output:
Dense backend array of absolute values.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod sign(x)[source]#
Generic backend-agnostic wrapper to compute signs elementwise.
- Input:
x: Dense backend array.
- Output:
Dense backend array of signs.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod sqrt(x)[source]#
Generic backend-agnostic wrapper to compute square roots elementwise.
- Input:
x: Dense backend array.
- Output:
Dense backend array of square roots.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod sum(x, axis=None, keepdims=False, dtype=None)[source]#
Generic backend-agnostic wrapper to reduce by summation.
- Input:
x: Dense backend array; axis, keepdims, and dtype control the reduction.
- Output:
Dense backend array or scalar containing sums.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
keepdims (bool)
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod mean(x, axis=None, keepdims=False)[source]#
Generic backend-agnostic wrapper to reduce by arithmetic mean.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense backend array or scalar containing means.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
keepdims (bool)
- Return type:
DenseArray
- abstractmethod min(x, axis=None, keepdims=False)[source]#
Generic backend-agnostic wrapper to reduce by minimum.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense backend array or scalar containing minima.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
keepdims (bool)
- Return type:
DenseArray
- abstractmethod max(x, axis=None, keepdims=False)[source]#
Generic backend-agnostic wrapper to reduce by maximum.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense backend array or scalar containing maxima.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
keepdims (bool)
- Return type:
DenseArray
- abstractmethod prod(x, axis=None, keepdims=False, dtype=None)[source]#
Generic backend-agnostic wrapper to reduce by product.
- Input:
x: Dense backend array; axis, keepdims, and dtype control the reduction.
- Output:
Dense backend array or scalar containing products.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
keepdims (bool)
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod trace(x)[source]#
Generic backend-agnostic wrapper to sum diagonal entries.
- Input:
x: Dense backend array plus optional diagonal and axis controls.
- Output:
Dense backend array or scalar containing trace values.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod argsort(x, axis=-1)[source]#
Generic backend-agnostic wrapper to return sorting indices.
- Input:
x: Dense backend array; axis and ordering options are backend-specific.
- Output:
Dense integer backend array of indices.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int)
- Return type:
DenseArray
- abstractmethod sort(x, axis=-1)[source]#
Generic backend-agnostic wrapper to sort values.
- Input:
x: Dense backend array; axis and ordering options are backend-specific.
- Output:
Dense backend array with sorted values.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int)
- Return type:
DenseArray
- abstractmethod argmin(x, axis=None, keepdims=False)[source]#
Generic backend-agnostic wrapper to return indices of minimum values.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense integer backend array or scalar of indices.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int | None)
keepdims (bool)
- Return type:
DenseArray
- abstractmethod argmax(x, axis=None, keepdims=False)[source]#
Generic backend-agnostic wrapper to return indices of maximum values.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense integer backend array or scalar of indices.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
axis (int | None)
keepdims (bool)
- Return type:
DenseArray
- abstractmethod vdot(x, y)[source]#
Generic backend-agnostic wrapper to compute a conjugating vector dot product.
- Input:
x, y: Dense backend arrays accepted by the backend vdot operation.
- Output:
Backend scalar or dense array containing the dot product.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
y (DenseArray)
- Return type:
DenseArray
- abstractmethod matmul(a, b)[source]#
Generic backend-agnostic wrapper to compute matrix products.
- Input:
a, b: Dense backend arrays with matrix-multiplication-compatible shapes.
- Output:
Dense backend array containing the product.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
a (DenseArray)
b (DenseArray)
- Return type:
DenseArray
- abstractmethod sparse_matmul(a, b)[source]#
Generic backend-agnostic wrapper to multiply sparse and dense arrays.
- Input:
a: Sparse backend array; b: Dense backend array.
- Output:
Dense backend array containing the product.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
a (SparseArray)
b (DenseArray)
- Return type:
DenseArray
- abstractmethod kron(a, b)[source]#
Generic backend-agnostic wrapper to compute a Kronecker product.
- Input:
a, b: Dense backend arrays.
- Output:
Dense backend array containing the Kronecker product.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
a (DenseArray)
b (DenseArray)
- Return type:
DenseArray
- abstractmethod einsum(subscripts, *operands)[source]#
Generic backend-agnostic wrapper to evaluate an Einstein summation expression.
- Input:
subscripts: Einstein summation string; operands: Dense backend arrays.
- Output:
Dense backend array containing the contraction result.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
subscripts (str)
operands (DenseArray)
- Return type:
DenseArray
- abstractmethod eigh(x)[source]#
Generic backend-agnostic wrapper to compute Hermitian eigenpairs.
- Input:
x: Dense Hermitian or symmetric backend array.
- Output:
Tuple of dense backend arrays containing eigenvalues and eigenvectors.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
tuple[DenseArray, DenseArray]
- abstractmethod norm(x, ord=None, axis=None, keepdims=False)[source]#
Generic backend-agnostic wrapper to compute vector or matrix norms.
- Input:
x: Dense backend array; ord, axis, and keepdims select the norm.
- Output:
Dense backend array or scalar containing norm values.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
ord (int | str | None)
axis (int | Sequence[int] | None)
keepdims (bool)
- Return type:
DenseArray
- abstractmethod solve(A, b)[source]#
Generic backend-agnostic wrapper to solve dense linear systems.
- Input:
A: Dense coefficient array; b: Dense right-hand side array.
- Output:
Dense backend array solving A @ x = b.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
A (DenseArray)
b (DenseArray)
- Return type:
DenseArray
- abstractmethod eigvalsh(A)[source]#
Generic backend-agnostic wrapper to compute Hermitian eigenvalues.
- Input:
A: Dense Hermitian or symmetric backend array.
- Output:
Dense backend array containing eigenvalues.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
A (DenseArray)
- Return type:
DenseArray
- abstractmethod svd(A, full_matrices=True)[source]#
Generic backend-agnostic wrapper to compute singular value decompositions.
- Input:
A: Dense backend array plus SVD options.
- Output:
Dense backend arrays containing singular vectors and/or singular values.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
A (DenseArray)
full_matrices (bool)
- Return type:
tuple[DenseArray, DenseArray, DenseArray]
- abstractmethod cholesky(A)[source]#
Generic backend-agnostic wrapper to compute Cholesky factors.
- Input:
A: Dense Hermitian positive-definite backend array.
- Output:
Dense backend array containing a triangular factor.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
A (DenseArray)
- Return type:
DenseArray
- abstractmethod logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False)[source]#
Generic backend-agnostic wrapper to compute a stable log-sum-exp reduction.
- Input:
a: Dense backend array; axis, weights, and sign options control the reduction.
- Output:
Dense backend array or tuple containing log-sum-exp results.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
b (DenseArray | None)
keepdims (bool)
return_sign (bool)
- Return type:
DenseArray | Tuple[DenseArray, DenseArray]
- abstractmethod exp(x)[source]#
Generic backend-agnostic wrapper to compute exponentials elementwise.
- Input:
x: Dense backend array.
- Output:
Dense backend array of exponentials.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod log(x)[source]#
Generic backend-agnostic wrapper to compute natural logarithms elementwise.
- Input:
x: Dense backend array.
- Output:
Dense backend array of logarithms.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod where(condition, x, y)[source]#
Generic backend-agnostic wrapper to select values by condition.
- Input:
condition: Boolean array or scalar; x and y: Values to choose between.
- Output:
Dense backend array containing selected values.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
condition (DenseArray | bool)
x (ArrayLike)
y (ArrayLike)
- Return type:
DenseArray
- abstractmethod maximum(x, y)[source]#
Generic backend-agnostic wrapper to compute elementwise maxima.
- Input:
x, y: Arrays or scalars accepted by backend broadcasting.
- Output:
Dense backend array containing maxima.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (ArrayLike)
y (ArrayLike)
- Return type:
DenseArray
- abstractmethod minimum(x, y)[source]#
Generic backend-agnostic wrapper to compute elementwise minima.
- Input:
x, y: Arrays or scalars accepted by backend broadcasting.
- Output:
Dense backend array containing minima.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (ArrayLike)
y (ArrayLike)
- Return type:
DenseArray
- abstractmethod clip(x, a_min, a_max)[source]#
Generic backend-agnostic wrapper to clip values into an interval.
- Input:
x: Dense backend array; a_min and a_max: Broadcastable bounds.
- Output:
Dense backend array with clipped values.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
a_min (ArrayLike)
a_max (ArrayLike)
- Return type:
DenseArray
- abstractmethod isfinite(x)[source]#
Generic backend-agnostic wrapper to test finiteness elementwise.
- Input:
x: Dense backend array.
- Output:
Boolean dense backend array.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod isnan(x)[source]#
Generic backend-agnostic wrapper to test NaN values elementwise.
- Input:
x: Dense backend array.
- Output:
Boolean dense backend array.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod concatenate(arrays, axis=0, dtype=None)[source]#
Generic backend-agnostic wrapper to join arrays along an existing axis.
- Input:
arrays: Sequence of dense backend arrays; axis and dtype options are backend-specific.
- Output:
Dense backend array containing concatenated inputs.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
arrays (Sequence[DenseArray])
axis (int)
dtype (Any | None)
- Return type:
DenseArray
- abstractmethod take(x, indices, axis=None)[source]#
Generic backend-agnostic wrapper to take values by integer indices.
- Input:
x: Dense backend array; indices: Integer indices; axis and mode options are backend-specific.
- Output:
Dense backend array containing selected values.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
indices (DenseArray)
axis (int | None)
- Return type:
DenseArray
- abstractmethod diag(x)[source]#
Generic backend-agnostic wrapper to extract or build a diagonal.
- Input:
x: Dense backend array and optional diagonal offset.
- Output:
Dense backend array containing a diagonal view/copy or matrix.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod diagonal(x)[source]#
Generic backend-agnostic wrapper to return selected diagonals.
- Input:
x: Dense backend array plus offset and axis controls.
- Output:
Dense backend array containing selected diagonals.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod tril(x)[source]#
Generic backend-agnostic wrapper to return lower-triangular values.
- Input:
x: Dense backend array and optional diagonal offset.
- Output:
Dense backend array with upper entries zeroed.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod triu(x)[source]#
Generic backend-agnostic wrapper to return upper-triangular values.
- Input:
x: Dense backend array and optional diagonal offset.
- Output:
Dense backend array with lower entries zeroed.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abstractmethod index_set(x, index, values, *, copy=True)[source]#
Generic backend-agnostic wrapper to set indexed values.
- Input:
x: Dense backend array; index: Selection; values: Replacement values; copy controls mutation policy.
- Output:
Dense backend array with indexed values set.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
index (int | slice | Any | Tuple[Any, ...])
values (ArrayLike)
copy (bool)
- Return type:
DenseArray
- abstractmethod index_add(x, index, values, *, copy=True)[source]#
Generic backend-agnostic wrapper to add into indexed values.
- Input:
x: Dense backend array; index: Selection; values: Values to add; copy controls mutation policy.
- Output:
Dense backend array with indexed values incremented.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (DenseArray)
index (int | slice | Any | Tuple[Any, ...])
values (DenseArray)
copy (bool)
- Return type:
DenseArray
- abstractmethod ix_(*args)[source]#
Generic backend-agnostic wrapper to build open mesh index arrays.
- Input:
args: One-dimensional index arrays or sequences.
- Output:
Tuple of dense backend arrays usable for open-mesh indexing.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
args (Any)
- Return type:
Any
- abstractmethod fori_loop(lower, upper, body_fun, init_val)[source]#
Generic backend-agnostic wrapper to run a counted loop primitive.
- Input:
lower, upper: Loop bounds; body_fun: Loop body; init_val: Initial carry value.
- Output:
Final carry value after loop execution.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
lower (int)
upper (int)
body_fun (Callable[[int, T], T])
init_val (T)
- Return type:
T
- abstractmethod while_loop(cond_fun, body_fun, init_val)[source]#
Generic backend-agnostic wrapper to run a while-loop primitive.
- Input:
cond_fun: Loop condition; body_fun: Loop body; init_val: Initial carry value.
- Output:
Final carry value after loop execution.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
cond_fun (Callable[[T], bool])
body_fun (Callable[[T], T])
init_val (T)
- Return type:
T
- abstractmethod scan(f, init, xs, length=None, reverse=False, unroll=1)[source]#
Generic backend-agnostic wrapper to run a scan primitive.
- Input:
f: Scan body; init: Initial carry; xs: Per-step inputs plus scan options.
- Output:
Tuple of final carry and stacked outputs.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
f (Callable[[Carry, X], Tuple[Carry, Y]])
init (Carry)
xs (X)
length (int | None)
reverse (bool)
unroll (int)
- Return type:
Tuple[Carry, Y]
- abstractmethod cond(pred, true_fun, false_fun, *operands)[source]#
Generic backend-agnostic wrapper to run conditional branch selection.
- Input:
pred: Predicate; true_fun and false_fun: Branch functions; operands: Branch inputs.
- Output:
Result returned by the selected branch.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
pred (bool)
true_fun (Callable[[T], R])
false_fun (Callable[[T], R])
operands (Any)
- Return type:
R
- abstractmethod allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]#
Generic backend-agnostic wrapper to compare dense arrays elementwise within tolerances.
- Input:
a, b: Dense backend arrays; rtol, atol, and equal_nan configure comparison.
- Output:
Boolean indicating whether arrays are close.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
a (DenseArray)
b (DenseArray)
rtol (float)
atol (float)
equal_nan (bool)
- Return type:
bool
- abstractmethod allclose_sparse(a, b, rtol=1e-05, atol=1e-08)[source]#
Generic backend-agnostic wrapper to compare sparse arrays elementwise within tolerances.
- Input:
a, b: Sparse backend arrays; rtol and atol configure comparison.
- Output:
Boolean indicating whether sparse arrays are close.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
a (SparseArray)
b (SparseArray)
rtol (float)
atol (float)
- Return type:
bool
NumpyOps#
- class spacecore.backend.NumpyOps[source]#
Bases:
BackendOpsBackendOps implementation for the NumPy/SciPy ecosystem.
This backend uses NumPy for dense array operations and SciPy for sparse array operations.
- Dense arrays
numpy.ndarray
- Sparse arrays
scipy.sparse.spmatrix scipy.sparse.sparray
- Methods
Most methods mirror the corresponding NumPy or SciPy signatures and delegate directly to NumPy/SciPy implementations. Backend-specific behavior, dtype promotion, broadcasting, memory layout, and error modes therefore follow NumPy/SciPy semantics.
- Backend handles
np : module NumPy module stored on the class and available through instances as ops.np. Advanced users may use it when SpaceCore’s portable API does not expose a required NumPy feature.
sp : module SciPy module stored on the class and available through instances as ops.sp. Advanced users may use it for SciPy-specific functionality.
- Notes
Code intended to remain backend-portable should prefer BackendOps methods. Direct use of ops.np or ops.sp is an explicit NumPy/SciPy-specific escape hatch.
NumPy’s device keyword is present for Array API interoperability. When supplied, it must be “cpu” or None; see the corresponding NumPy documentation for each method.
- property dense_array: Type[Any]#
Dense array type using NumPy.
- Returns:
Concrete dense array class accepted by this backend.
- property sparse_array: Tuple[Type[Any], ...]#
Sparse array type tuple using SciPy.
- Returns:
Concrete sparse array classes accepted by this backend, or None.
- sanitize_dtype(dtype)[source]#
Normalize a dtype specifier using NumPy.
- Input:
dtype: Optional dtype requested by SpaceCore or the caller.
- Output:
Backend dtype object accepted by array constructors.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.dtype.html
- Parameters:
dtype (Any | None)
- Return type:
Any
- get_dtype(x)[source]#
Return an array dtype using NumPy.
- Input:
x: Dense or sparse backend array.
- Output:
Backend dtype associated with x.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.dtype.html
- Parameters:
x (Any)
- Return type:
Any
- shape(x)[source]#
Return array shape metadata using NumPy.
- Input:
x: Dense or sparse backend array.
- Output:
Tuple describing the logical shape of x.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html
- Parameters:
x (Any)
- Return type:
tuple[int, …]
- ndim(x)[source]#
Return array rank metadata using NumPy.
- Input:
x: Dense or sparse backend array.
- Output:
Number of dimensions in x.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.ndim.html
- Parameters:
x (Any)
- Return type:
int
- size(x)[source]#
Return logical element count using NumPy.
- Input:
x: Dense or sparse backend array.
- Output:
Total number of logical dense elements.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.size.html
- Backend-specific notes:
SciPy sparse inputs are reported by logical dense size, not stored entries.
- Parameters:
x (Any)
- Return type:
int
- property inf#
Positive infinity scalar using NumPy.
- Returns:
Backend scalar representing positive infinity.
- property nan#
NaN scalar using NumPy.
- Returns:
Backend scalar representing NaN.
- property pi#
Pi scalar using NumPy.
- Returns:
Backend scalar representing pi.
- property e#
Euler number scalar using NumPy.
- Returns:
Backend scalar representing Euler’s number.
- property eps#
Machine epsilon scalar using NumPy.
- Returns:
Backend scalar for float64 machine epsilon.
- asarray(a, dtype=None, order=None, *, device=None, copy=None, like=None)[source]#
Convert input to a dense array using NumPy.
- Input:
x/a: Array-like input and optional dtype or backend conversion parameters.
- Output:
Dense backend array.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.asarray.html
- Parameters:
a (Any)
dtype (Any | None)
order (Literal['C', 'F', 'A', 'K'] | None)
device (str | None)
copy (bool | None)
like (DenseArray | None)
- Return type:
DenseArray
- astype(x, dtype, order='K', casting='unsafe', subok=True, copy=True)[source]#
Cast an array to a dtype using NumPy.
- Input:
x: Dense backend array; dtype: target dtype and optional casting controls.
- Output:
Dense backend array with the requested dtype.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.astype.html
- Parameters:
x (DenseArray)
dtype (Any)
order (Literal['C', 'F', 'A', 'K'])
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
subok (bool)
copy (bool)
- Return type:
DenseArray
- assparse(x, *, format='csr', dtype=None)[source]#
Convert input to a sparse array using SciPy.
- Input:
x: Dense, sparse, or array-like input plus sparse-format options.
- Output:
Sparse backend array.
- See:
- Backend-specific notes:
SpaceCore currently converts dense inputs to 2-D SciPy sparse matrices in the requested format.
- Parameters:
x (Any)
format (Literal['csr', 'csc', 'coo'])
dtype (Any | None)
- Return type:
SparseArray
- empty(shape, dtype=<class 'float'>, order='C', *, device=None, like=None)[source]#
Create an uninitialized dense array using NumPy.
- Input:
shape: Output shape; dtype and placement options are backend-specific.
- Output:
Dense backend array with uninitialized values.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.empty.html
- Parameters:
shape (int | Tuple[int, ...])
dtype (Any | None)
order (Literal['C', 'F'])
device (str | None)
like (DenseArray | None)
- Return type:
DenseArray
- zeros(shape, dtype=None, order='C', *, device=None, like=None)[source]#
Create a zero-filled dense array using NumPy.
- Input:
shape: Output shape; dtype and placement options are backend-specific.
- Output:
Dense backend array filled with zeros.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.zeros.html
- Parameters:
shape (int | Tuple[int, ...])
dtype (Any | None)
order (Literal['C', 'F'])
device (str | None)
like (DenseArray | None)
- Return type:
DenseArray
- ones(shape, dtype=None, order='C', *, device=None, like=None)[source]#
Create a one-filled dense array using NumPy.
- Input:
shape: Output shape; dtype and placement options are backend-specific.
- Output:
Dense backend array filled with ones.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.ones.html
- Parameters:
shape (int | Tuple[int, ...])
dtype (Any | None)
order (Literal['C', 'F'])
device (str | None)
like (DenseArray | None)
- Return type:
DenseArray
- zeros_like(x, dtype=None, order='K', subok=True, shape=None)[source]#
Create zeros shaped like another array using NumPy.
- Input:
x: Prototype dense array; dtype, shape, and placement options are backend-specific.
- Output:
Dense backend array of zeros.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.zeros_like.html
- Parameters:
x (DenseArray)
dtype (Any | None)
order (Literal['C', 'F', 'A', 'K'])
subok (bool)
shape (int | Tuple[int, ...] | None)
- Return type:
DenseArray
- ones_like(x, dtype=None, order='K', subok=True, shape=None)[source]#
Create ones shaped like another array using NumPy.
- Input:
x: Prototype dense array; dtype, shape, and placement options are backend-specific.
- Output:
Dense backend array of ones.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.ones_like.html
- Parameters:
x (DenseArray)
dtype (Any | None)
order (Literal['C', 'F', 'A', 'K'])
subok (bool)
shape (int | Tuple[int, ...] | None)
- Return type:
DenseArray
- full_like(x, value, dtype=None, order='K', subok=True, shape=None)[source]#
Create filled values shaped like another array using NumPy.
- Input:
x: Prototype dense array; value/fill_value and dtype options are backend-specific.
- Output:
Dense backend array filled with the requested value.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.full_like.html
- Parameters:
x (DenseArray)
value (Any)
dtype (Any | None)
order (Literal['C', 'F', 'A', 'K'])
subok (bool)
shape (int | Tuple[int, ...] | None)
- Return type:
DenseArray
- arange(start, stop=None, step=None, dtype=None, *, device=None, like=None)[source]#
Create evenly spaced integer-range values using NumPy.
- Input:
start, stop, step: Range parameters; dtype and placement options are backend-specific.
- Output:
One-dimensional dense backend array.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.arange.html
- Parameters:
start (int)
stop (int | None)
step (int | None)
dtype (Any | None)
device (str | None)
like (DenseArray | None)
- Return type:
DenseArray
- full(shape, fill_value, dtype=None, order='C', *, device=None, like=None)[source]#
Create a filled dense array using NumPy.
- Input:
shape: Output shape; fill_value and dtype options are backend-specific.
- Output:
Dense backend array filled with fill_value.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.full.html
- Parameters:
shape (int | Tuple[int, ...])
fill_value (Any)
dtype (Any | None)
order (Literal['C', 'F'])
device (str | None)
like (DenseArray | None)
- Return type:
DenseArray
- eye(N, M=None, k=0, dtype=<class 'float'>, order='C', *, device=None, like=None)[source]#
Create a dense identity-like matrix using NumPy.
- Input:
n and optional m: Matrix dimensions; dtype and placement options are backend-specific.
- Output:
Two-dimensional dense backend array.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.eye.html
- Parameters:
N (int)
M (int | None)
k (int)
dtype (Any | None)
order (Literal['C', 'F'])
device (str | None)
like (DenseArray | None)
- Return type:
DenseArray
- ravel(a, order='C')[source]#
Flatten an array using NumPy.
- Input:
x: Dense backend array plus optional order parameters.
- Output:
One-dimensional dense backend array view or copy.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.ravel.html
- Parameters:
a (DenseArray)
order (Literal['C', 'F', 'A', 'K'])
- Return type:
DenseArray
- reshape(a, shape, order='C', copy=None)[source]#
Reshape an array using NumPy.
- Input:
x: Dense backend array; shape: New shape plus backend-specific options.
- Output:
Dense backend array with the requested shape.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.reshape.html
- Parameters:
a (DenseArray)
shape (int | Tuple[int, ...])
order (Literal['C', 'F', 'A', 'K'])
copy (bool | None)
- Return type:
DenseArray
- transpose(a, axes=None)[source]#
Permute array axes using NumPy.
- Input:
x: Dense backend array; axes: Optional axis order.
- Output:
Dense backend array with permuted axes.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.transpose.html
- Parameters:
a (DenseArray)
axes (Sequence[int] | None)
- Return type:
DenseArray
- swapaxes(a, axis1, axis2)[source]#
Interchange two axes using NumPy.
- Input:
x: Dense backend array; axis1 and axis2: Axes to swap.
- Output:
Dense backend array with the two axes exchanged.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.swapaxes.html
- Parameters:
a (DenseArray)
axis1 (int)
axis2 (int)
- Return type:
DenseArray
- broadcast_to(x, shape, subok=False)[source]#
Broadcast an array to a shape using NumPy.
- Input:
x: Dense backend array; shape: Target broadcast shape.
- Output:
Dense backend array with broadcast shape.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.broadcast_to.html
- Parameters:
x (DenseArray)
shape (int | Tuple[int, ...])
subok (bool)
- Return type:
DenseArray
- expand_dims(x, axis)[source]#
Insert length-one axes using NumPy.
- Input:
x: Dense backend array; axis: Position or positions to insert.
- Output:
Dense backend array with expanded rank.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.expand_dims.html
- Parameters:
x (DenseArray)
axis (int | Sequence[int])
- Return type:
DenseArray
- squeeze(x, axis=None)[source]#
Remove length-one axes using NumPy.
- Input:
x: Dense backend array; axis: Optional axes to squeeze.
- Output:
Dense backend array with selected singleton dimensions removed.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.squeeze.html
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
- Return type:
DenseArray
- moveaxis(x, source, destination)[source]#
Move axes to new positions using NumPy.
- Input:
x: Dense backend array; source and destination: Axis positions.
- Output:
Dense backend array with moved axes.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.moveaxis.html
- Parameters:
x (DenseArray)
source (int | Sequence[int])
destination (int | Sequence[int])
- Return type:
DenseArray
- stack(arrays, axis=0, out=None, *, dtype=None, casting='same_kind')[source]#
Stack arrays along a new axis using NumPy.
- Input:
arrays: Sequence of dense backend arrays; axis: New axis position.
- Output:
Dense backend array containing stacked inputs.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.stack.html
- Parameters:
arrays (Sequence[DenseArray])
axis (int)
out (DenseArray | None)
dtype (Any | None)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
- Return type:
DenseArray
- conj(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Compute complex conjugates using NumPy.
- Input:
x: Dense backend array.
- Output:
Dense backend array with conjugated values.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.conj.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
where (DenseArray | bool)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- abs(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Compute absolute values using NumPy.
- Input:
x: Dense backend array.
- Output:
Dense backend array of absolute values.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.abs.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
where (DenseArray | bool)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- sign(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Compute signs elementwise using NumPy.
- Input:
x: Dense backend array.
- Output:
Dense backend array of signs.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.sign.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
where (DenseArray | bool)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- sqrt(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Compute square roots elementwise using NumPy.
- Input:
x: Dense backend array.
- Output:
Dense backend array of square roots.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
where (DenseArray | bool)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- real(x)[source]#
Extract real components using NumPy.
- Input:
x: Dense backend array.
- Output:
Dense backend array containing real components.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.real.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- imag(x)[source]#
Extract imaginary components using NumPy.
- Input:
x: Dense backend array.
- Output:
Dense backend array containing imaginary components.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.imag.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- sum(a, axis=None, dtype=None, out=None, keepdims=False, initial=None, where=True)[source]#
Reduce by summation using NumPy.
- Input:
x: Dense backend array; axis, keepdims, and dtype control the reduction.
- Output:
Dense backend array or scalar containing sums.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.sum.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
dtype (Any | None)
out (DenseArray | None)
keepdims (bool)
initial (DenseArray | None)
where (DenseArray | bool)
- Return type:
DenseArray
- mean(a, axis=None, dtype=None, out=None, keepdims=False, where=True)[source]#
Reduce by arithmetic mean using NumPy.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense backend array or scalar containing means.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.mean.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
dtype (Any | None)
out (DenseArray | None)
keepdims (bool)
where (DenseArray | bool)
- Return type:
DenseArray
- min(a, axis=None, out=None, keepdims=False, initial=None, where=True)[source]#
Reduce by minimum using NumPy.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense backend array or scalar containing minima.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.min.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
out (DenseArray | None)
keepdims (bool)
initial (DenseArray | None)
where (DenseArray | bool)
- Return type:
DenseArray
- max(a, axis=None, out=None, keepdims=False, initial=None, where=True)[source]#
Reduce by maximum using NumPy.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense backend array or scalar containing maxima.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.max.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
out (DenseArray | None)
keepdims (bool)
initial (DenseArray | None)
where (DenseArray | bool)
- Return type:
DenseArray
- prod(a, axis=None, dtype=None, out=None, keepdims=False, initial=None, where=True)[source]#
Reduce by product using NumPy.
- Input:
x: Dense backend array; axis, keepdims, and dtype control the reduction.
- Output:
Dense backend array or scalar containing products.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.prod.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
dtype (Any | None)
out (DenseArray | None)
keepdims (bool)
initial (DenseArray | None)
where (DenseArray | bool)
- Return type:
DenseArray
- trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None)[source]#
Sum diagonal entries using NumPy.
- Input:
x: Dense backend array plus optional diagonal and axis controls.
- Output:
Dense backend array or scalar containing trace values.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.trace.html
- Parameters:
a (DenseArray)
offset (int)
axis1 (int)
axis2 (int)
dtype (Any | None)
out (DenseArray | None)
- Return type:
DenseArray
- argsort(a, axis=-1, kind=None, order=None, *, stable=None)[source]#
Return sorting indices using NumPy.
- Input:
x: Dense backend array; axis and ordering options are backend-specific.
- Output:
Dense integer backend array of indices.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.argsort.html
- Parameters:
a (DenseArray)
axis (int)
kind (Literal['quicksort', 'mergesort', 'heapsort', 'stable'] | None)
order (str | Sequence[str] | None)
stable (bool | None)
- Return type:
DenseArray
- sort(a, axis=-1, kind=None, order=None, *, stable=None)[source]#
Sort values using NumPy.
- Input:
x: Dense backend array; axis and ordering options are backend-specific.
- Output:
Dense backend array with sorted values.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.sort.html
- Parameters:
a (DenseArray)
axis (int)
kind (Literal['quicksort', 'mergesort', 'heapsort', 'stable'] | None)
order (str | Sequence[str] | None)
stable (bool | None)
- Return type:
DenseArray
- argmin(a, axis=None, out=None, *, keepdims=False)[source]#
Return indices of minimum values using NumPy.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense integer backend array or scalar of indices.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.argmin.html
- Parameters:
a (DenseArray)
axis (int | None)
out (DenseArray | None)
keepdims (bool)
- Return type:
DenseArray
- argmax(a, axis=None, out=None, *, keepdims=False)[source]#
Return indices of maximum values using NumPy.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense integer backend array or scalar of indices.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.argmax.html
- Parameters:
a (DenseArray)
axis (int | None)
out (DenseArray | None)
keepdims (bool)
- Return type:
DenseArray
- vdot(a, b)[source]#
Compute a conjugating vector dot product using NumPy.
- Input:
x, y: Dense backend arrays accepted by the backend vdot operation.
- Output:
Backend scalar or dense array containing the dot product.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.vdot.html
- Parameters:
a (DenseArray)
b (DenseArray)
- Return type:
DenseArray
- matmul(a, b, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Compute matrix products using NumPy.
- Input:
a, b: Dense backend arrays with matrix-multiplication-compatible shapes.
- Output:
Dense backend array containing the product.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.matmul.html
- Parameters:
a (DenseArray)
b (DenseArray)
out (DenseArray | None)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- sparse_matmul(a, b)[source]#
Multiply sparse and dense arrays using SciPy.
- Input:
a: Sparse backend array; b: Dense backend array.
- Output:
Dense backend array containing the product.
- See:
- Backend-specific notes:
Uses SciPy sparse multiplication before returning a dense NumPy result when applicable.
- Parameters:
a (SparseArray)
b (DenseArray)
- Return type:
DenseArray
- kron(a, b)[source]#
Compute a Kronecker product using NumPy.
- Input:
a, b: Dense backend arrays.
- Output:
Dense backend array containing the Kronecker product.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.kron.html
- Parameters:
a (DenseArray)
b (DenseArray)
- Return type:
DenseArray
- einsum(subscripts, *operands, out=None, dtype=None, order='K', casting='safe', optimize=False)[source]#
Evaluate an Einstein summation expression using NumPy.
- Input:
subscripts: Einstein summation string; operands: Dense backend arrays.
- Output:
Dense backend array containing the contraction result.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.einsum.html
- Parameters:
subscripts (str)
operands (DenseArray)
out (DenseArray | None)
dtype (Any | None)
order (Literal['C', 'F', 'A', 'K'])
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
optimize (bool | str | Sequence[Any])
- Return type:
DenseArray
- eigh(a, UPLO='L')[source]#
Compute Hermitian eigenpairs using NumPy.
- Input:
x: Dense Hermitian or symmetric backend array.
- Output:
Tuple of dense backend arrays containing eigenvalues and eigenvectors.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.linalg.eigh.html
- Parameters:
a (DenseArray)
UPLO (Literal['L', 'U'])
- Return type:
Tuple[DenseArray, DenseArray]
- norm(x, ord=None, axis=None, keepdims=False)[source]#
Compute vector or matrix norms using NumPy.
- Input:
x: Dense backend array; ord, axis, and keepdims select the norm.
- Output:
Dense backend array or scalar containing norm values.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html
- Parameters:
x (DenseArray)
ord (int | str | None)
axis (int | Sequence[int] | None)
keepdims (bool)
- Return type:
DenseArray
- solve(A, b)[source]#
Solve dense linear systems using NumPy.
- Input:
A: Dense coefficient array; b: Dense right-hand side array.
- Output:
Dense backend array solving A @ x = b.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.linalg.solve.html
- Parameters:
A (DenseArray)
b (DenseArray)
- Return type:
DenseArray
- eigvalsh(A, UPLO='L')[source]#
Compute Hermitian eigenvalues using NumPy.
- Input:
A: Dense Hermitian or symmetric backend array.
- Output:
Dense backend array containing eigenvalues.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.linalg.eigvalsh.html
- Parameters:
A (DenseArray)
UPLO (Literal['L', 'U'])
- Return type:
DenseArray
- svd(A, full_matrices=True, compute_uv=True, hermitian=False)[source]#
Compute singular value decompositions using NumPy.
- Input:
A: Dense backend array plus SVD options.
- Output:
Dense backend arrays containing singular vectors and/or singular values.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.linalg.svd.html
- Parameters:
A (DenseArray)
full_matrices (bool)
compute_uv (bool)
hermitian (bool)
- Return type:
DenseArray | Tuple[DenseArray, DenseArray, DenseArray]
- cholesky(A)[source]#
Compute Cholesky factors using NumPy.
- Input:
A: Dense Hermitian positive-definite backend array.
- Output:
Dense backend array containing a triangular factor.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.linalg.cholesky.html
- Parameters:
A (DenseArray)
- Return type:
DenseArray
- logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False)[source]#
Compute a stable log-sum-exp reduction using SciPy.
- Input:
a: Dense backend array; axis, weights, and sign options control the reduction.
- Output:
Dense backend array or tuple containing log-sum-exp results.
- See:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
b (DenseArray | None)
keepdims (bool)
return_sign (bool)
- Return type:
DenseArray | Tuple[DenseArray, DenseArray]
- exp(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Compute exponentials elementwise using NumPy.
- Input:
x: Dense backend array.
- Output:
Dense backend array of exponentials.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.exp.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
where (DenseArray | bool)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- log(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Compute natural logarithms elementwise using NumPy.
- Input:
x: Dense backend array.
- Output:
Dense backend array of logarithms.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.log.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
where (DenseArray | bool)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- maximum(x, y, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Compute elementwise maxima using NumPy.
- Input:
x, y: Arrays or scalars accepted by backend broadcasting.
- Output:
Dense backend array containing maxima.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.maximum.html
- Parameters:
x (DenseArray)
y (DenseArray)
out (DenseArray | None)
where (DenseArray | bool)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- minimum(x, y, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Compute elementwise minima using NumPy.
- Input:
x, y: Arrays or scalars accepted by backend broadcasting.
- Output:
Dense backend array containing minima.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.minimum.html
- Parameters:
x (DenseArray)
y (DenseArray)
out (DenseArray | None)
where (DenseArray | bool)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- clip(x, a_min, a_max, out=None, **kwargs)[source]#
Clip values into an interval using NumPy.
- Input:
x: Dense backend array; a_min and a_max: Broadcastable bounds.
- Output:
Dense backend array with clipped values.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.clip.html
- Parameters:
x (DenseArray)
a_min (DenseArray)
a_max (DenseArray)
out (DenseArray | None)
kwargs (Any)
- Return type:
DenseArray
- isfinite(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Test finiteness elementwise using NumPy.
- Input:
x: Dense backend array.
- Output:
Boolean dense backend array.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
where (DenseArray | bool)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- isnan(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)[source]#
Test NaN values elementwise using NumPy.
- Input:
x: Dense backend array.
- Output:
Boolean dense backend array.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.isnan.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
where (DenseArray | bool)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
order (Literal['C', 'F', 'A', 'K'])
dtype (Any | None)
subok (bool)
- Return type:
DenseArray
- where(condition, x, y)[source]#
Select values by condition using NumPy.
- Input:
condition: Boolean array or scalar; x and y: Values to choose between.
- Output:
Dense backend array containing selected values.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.where.html
- Parameters:
condition (DenseArray | bool)
x (DenseArray)
y (DenseArray)
- Return type:
DenseArray
- concatenate(arrays, axis=0, out=None, *, dtype=None, casting='same_kind')[source]#
Join arrays along an existing axis using NumPy.
- Input:
arrays: Sequence of dense backend arrays; axis and dtype options are backend-specific.
- Output:
Dense backend array containing concatenated inputs.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html
- Parameters:
arrays (Sequence[DenseArray])
axis (int)
out (DenseArray | None)
dtype (Any | None)
casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'])
- Return type:
DenseArray
- take(x, indices, axis=None, out=None, mode='raise')[source]#
Take values by integer indices using NumPy.
- Input:
x: Dense backend array; indices: Integer indices; axis and mode options are backend-specific.
- Output:
Dense backend array containing selected values.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.take.html
- Parameters:
x (DenseArray)
indices (DenseArray)
axis (int | None)
out (DenseArray | None)
mode (Literal['raise', 'wrap', 'clip'])
- Return type:
DenseArray
- diag(x, k=0)[source]#
Extract or build a diagonal using NumPy.
- Input:
x: Dense backend array and optional diagonal offset.
- Output:
Dense backend array containing a diagonal view/copy or matrix.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.diag.html
- Parameters:
x (DenseArray)
k (int)
- Return type:
DenseArray
- diagonal(x, offset=0, axis1=0, axis2=1)[source]#
Return selected diagonals using NumPy.
- Input:
x: Dense backend array plus offset and axis controls.
- Output:
Dense backend array containing selected diagonals.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.diagonal.html
- Parameters:
x (DenseArray)
offset (int)
axis1 (int)
axis2 (int)
- Return type:
DenseArray
- tril(x, k=0)[source]#
Return lower-triangular values using NumPy.
- Input:
x: Dense backend array and optional diagonal offset.
- Output:
Dense backend array with upper entries zeroed.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.tril.html
- Parameters:
x (DenseArray)
k (int)
- Return type:
DenseArray
- triu(x, k=0)[source]#
Return upper-triangular values using NumPy.
- Input:
x: Dense backend array and optional diagonal offset.
- Output:
Dense backend array with lower entries zeroed.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.triu.html
- Parameters:
x (DenseArray)
k (int)
- Return type:
DenseArray
- index_set(x, index, values, *, copy=True)[source]#
Set indexed values using NumPy.
- Input:
x: Dense backend array; index: Selection; values: Replacement values; copy controls mutation policy.
- Output:
Dense backend array with indexed values set.
- See:
- Backend-specific notes:
With copy=True this copies before assignment; with copy=False it mutates the input array.
- Parameters:
x (DenseArray)
index (int | slice | Any | Tuple[Any, ...])
values (DenseArray)
copy (bool)
- ix_(*args)[source]#
Build open mesh index arrays using NumPy.
- Input:
args: One-dimensional index arrays or sequences.
- Output:
Tuple of dense backend arrays usable for open-mesh indexing.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.ix_.html
- Parameters:
args (Any)
- Return type:
Any
- fori_loop(lower, upper, body_fun, init_val)[source]#
Run a counted loop primitive using NumPy.
- Input:
lower, upper: Loop bounds; body_fun: Loop body; init_val: Initial carry value.
- Output:
Final carry value after loop execution.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.lax.fori_loop.html
- Backend-specific notes:
NumPy executes this eagerly as a Python for-loop, without JAX tracing semantics.
- Parameters:
lower (int)
upper (int)
body_fun (Callable[[int, T], T])
init_val (T)
- Return type:
T
- while_loop(cond_fun, body_fun, init_val)[source]#
Run a while-loop primitive using NumPy.
- Input:
cond_fun: Loop condition; body_fun: Loop body; init_val: Initial carry value.
- Output:
Final carry value after loop execution.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.lax.while_loop.html
- Backend-specific notes:
NumPy executes this eagerly as a Python while-loop, without JAX tracing semantics.
- Parameters:
cond_fun (Callable[[T], bool])
body_fun (Callable[[T], T])
init_val (T)
- Return type:
T
- scan(f, init, xs, length=None, reverse=False, unroll=1)[source]#
Run a scan primitive using NumPy.
- Input:
f: Scan body; init: Initial carry; xs: Per-step inputs plus scan options.
- Output:
Tuple of final carry and stacked outputs.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.lax.scan.html
- Backend-specific notes:
NumPy executes this eagerly and accepts unroll only for API parity.
- Parameters:
f (Callable[[Carry, X], Tuple[Carry, Y]])
init (Carry)
xs (X)
length (int | None)
reverse (bool)
unroll (int)
- Return type:
Tuple[Carry, Y]
- cond(pred, true_fun, false_fun, *operands)[source]#
Run conditional branch selection using NumPy.
- Input:
pred: Predicate; true_fun and false_fun: Branch functions; operands: Branch inputs.
- Output:
Result returned by the selected branch.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.lax.cond.html
- Backend-specific notes:
NumPy chooses the branch eagerly with Python truth-value conversion.
- Parameters:
pred (bool)
true_fun (Callable[[T], R])
false_fun (Callable[[T], R])
operands (Any)
- Return type:
R
- index_add(x, index, values, *, copy=True)[source]#
Add into indexed values using NumPy.
- Input:
x: Dense backend array; index: Selection; values: Values to add; copy controls mutation policy.
- Output:
Dense backend array with indexed values incremented.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.ufunc.at.html
- Backend-specific notes:
Uses numpy.add.at so repeated indices accumulate in NumPy order.
- Parameters:
x (DenseArray)
index (int | slice | Any | Tuple[Any, ...])
values (DenseArray)
copy (bool)
- Return type:
DenseArray
- allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]#
Compare dense arrays elementwise within tolerances using NumPy.
- Input:
a, b: Dense backend arrays; rtol, atol, and equal_nan configure comparison.
- Output:
Boolean indicating whether arrays are close.
- See:
https://numpy.org/doc/stable/reference/generated/numpy.allclose.html
- Parameters:
a (DenseArray)
b (DenseArray)
rtol (float)
atol (float)
equal_nan (bool)
- Return type:
bool
- allclose_sparse(a, b, rtol=1e-05, atol=1e-08)[source]#
Compare sparse arrays elementwise within tolerances using SciPy.
- Input:
a, b: Sparse backend arrays; rtol and atol configure comparison.
- Output:
Boolean indicating whether sparse arrays are close.
- See:
- Backend-specific notes:
Sparse inputs are converted to CSR and compared by logical sparse difference.
- Parameters:
a (SparseArray)
b (SparseArray)
rtol (float)
atol (float)
- Return type:
bool
- property allow_sparse: bool#
Generic backend-agnostic wrapper to sparse-array support flag.
- Input:
None.
- Output:
Boolean indicating whether this backend supports sparse arrays.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- property family: str#
Generic backend-agnostic wrapper to backend family identifier.
- Input:
None.
- Output:
String naming the concrete backend family.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- is_array(x)#
Generic backend-agnostic wrapper to test for any backend array.
- Input:
x: Object to test.
- Output:
True when x is dense or sparse for this backend.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
bool
- is_dense(x)#
Generic backend-agnostic wrapper to test for a dense backend array.
- Input:
x: Object to test.
- Output:
True when x is an instance of the backend dense array type.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
bool
- is_sparse(x)#
Generic backend-agnostic wrapper to test for a sparse backend array.
- Input:
x: Object to test.
- Output:
True when x is an instance of a backend sparse array type.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
bool
JaxOps#
- class spacecore.backend.JaxOps[source]#
Bases:
BackendOpsBackendOps implementation for the JAX ecosystem.
This backend uses JAX for dense array operations and JAX experimental sparse arrays for sparse operations.
- Dense arrays
jax.Array
- Sparse arrays
jax.experimental.sparse.BCOO jax.experimental.sparse.BCSR
- Methods
Most methods mirror the corresponding JAX public API signatures and delegate to jax.numpy, jax.numpy.linalg, jax.scipy, or jax.experimental.sparse. Backend-specific behavior, tracing rules, dtype canonicalization, device placement, sharding, and error modes therefore follow JAX semantics.
- Backend handles
- jaxmodule
JAX module stored on the class and available through instances as ops.jax. Advanced users may use it when SpaceCore’s portable API does not expose a required JAX feature.
- jnpmodule
jax.numpy module stored on the class and available through instances as ops.jnp.
- jsparsemodule
jax.experimental.sparse module stored on the class and available through instances as ops.jsparse.
- Notes
Code intended to remain backend-portable should prefer BackendOps methods. Direct use of ops.jax, ops.jnp, or ops.jsparse is an explicit JAX-specific escape hatch.
Some parameters are accepted for JAX signature compatibility even when JAX ignores them. Array-creation routines may expose device and out_sharding for explicit placement or sharding.
- sanitize_dtype(dtype)[source]#
Normalize a dtype specifier using JAX.
- Input:
dtype: Optional dtype requested by SpaceCore or the caller.
- Output:
Backend dtype object accepted by array constructors.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.dtype.html
- Backend-specific notes:
SpaceCore rejects dtypes that JAX would silently canonicalize under the active x64 setting.
- Parameters:
dtype (Any | None)
- Return type:
Any
- get_dtype(x)[source]#
Return an array dtype using JAX.
- Input:
x: Dense or sparse backend array.
- Output:
Backend dtype associated with x.
- See:
- Parameters:
x (Any)
- Return type:
Any
- shape(x)[source]#
Return array shape metadata using JAX.
- Input:
x: Dense or sparse backend array.
- Output:
Tuple describing the logical shape of x.
- See:
- Parameters:
x (Any)
- Return type:
tuple[int, …]
- ndim(x)[source]#
Return array rank metadata using JAX.
- Input:
x: Dense or sparse backend array.
- Output:
Number of dimensions in x.
- See:
- Parameters:
x (Any)
- Return type:
int
- size(x)[source]#
Return logical element count using JAX.
- Input:
x: Dense or sparse backend array.
- Output:
Total number of logical dense elements.
- See:
- Backend-specific notes:
Shape-polymorphic dimensions may not be concrete Python integers inside traced code.
- Parameters:
x (Any)
- Return type:
int
- property dense_array: Type[Any]#
Dense array type using JAX.
- Returns:
Concrete dense array class accepted by this backend.
- property sparse_array: Tuple[Type[Any], ...]#
Sparse array type tuple using JAX.
- Returns:
Concrete sparse array classes accepted by this backend, or None.
- property inf#
Positive infinity scalar using JAX.
- Returns:
Backend scalar representing positive infinity.
- property nan#
NaN scalar using JAX.
- Input:
None.
- Output:
Backend scalar representing NaN.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.nan.html
- property pi#
Pi scalar using JAX.
- Input:
None.
- Output:
Backend scalar representing pi.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.pi.html
- property e#
Euler number scalar using JAX.
- Input:
None.
- Output:
Backend scalar representing Euler’s number.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.e.html
- property eps#
Machine epsilon scalar using JAX.
- Input:
None.
- Output:
Backend scalar for float64 machine epsilon.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.finfo.html
- asarray(a, dtype=None, order=None, *, copy=None, device=None)[source]#
Convert input to a dense array using JAX.
- Input:
x/a: Array-like input and optional dtype or backend conversion parameters.
- Output:
Dense backend array.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.asarray.html
- Parameters:
a (Any)
dtype (Any | None)
order (Literal['C', 'F', 'A', 'K'] | None)
copy (bool | None)
device (Any | None)
- Return type:
DenseArray
- astype(x, dtype, copy=True)[source]#
Cast an array to a dtype using JAX.
- Input:
x: Dense backend array; dtype: target dtype and optional casting controls.
- Output:
Dense backend array with the requested dtype.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.Array.astype.html
- Parameters:
x (DenseArray)
dtype (Any)
copy (bool)
- Return type:
DenseArray
- assparse(x, *, format='bcoo', index_dtype=None, nse=None, dtype=None)[source]#
Convert input to a sparse array using JAX.
- Input:
x: Dense, sparse, or array-like input plus sparse-format options.
- Output:
Sparse backend array.
- See:
- Backend-specific notes:
Dense inputs are converted with JAX sparse BCOO/BCSR constructors; SciPy sparse inputs use from_scipy_sparse.
- Parameters:
x (Any)
format (Literal['bcoo', 'bcsr'])
index_dtype (Any | None)
nse (int | None)
dtype (Any | None)
- Return type:
SparseArray
- empty(shape, dtype=None, *, device=None, out_sharding=None)[source]#
Create an uninitialized dense array using JAX.
- Input:
shape: Output shape; dtype and placement options are backend-specific.
- Output:
Dense backend array with uninitialized values.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.empty.html
- Backend-specific notes:
out_sharding is forwarded only when supported by the installed JAX version.
- Parameters:
shape (int | Tuple[int, ...])
dtype (Any | None)
device (Any | None)
out_sharding (Any | None)
- Return type:
DenseArray
- zeros(shape, dtype=None, *, device=None, out_sharding=None)[source]#
Create a zero-filled dense array using JAX.
- Input:
shape: Output shape; dtype and placement options are backend-specific.
- Output:
Dense backend array filled with zeros.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.zeros.html
- Backend-specific notes:
out_sharding is forwarded only when supported by the installed JAX version.
- Parameters:
shape (int | Tuple[int, ...])
dtype (Any | None)
device (Any | None)
out_sharding (Any | None)
- Return type:
DenseArray
- ones(shape, dtype=None, *, device=None, out_sharding=None)[source]#
Create a one-filled dense array using JAX.
- Input:
shape: Output shape; dtype and placement options are backend-specific.
- Output:
Dense backend array filled with ones.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.ones.html
- Parameters:
shape (int | Tuple[int, ...])
dtype (Any | None)
device (Any | None)
out_sharding (Any | None)
- Return type:
DenseArray
- zeros_like(x, dtype=None, shape=None, *, device=None, out_sharding=None)[source]#
Create zeros shaped like another array using JAX.
- Input:
x: Prototype dense array; dtype, shape, and placement options are backend-specific.
- Output:
Dense backend array of zeros.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.zeros_like.html
- Backend-specific notes:
out_sharding is forwarded only when supported by the installed JAX version.
- Parameters:
x (DenseArray)
dtype (Any | None)
shape (Any)
device (Any | None)
out_sharding (Any | None)
- Return type:
DenseArray
- ones_like(x, dtype=None, shape=None, *, device=None, out_sharding=None)[source]#
Create ones shaped like another array using JAX.
- Input:
x: Prototype dense array; dtype, shape, and placement options are backend-specific.
- Output:
Dense backend array of ones.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.ones_like.html
- Backend-specific notes:
out_sharding is forwarded only when supported by the installed JAX version.
- Parameters:
x (DenseArray)
dtype (Any | None)
shape (Any)
device (Any | None)
out_sharding (Any | None)
- Return type:
DenseArray
- full_like(x, value, dtype=None, shape=None, *, device=None)[source]#
Create filled values shaped like another array using JAX.
- Input:
x: Prototype dense array; value/fill_value and dtype options are backend-specific.
- Output:
Dense backend array filled with the requested value.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.full_like.html
- Parameters:
x (DenseArray)
value (Any)
dtype (Any | None)
shape (Any)
device (Any | None)
- Return type:
DenseArray
- arange(start, stop=None, step=None, dtype=None, *, device=None, out_sharding=None)[source]#
Create evenly spaced integer-range values using JAX.
- Input:
start, stop, step: Range parameters; dtype and placement options are backend-specific.
- Output:
One-dimensional dense backend array.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.arange.html
- Parameters:
start (int)
stop (int | None)
step (int | None)
dtype (Any | None)
device (Any | None)
out_sharding (Any | None)
- Return type:
DenseArray
- full(shape, fill_value, dtype=None, *, device=None)[source]#
Create a filled dense array using JAX.
- Input:
shape: Output shape; fill_value and dtype options are backend-specific.
- Output:
Dense backend array filled with fill_value.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.full.html
- Parameters:
shape (int | Tuple[int, ...])
fill_value (Any)
dtype (Any | None)
device (Any | None)
- Return type:
DenseArray
- eye(N, M=None, k=0, dtype=None, *, device=None)[source]#
Create a dense identity-like matrix using JAX.
- Input:
n and optional m: Matrix dimensions; dtype and placement options are backend-specific.
- Output:
Two-dimensional dense backend array.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.eye.html
- Parameters:
N (int)
M (int | None)
k (int)
dtype (Any | None)
device (Any | None)
- Return type:
DenseArray
- ravel(a, order='C', *, out_sharding=None)[source]#
Flatten an array using JAX.
- Input:
x: Dense backend array plus optional order parameters.
- Output:
One-dimensional dense backend array view or copy.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.ravel.html
- Parameters:
a (DenseArray)
order (Literal['C', 'F', 'A', 'K'])
out_sharding (Any | None)
- Return type:
DenseArray
- reshape(a, shape, order='C', *, copy=None, out_sharding=None)[source]#
Reshape an array using JAX.
- Input:
x: Dense backend array; shape: New shape plus backend-specific options.
- Output:
Dense backend array with the requested shape.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.reshape.html
- Parameters:
a (DenseArray)
shape (int | Tuple[int, ...])
order (Literal['C', 'F', 'A'])
copy (bool | None)
out_sharding (Any | None)
- Return type:
DenseArray
- transpose(x, axes=None)[source]#
Permute array axes using JAX.
- Input:
x: Dense backend array; axes: Optional axis order.
- Output:
Dense backend array with permuted axes.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.transpose.html
- Parameters:
x (DenseArray)
axes (Sequence[int] | None)
- Return type:
DenseArray
- swapaxes(x, axis1, axis2)[source]#
Interchange two axes using JAX.
- Input:
x: Dense backend array; axis1 and axis2: Axes to swap.
- Output:
Dense backend array with the two axes exchanged.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.swapaxes.html
- Parameters:
x (DenseArray)
axis1 (int)
axis2 (int)
- Return type:
DenseArray
- broadcast_to(x, shape, *, out_sharding=None)[source]#
Broadcast an array to a shape using JAX.
- Input:
x: Dense backend array; shape: Target broadcast shape.
- Output:
Dense backend array with broadcast shape.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.broadcast_to.html
- Parameters:
x (DenseArray)
shape (int | Tuple[int, ...])
out_sharding (Any | None)
- Return type:
DenseArray
- expand_dims(x, axis)[source]#
Insert length-one axes using JAX.
- Input:
x: Dense backend array; axis: Position or positions to insert.
- Output:
Dense backend array with expanded rank.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.expand_dims.html
- Parameters:
x (DenseArray)
axis (int | Sequence[int])
- Return type:
DenseArray
- squeeze(x, axis=None)[source]#
Remove length-one axes using JAX.
- Input:
x: Dense backend array; axis: Optional axes to squeeze.
- Output:
Dense backend array with selected singleton dimensions removed.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.squeeze.html
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
- Return type:
DenseArray
- moveaxis(x, source, destination)[source]#
Move axes to new positions using JAX.
- Input:
x: Dense backend array; source and destination: Axis positions.
- Output:
Dense backend array with moved axes.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.moveaxis.html
- Parameters:
x (DenseArray)
source (int | Sequence[int])
destination (int | Sequence[int])
- Return type:
DenseArray
- stack(arrays, axis=0, out=None, dtype=None)[source]#
Stack arrays along a new axis using JAX.
- Input:
arrays: Sequence of dense backend arrays; axis: New axis position.
- Output:
Dense backend array containing stacked inputs.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.stack.html
- Parameters:
arrays (Sequence[DenseArray])
axis (int)
out (Any | None)
dtype (Any | None)
- Return type:
DenseArray
- conj(x)[source]#
Compute complex conjugates using JAX.
- Input:
x: Dense backend array.
- Output:
Dense backend array with conjugated values.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.conj.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- real(x)[source]#
Extract real components using JAX.
- Input:
x: Dense backend array.
- Output:
Dense backend array containing real components.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.real.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- imag(x)[source]#
Extract imaginary components using JAX.
- Input:
x: Dense backend array.
- Output:
Dense backend array containing imaginary components.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.imag.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abs(x)[source]#
Compute absolute values using JAX.
- Input:
x: Dense backend array.
- Output:
Dense backend array of absolute values.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.abs.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- sign(x)[source]#
Compute signs elementwise using JAX.
- Input:
x: Dense backend array.
- Output:
Dense backend array of signs.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.sign.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- sqrt(x)[source]#
Compute square roots elementwise using JAX.
- Input:
x: Dense backend array.
- Output:
Dense backend array of square roots.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.sqrt.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- sum(a, axis=None, dtype=None, out=None, keepdims=False, initial=None, where=None, promote_integers=True)[source]#
Reduce by summation using JAX.
- Input:
x: Dense backend array; axis, keepdims, and dtype control the reduction.
- Output:
Dense backend array or scalar containing sums.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.sum.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
dtype (Any | None)
out (Any | None)
keepdims (bool)
initial (DenseArray | None)
where (DenseArray | None)
promote_integers (bool)
- Return type:
DenseArray
- mean(a, axis=None, dtype=None, out=None, keepdims=False, *, where=None)[source]#
Reduce by arithmetic mean using JAX.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense backend array or scalar containing means.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.mean.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
dtype (Any | None)
out (None)
keepdims (bool)
where (DenseArray | None)
- Return type:
DenseArray
- min(a, axis=None, out=None, keepdims=False, initial=None, where=None)[source]#
Reduce by minimum using JAX.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense backend array or scalar containing minima.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.min.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
out (None)
keepdims (bool)
initial (DenseArray | None)
where (DenseArray | None)
- Return type:
DenseArray
- max(a, axis=None, out=None, keepdims=False, initial=None, where=None)[source]#
Reduce by maximum using JAX.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense backend array or scalar containing maxima.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.max.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
out (None)
keepdims (bool)
initial (DenseArray | None)
where (DenseArray | None)
- Return type:
DenseArray
- prod(a, axis=None, dtype=None, out=None, keepdims=False, initial=None, where=None, promote_integers=True)[source]#
Reduce by product using JAX.
- Input:
x: Dense backend array; axis, keepdims, and dtype control the reduction.
- Output:
Dense backend array or scalar containing products.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.prod.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
dtype (Any | None)
out (Any | None)
keepdims (bool)
initial (DenseArray | None)
where (DenseArray | None)
promote_integers (bool)
- Return type:
DenseArray
- trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None)[source]#
Sum diagonal entries using JAX.
- Input:
x: Dense backend array plus optional diagonal and axis controls.
- Output:
Dense backend array or scalar containing trace values.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.trace.html
- Parameters:
a (DenseArray)
offset (int | Any)
axis1 (int)
axis2 (int)
dtype (Any | None)
out (DenseArray | None)
- Return type:
DenseArray
- argsort(a, axis=-1, kind=None, order=None, stable=True, descending=False)[source]#
Return sorting indices using JAX.
- Input:
x: Dense backend array; axis and ordering options are backend-specific.
- Output:
Dense integer backend array of indices.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.argsort.html
- Parameters:
a (DenseArray)
axis (int | None)
kind (None)
order (None)
stable (bool)
descending (bool)
- Return type:
DenseArray
- sort(a, axis=-1, kind=None, order=None, stable=True, descending=False)[source]#
Sort values using JAX.
- Input:
x: Dense backend array; axis and ordering options are backend-specific.
- Output:
Dense backend array with sorted values.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.sort.html
- Parameters:
a (DenseArray)
axis (int | None)
kind (None)
order (None)
stable (bool)
descending (bool)
- Return type:
DenseArray
- argmin(a, axis=None, out=None, keepdims=False)[source]#
Return indices of minimum values using JAX.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense integer backend array or scalar of indices.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.argmin.html
- Parameters:
a (DenseArray)
axis (int | None)
out (Any | None)
keepdims (bool)
- Return type:
DenseArray
- argmax(a, axis=None, out=None, keepdims=False)[source]#
Return indices of maximum values using JAX.
- Input:
x: Dense backend array; axis and keepdims control the reduction.
- Output:
Dense integer backend array or scalar of indices.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.argmax.html
- Parameters:
a (DenseArray)
axis (int | None)
out (Any | None)
keepdims (bool)
- Return type:
DenseArray
- vdot(a, b, *, precision=None, preferred_element_type=None)[source]#
Compute a conjugating vector dot product using JAX.
- Input:
x, y: Dense backend arrays accepted by the backend vdot operation.
- Output:
Backend scalar or dense array containing the dot product.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.vdot.html
- Parameters:
a (DenseArray)
b (DenseArray)
precision (Any | None)
preferred_element_type (Any | None)
- Return type:
DenseArray
- matmul(a, b, *, precision=None, preferred_element_type=None, out_sharding=None)[source]#
Compute matrix products using JAX.
- Input:
a, b: Dense backend arrays with matrix-multiplication-compatible shapes.
- Output:
Dense backend array containing the product.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.matmul.html
- Parameters:
a (DenseArray)
b (DenseArray)
precision (Any | None)
preferred_element_type (Any | None)
out_sharding (Any | None)
- Return type:
DenseArray
- sparse_matmul(a, b)[source]#
Multiply sparse and dense arrays using JAX.
- Input:
a: Sparse backend array; b: Dense backend array.
- Output:
Dense backend array containing the product.
- See:
- Backend-specific notes:
Uses JAX sparse matmul and returns a JAX array; sparse support remains experimental in JAX.
- Parameters:
a (SparseArray)
b (DenseArray)
- Return type:
DenseArray
- kron(a, b)[source]#
Compute a Kronecker product using JAX.
- Input:
a, b: Dense backend arrays.
- Output:
Dense backend array containing the Kronecker product.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.kron.html
- Parameters:
a (DenseArray)
b (DenseArray)
- Return type:
DenseArray
- einsum(subscripts, /, *operands, out=None, optimize='auto', precision=None, preferred_element_type=None, _dot_general=None, out_sharding=None)[source]#
Evaluate an Einstein summation expression using JAX.
- Input:
subscripts: Einstein summation string; operands: Dense backend arrays.
- Output:
Dense backend array containing the contraction result.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.einsum.html
- Parameters:
subscripts (str)
operands (DenseArray)
out (Any | None)
optimize (str | bool | list[Tuple[int, ...]])
precision (Any | None)
preferred_element_type (Any | None)
_dot_general (Any | None)
out_sharding (Any | None)
- Return type:
DenseArray
- eigh(x, UPLO='L', symmetrize_input=True)[source]#
Compute Hermitian eigenpairs using JAX.
- Input:
x: Dense Hermitian or symmetric backend array.
- Output:
Tuple of dense backend arrays containing eigenvalues and eigenvectors.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.linalg.eigh.html
- Backend-specific notes:
SpaceCore rejects sparse input before delegating to JAX dense linear algebra.
- Parameters:
x (DenseArray)
UPLO (Literal['L', 'U'])
symmetrize_input (bool)
- Return type:
Tuple[DenseArray, DenseArray]
- norm(x, ord=None, axis=None, keepdims=False)[source]#
Compute vector or matrix norms using JAX.
- Input:
x: Dense backend array; ord, axis, and keepdims select the norm.
- Output:
Dense backend array or scalar containing norm values.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.linalg.norm.html
- Parameters:
x (DenseArray)
ord (int | str | None)
axis (int | Sequence[int] | None)
keepdims (bool)
- Return type:
DenseArray
- solve(A, b)[source]#
Solve dense linear systems using JAX.
- Input:
A: Dense coefficient array; b: Dense right-hand side array.
- Output:
Dense backend array solving A @ x = b.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.linalg.solve.html
- Parameters:
A (DenseArray)
b (DenseArray)
- Return type:
DenseArray
- eigvalsh(A, UPLO='L', *, symmetrize_input=True)[source]#
Compute Hermitian eigenvalues using JAX.
- Input:
A: Dense Hermitian or symmetric backend array.
- Output:
Dense backend array containing eigenvalues.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.linalg.eigvalsh.html
- Parameters:
A (DenseArray)
UPLO (Literal['L', 'U'])
symmetrize_input (bool)
- Return type:
DenseArray
- svd(A, full_matrices=True, compute_uv=True, hermitian=False, subset_by_index=None)[source]#
Compute singular value decompositions using JAX.
- Input:
A: Dense backend array plus SVD options.
- Output:
Dense backend arrays containing singular vectors and/or singular values.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.linalg.svd.html
- Parameters:
A (DenseArray)
full_matrices (bool)
compute_uv (bool)
hermitian (bool)
subset_by_index (tuple[int, int] | None)
- Return type:
DenseArray | Tuple[DenseArray, DenseArray, DenseArray]
- cholesky(A, *, upper=False, symmetrize_input=True)[source]#
Compute Cholesky factors using JAX.
- Input:
A: Dense Hermitian positive-definite backend array.
- Output:
Dense backend array containing a triangular factor.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.linalg.cholesky.html
- Parameters:
A (DenseArray)
upper (bool)
symmetrize_input (bool)
- Return type:
DenseArray
- logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False, where=None)[source]#
Compute a stable log-sum-exp reduction using JAX.
- Input:
a: Dense backend array; axis, weights, and sign options control the reduction.
- Output:
Dense backend array or tuple containing log-sum-exp results.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.scipy.special.logsumexp.html
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
b (DenseArray | None)
keepdims (bool)
return_sign (bool)
where (DenseArray | None)
- Return type:
DenseArray | Tuple[DenseArray, DenseArray]
- exp(x)[source]#
Compute exponentials elementwise using JAX.
- Input:
x: Dense backend array.
- Output:
Dense backend array of exponentials.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.exp.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- log(x)[source]#
Compute natural logarithms elementwise using JAX.
- Input:
x: Dense backend array.
- Output:
Dense backend array of logarithms.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.log.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- maximum(x, y)[source]#
Compute elementwise maxima using JAX.
- Input:
x, y: Arrays or scalars accepted by backend broadcasting.
- Output:
Dense backend array containing maxima.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.maximum.html
- Parameters:
x (DenseArray)
y (DenseArray)
- Return type:
DenseArray
- minimum(x, y)[source]#
Compute elementwise minima using JAX.
- Input:
x, y: Arrays or scalars accepted by backend broadcasting.
- Output:
Dense backend array containing minima.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.minimum.html
- Parameters:
x (DenseArray)
y (DenseArray)
- Return type:
DenseArray
- clip(x, a_min, a_max)[source]#
Clip values into an interval using JAX.
- Input:
x: Dense backend array; a_min and a_max: Broadcastable bounds.
- Output:
Dense backend array with clipped values.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.clip.html
- Parameters:
x (DenseArray)
a_min (DenseArray)
a_max (DenseArray)
- Return type:
DenseArray
- isfinite(x)[source]#
Test finiteness elementwise using JAX.
- Input:
x: Dense backend array.
- Output:
Boolean dense backend array.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.isfinite.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- isnan(x)[source]#
Test NaN values elementwise using JAX.
- Input:
x: Dense backend array.
- Output:
Boolean dense backend array.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.isnan.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- where(condition, x=None, y=None, *, size=None, fill_value=None)[source]#
Select values by condition using JAX.
- Input:
condition: Boolean array or scalar; x and y: Values to choose between.
- Output:
Dense backend array containing selected values.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.where.html
- Parameters:
condition (DenseArray | bool)
x (DenseArray | None)
y (DenseArray | None)
size (int | None)
fill_value (DenseArray | None)
- Return type:
DenseArray
- concatenate(arrays, axis=0, dtype=None)[source]#
Join arrays along an existing axis using JAX.
- Input:
arrays: Sequence of dense backend arrays; axis and dtype options are backend-specific.
- Output:
Dense backend array containing concatenated inputs.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.concatenate.html
- Parameters:
arrays (Sequence[DenseArray])
axis (int)
dtype (Any | None)
- Return type:
DenseArray
- take(x, indices, axis=None, out=None, mode=None, unique_indices=False, indices_are_sorted=False, fill_value=None)[source]#
Take values by integer indices using JAX.
- Input:
x: Dense backend array; indices: Integer indices; axis and mode options are backend-specific.
- Output:
Dense backend array containing selected values.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.take.html
- Backend-specific notes:
Out-of-bounds and mode behavior follow JAX, which can differ from NumPy.
- Parameters:
x (DenseArray)
indices (DenseArray)
axis (int | None)
out (None)
mode (str | None)
unique_indices (bool)
indices_are_sorted (bool)
fill_value (Any | None)
- Return type:
DenseArray
- diag(x, k=0)[source]#
Extract or build a diagonal using JAX.
- Input:
x: Dense backend array and optional diagonal offset.
- Output:
Dense backend array containing a diagonal view/copy or matrix.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.diag.html
- Parameters:
x (DenseArray)
k (int)
- Return type:
DenseArray
- diagonal(x, offset=0, axis1=0, axis2=1)[source]#
Return selected diagonals using JAX.
- Input:
x: Dense backend array plus offset and axis controls.
- Output:
Dense backend array containing selected diagonals.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.diagonal.html
- Parameters:
x (DenseArray)
offset (int)
axis1 (int)
axis2 (int)
- Return type:
DenseArray
- tril(x, k=0)[source]#
Return lower-triangular values using JAX.
- Input:
x: Dense backend array and optional diagonal offset.
- Output:
Dense backend array with upper entries zeroed.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.tril.html
- Parameters:
x (DenseArray)
k (int)
- Return type:
DenseArray
- triu(x, k=0)[source]#
Return upper-triangular values using JAX.
- Input:
x: Dense backend array and optional diagonal offset.
- Output:
Dense backend array with lower entries zeroed.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.triu.html
- Parameters:
x (DenseArray)
k (int)
- Return type:
DenseArray
- index_set(x, index, values, *, copy=True)[source]#
Set indexed values using JAX.
- Input:
x: Dense backend array; index: Selection; values: Replacement values; copy controls mutation policy.
- Output:
Dense backend array with indexed values set.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.Array.at.html
- Backend-specific notes:
JAX arrays are immutable; copy=False raises NotImplementedError.
- Parameters:
x (DenseArray)
index (int | slice | Any | Tuple[Any, ...])
values (ArrayLike)
copy (bool)
- ix_(*args)[source]#
Build open mesh index arrays using JAX.
- Input:
args: One-dimensional index arrays or sequences.
- Output:
Tuple of dense backend arrays usable for open-mesh indexing.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.ix_.html
- Parameters:
args (Any)
- Return type:
Any
- fori_loop(lower, upper, body_fun, init_val, *, unroll=None)[source]#
Run a counted loop primitive using JAX.
- Input:
lower, upper: Loop bounds; body_fun: Loop body; init_val: Initial carry value.
- Output:
Final carry value after loop execution.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.lax.fori_loop.html
- Backend-specific notes:
Loop bounds and unroll behavior follow JAX tracing and compilation rules.
- Parameters:
lower (int)
upper (int)
body_fun (Callable[[int, T], T])
init_val (T)
unroll (int | bool | None)
- Return type:
T
- while_loop(cond_fun, body_fun, init_val)[source]#
Run a while-loop primitive using JAX.
- Input:
cond_fun: Loop condition; body_fun: Loop body; init_val: Initial carry value.
- Output:
Final carry value after loop execution.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.lax.while_loop.html
- Backend-specific notes:
Condition and body are staged according to JAX lax control-flow semantics.
- Parameters:
cond_fun (Callable[[T], bool])
body_fun (Callable[[T], T])
init_val (T)
- Return type:
T
- scan(f, init, xs, length=None, reverse=False, unroll=1, _split_transpose=False)[source]#
Run a scan primitive using JAX.
- Input:
f: Scan body; init: Initial carry; xs: Per-step inputs plus scan options.
- Output:
Tuple of final carry and stacked outputs.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.lax.scan.html
- Backend-specific notes:
Inputs and outputs may be pytrees and are staged according to JAX lax.scan semantics.
- Parameters:
f (Callable[[Carry, X], Tuple[Carry, Y]])
init (Carry)
xs (X)
length (int | None)
reverse (bool)
unroll (int)
_split_transpose (bool)
- Return type:
Tuple[Carry, Y]
- cond(pred, true_fun, false_fun, *operands)[source]#
Run conditional branch selection using JAX.
- Input:
pred: Predicate; true_fun and false_fun: Branch functions; operands: Branch inputs.
- Output:
Result returned by the selected branch.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.lax.cond.html
- Backend-specific notes:
Branches are staged according to JAX lax.cond semantics rather than Python eager branching.
- Parameters:
pred (bool)
true_fun (Callable[[T], R])
false_fun (Callable[[T], R])
operands (Any)
- Return type:
R
- index_add(x, index, values, *, copy=True)[source]#
Add into indexed values using JAX.
- Input:
x: Dense backend array; index: Selection; values: Values to add; copy controls mutation policy.
- Output:
Dense backend array with indexed values incremented.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.Array.at.html
- Backend-specific notes:
JAX arrays are immutable; copy=False raises NotImplementedError and repeated indices follow JAX scatter-add semantics.
- Parameters:
x (DenseArray)
index (int | slice | Any | Tuple[Any, ...])
values (DenseArray)
copy (bool)
- allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]#
Compare dense arrays elementwise within tolerances using JAX.
- Input:
a, b: Dense backend arrays; rtol, atol, and equal_nan configure comparison.
- Output:
Boolean indicating whether arrays are close.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.numpy.allclose.html
- Parameters:
a (DenseArray)
b (DenseArray)
rtol (float)
atol (float)
equal_nan (bool)
- Return type:
bool
- allclose_sparse(a, b, rtol=1e-05, atol=1e-08)[source]#
Compare sparse arrays elementwise within tolerances using JAX.
- Input:
a, b: Sparse backend arrays; rtol and atol configure comparison.
- Output:
Boolean indicating whether sparse arrays are close.
- See:
- Backend-specific notes:
SpaceCore converts JAX sparse arrays through SciPy sparse arrays for comparison.
- Parameters:
a (SparseArray)
b (SparseArray)
rtol (float)
atol (float)
- Return type:
bool
- property allow_sparse: bool#
Generic backend-agnostic wrapper to sparse-array support flag.
- Input:
None.
- Output:
Boolean indicating whether this backend supports sparse arrays.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- property family: str#
Generic backend-agnostic wrapper to backend family identifier.
- Input:
None.
- Output:
String naming the concrete backend family.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- is_array(x)#
Generic backend-agnostic wrapper to test for any backend array.
- Input:
x: Object to test.
- Output:
True when x is dense or sparse for this backend.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
bool
- is_dense(x)#
Generic backend-agnostic wrapper to test for a dense backend array.
- Input:
x: Object to test.
- Output:
True when x is an instance of the backend dense array type.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
bool
- is_sparse(x)#
Generic backend-agnostic wrapper to test for a sparse backend array.
- Input:
x: Object to test.
- Output:
True when x is an instance of a backend sparse array type.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
bool
TorchOps#
- class spacecore.backend.TorchOps[source]#
Bases:
BackendOpsBackendOps implementation for PyTorch tensors.
This backend uses PyTorch for dense and sparse tensor operations.
- Dense arrays
torch.Tensor with strided layout
- Sparse arrays
torch.Tensor with a PyTorch sparse layout
- Methods
Most methods mirror the corresponding PyTorch public API signatures and delegate to
torchortorch.linalg. Backend-specific behavior, dtype promotion, broadcasting, device placement, autograd tracking, and error modes therefore follow PyTorch semantics.- Backend handles
- torchmodule
PyTorch module stored on the class and available through instances as
ops.torch. Advanced users may use it when SpaceCore’s portable API does not expose a required PyTorch feature.
- Notes
Code intended to remain backend-portable should prefer
BackendOpsmethods. Direct use ofops.torchis an explicit PyTorch-specific escape hatch.TorchOpsfollows PyTorch dtype defaults. When no dtype is provided,sanitize_dtype(None)returnstorch.get_default_dtype(). Pythoncomplexmaps totorch.complex64ortorch.complex128based on the active default floating dtype, and NumPy dtype specifiers are mapped to their corresponding PyTorch dtypes when supported.Array creation and conversion methods may accept a backend-specific
device=keyword. Existing tensors stay on their device unless an explicit device conversion is requested. Dense conversion and ordinary math operations do not detach tensors; autograd metadata is preserved according to normal PyTorch rules.
- property dense_array: Type[Any]#
Dense array type using PyTorch.
- Returns:
Concrete dense tensor class accepted by this backend.
- property sparse_array: Tuple[Type[Any], ...]#
Sparse array type tuple using PyTorch.
- Returns:
Tensor class accepted by this backend for sparse tensor layouts.
- is_dense(x)[source]#
Check whether an object is a dense PyTorch tensor.
- Input:
x: Object to inspect.
- Output:
Boolean indicating whether x is a strided PyTorch tensor.
- See:
https://docs.pytorch.org/docs/stable/tensor_attributes.html#torch-layout
- Parameters:
x (Any)
- Return type:
bool
- is_sparse(x)[source]#
Check whether an object is a sparse PyTorch tensor.
- Input:
x: Object to inspect.
- Output:
Boolean indicating whether x is a PyTorch tensor with a sparse layout.
- See:
- Parameters:
x (Any)
- Return type:
bool
- sanitize_dtype(dtype)[source]#
Normalize a dtype specifier using PyTorch.
- Input:
dtype: Optional dtype requested by SpaceCore or the caller.
- Output:
Backend dtype object accepted by PyTorch tensor constructors.
- See:
https://docs.pytorch.org/docs/stable/tensor_attributes.html#torch-dtype
- Backend-specific notes:
Nonefollowstorch.get_default_dtype(). NumPy dtype specifiers are mapped to equivalent PyTorch dtypes when supported.
- Parameters:
dtype (Any | None)
- Return type:
Any
- get_dtype(x)[source]#
Return a tensor dtype using PyTorch.
- Input:
x: Dense or sparse backend tensor.
- Output:
Backend dtype associated with x.
- See:
https://docs.pytorch.org/docs/stable/tensor_attributes.html#torch-dtype
- Parameters:
x (Any)
- Return type:
Any
- shape(x)[source]#
Return tensor shape metadata using PyTorch.
- Input:
x: Dense or sparse backend tensor.
- Output:
Tuple describing the logical shape of x.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.Tensor.shape.html
- Parameters:
x (Any)
- Return type:
tuple[int, …]
- ndim(x)[source]#
Return tensor rank metadata using PyTorch.
- Input:
x: Dense or sparse backend tensor.
- Output:
Number of dimensions in x.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.Tensor.ndim.html
- Parameters:
x (Any)
- Return type:
int
- size(x)[source]#
Return logical element count using PyTorch.
- Input:
x: Dense or sparse backend tensor.
- Output:
Total number of logical dense elements.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.numel.html
- Parameters:
x (Any)
- Return type:
int
- property inf#
Positive infinity scalar using PyTorch.
- Returns:
Backend tensor scalar representing positive infinity.
- property nan#
NaN scalar using PyTorch.
- Returns:
Backend tensor scalar representing NaN.
- property pi#
Pi scalar using PyTorch.
- Returns:
Backend tensor scalar representing pi.
- property e#
Euler number scalar using PyTorch.
- Returns:
Backend tensor scalar representing Euler’s number.
- property eps#
Machine epsilon scalar using PyTorch.
- Returns:
Backend tensor scalar for float64 machine epsilon.
- asarray(x, dtype=None, *, device=None, copy=None)[source]#
Convert input to a dense tensor using PyTorch.
- Input:
x/a: Array-like input and optional dtype, device, or copy controls.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.as_tensor.html
- Backend-specific notes:
Sparse tensors are densified. Existing tensors keep autograd metadata according to normal PyTorch conversion rules.
- Parameters:
x (Any)
dtype (Any | None)
device (Any | None)
copy (bool | None)
- Return type:
DenseArray
- astype(x, dtype, copy=True, *, non_blocking=False, memory_format=None)[source]#
Cast a tensor to a dtype using PyTorch.
- Input:
x: Dense backend tensor; dtype: Target dtype; copy: Whether to force a copy.
- Output:
Tensor with the requested dtype.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.Tensor.to.html
- Parameters:
x (DenseArray)
dtype (Any)
copy (bool)
non_blocking (bool)
memory_format (Any | None)
- Return type:
DenseArray
- assparse(x, *, format='coo', dtype=None, device=None)[source]#
Convert input to a sparse tensor using PyTorch.
- Input:
x: Dense, sparse, or SciPy sparse input plus sparse format, dtype, and device.
- Output:
Sparse backend tensor in COO, CSR, or CSC format.
- See:
- Backend-specific notes:
SciPy sparse inputs are converted through COO indices and values. Dense inputs are converted through PyTorch’s sparse COO conversion.
- Parameters:
x (Any)
format (Literal['coo', 'csr', 'csc'])
dtype (Any | None)
device (Any | None)
- Return type:
SparseArray
- empty(shape, dtype=None, *, out=None, layout=None, device=None, requires_grad=False, pin_memory=False, memory_format=None)[source]#
Create an uninitialized dense tensor using PyTorch.
- Input:
shape: Output shape; dtype and device: Optional construction parameters.
- Output:
Dense backend tensor with uninitialized values.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.empty.html
- Parameters:
shape (int | Tuple[int, ...])
dtype (Any | None)
out (DenseArray | None)
layout (Any | None)
device (Any | None)
requires_grad (bool)
pin_memory (bool)
memory_format (Any | None)
- Return type:
DenseArray
- zeros(shape, dtype=None, *, out=None, layout=None, device=None, requires_grad=False)[source]#
Create a dense tensor filled with zeros using PyTorch.
- Input:
shape: Output shape; dtype and device: Optional construction parameters.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.zeros.html
- Parameters:
shape (int | Tuple[int, ...])
dtype (Any | None)
out (DenseArray | None)
layout (Any | None)
device (Any | None)
requires_grad (bool)
- Return type:
DenseArray
- ones(shape, dtype=None, *, out=None, layout=None, device=None, requires_grad=False)[source]#
Create a dense tensor filled with ones using PyTorch.
- Input:
shape: Output shape; dtype and device: Optional construction parameters.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.ones.html
- Parameters:
shape (int | Tuple[int, ...])
dtype (Any | None)
out (DenseArray | None)
layout (Any | None)
device (Any | None)
requires_grad (bool)
- Return type:
DenseArray
- zeros_like(x, dtype=None, *, layout=None, device=None, requires_grad=False, memory_format=None)[source]#
Create a zero tensor matching another tensor using PyTorch.
- Input:
x: Reference tensor; dtype and device: Optional overrides.
- Output:
Dense backend tensor with shape matching x.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.zeros_like.html
- Parameters:
x (DenseArray)
dtype (Any | None)
layout (Any | None)
device (Any | None)
requires_grad (bool)
memory_format (Any | None)
- Return type:
DenseArray
- ones_like(x, dtype=None, *, layout=None, device=None, requires_grad=False, memory_format=None)[source]#
Create a one tensor matching another tensor using PyTorch.
- Input:
x: Reference tensor; dtype and device: Optional overrides.
- Output:
Dense backend tensor with shape matching x.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.ones_like.html
- Parameters:
x (DenseArray)
dtype (Any | None)
layout (Any | None)
device (Any | None)
requires_grad (bool)
memory_format (Any | None)
- Return type:
DenseArray
- full_like(x, value, dtype=None, *, layout=None, device=None, requires_grad=False, memory_format=None)[source]#
Create a filled tensor matching another tensor using PyTorch.
- Input:
x: Reference tensor; value: Fill value; dtype and device: Optional overrides.
- Output:
Dense backend tensor with shape matching x.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.full_like.html
- Parameters:
x (DenseArray)
value (Any)
dtype (Any | None)
layout (Any | None)
device (Any | None)
requires_grad (bool)
memory_format (Any | None)
- Return type:
DenseArray
- arange(start=0, stop=None, step=None, dtype=None, *, out=None, layout=None, device=None, requires_grad=False)[source]#
Create a range tensor using PyTorch.
- Input:
start, stop, step: Range parameters; dtype and device: Optional construction parameters.
- Output:
Dense backend tensor containing evenly spaced values.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.arange.html
- Parameters:
start (int | float)
stop (int | float | None)
step (int | float | None)
dtype (Any | None)
out (DenseArray | None)
layout (Any | None)
device (Any | None)
requires_grad (bool)
- Return type:
DenseArray
- full(shape, fill_value, dtype=None, *, out=None, layout=None, device=None, requires_grad=False)[source]#
Create a filled dense tensor using PyTorch.
- Input:
shape: Output shape; fill_value: Fill value; dtype and device: Optional parameters.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.full.html
- Parameters:
shape (int | Tuple[int, ...])
fill_value (Any)
dtype (Any | None)
out (DenseArray | None)
layout (Any | None)
device (Any | None)
requires_grad (bool)
- Return type:
DenseArray
- eye(n, m=None, k=0, dtype=None, *, out=None, layout=None, device=None, requires_grad=False)[source]#
Create a two-dimensional identity-like tensor using PyTorch.
- Input:
n, m: Matrix dimensions; k: Diagonal offset; dtype and device: Optional parameters.
- Output:
Dense backend tensor with ones on the requested diagonal.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.eye.html
- Backend-specific notes:
PyTorch
torch.eyehas no diagonal offset parameter, so SpaceCore constructs the offset diagonal explicitly.
- Parameters:
n (int)
m (int | None)
k (int)
dtype (Any | None)
out (DenseArray | None)
layout (Any | None)
device (Any | None)
requires_grad (bool)
- Return type:
DenseArray
- ravel(x)[source]#
Flatten a tensor using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
One-dimensional tensor view or copy following PyTorch semantics.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.ravel.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- reshape(x, shape, *, copy=None)[source]#
Reshape a tensor using PyTorch.
- Input:
x: Dense backend tensor; shape: Target shape; copy: Whether to clone first.
- Output:
Reshaped dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.reshape.html
- Parameters:
x (DenseArray)
shape (int | Tuple[int, ...])
copy (bool | None)
- Return type:
DenseArray
- transpose(x, axes=None)[source]#
Permute tensor axes using PyTorch.
- Input:
x: Dense backend tensor; axes: Optional axis order.
- Output:
Tensor with permuted axes.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.permute.html
- Parameters:
x (DenseArray)
axes (Sequence[int] | None)
- Return type:
DenseArray
- swapaxes(x, axis1, axis2)[source]#
Swap two tensor axes using PyTorch.
- Input:
x: Dense backend tensor; axis1, axis2: Axes to swap.
- Output:
Tensor with the requested axes swapped.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.swapaxes.html
- Parameters:
x (DenseArray)
axis1 (int)
axis2 (int)
- Return type:
DenseArray
- broadcast_to(x, shape)[source]#
Broadcast a tensor to a shape using PyTorch.
- Input:
x: Dense backend tensor; shape: Target broadcast shape.
- Output:
Broadcasted tensor view following PyTorch broadcasting rules.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.broadcast_to.html
- Parameters:
x (DenseArray)
shape (int | Tuple[int, ...])
- Return type:
DenseArray
- expand_dims(x, axis)[source]#
Insert singleton dimensions using PyTorch.
- Input:
x: Dense backend tensor; axis: Axis or axes where dimensions are inserted.
- Output:
Tensor with inserted singleton dimensions.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.unsqueeze.html
- Parameters:
x (DenseArray)
axis (int | Sequence[int])
- Return type:
DenseArray
- squeeze(x, axis=None)[source]#
Remove singleton dimensions using PyTorch.
- Input:
x: Dense backend tensor; axis: Optional axis or axes to squeeze.
- Output:
Tensor with singleton dimensions removed.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.squeeze.html
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
- Return type:
DenseArray
- moveaxis(x, source, destination)[source]#
Move tensor axes to new positions using PyTorch.
- Input:
x: Dense backend tensor; source and destination: Axis positions.
- Output:
Tensor with axes moved.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.moveaxis.html
- Parameters:
x (DenseArray)
source (int | Sequence[int])
destination (int | Sequence[int])
- Return type:
DenseArray
- stack(arrays, axis=0, *, out=None)[source]#
Stack tensors along a new axis using PyTorch.
- Input:
arrays: Sequence of tensors; axis: New axis; out: Optional output tensor.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.stack.html
- Parameters:
arrays (Sequence[DenseArray])
axis (int)
out (DenseArray | None)
- Return type:
DenseArray
- conj(x)[source]#
Return the complex conjugate using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
Tensor containing complex conjugates.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.conj.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- real(x)[source]#
Return the real part of a tensor using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
Tensor view or value containing real components.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.real.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- imag(x)[source]#
Return the imaginary part of a tensor using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
Tensor view or value containing imaginary components.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.imag.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- abs(x, *, out=None)[source]#
Compute elementwise absolute value using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.abs.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
- Return type:
DenseArray
- sign(x, *, out=None)[source]#
Compute elementwise sign using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.sign.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
- Return type:
DenseArray
- sqrt(x, *, out=None)[source]#
Compute elementwise square root using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.sqrt.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
- Return type:
DenseArray
- sum(x, axis=None, dtype=None, keepdims=False, *, out=None)[source]#
Sum tensor elements using PyTorch.
- Input:
x: Dense backend tensor; axis, dtype, keepdims: Reduction controls.
- Output:
Dense backend tensor or scalar tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.sum.html
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
dtype (Any | None)
keepdims (bool)
out (DenseArray | None)
- Return type:
DenseArray
- mean(x, axis=None, dtype=None, keepdims=False, *, out=None)[source]#
Average tensor elements using PyTorch.
- Input:
x: Dense backend tensor; axis, dtype, keepdims: Reduction controls.
- Output:
Dense backend tensor or scalar tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.mean.html
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
dtype (Any | None)
keepdims (bool)
out (DenseArray | None)
- Return type:
DenseArray
- min(x, axis=None, keepdims=False, *, out=None)[source]#
Compute minimum values using PyTorch.
- Input:
x: Dense backend tensor; axis and keepdims: Reduction controls.
- Output:
Dense backend tensor or scalar tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.amin.html
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
keepdims (bool)
out (DenseArray | None)
- Return type:
DenseArray
- max(x, axis=None, keepdims=False, *, out=None)[source]#
Compute maximum values using PyTorch.
- Input:
x: Dense backend tensor; axis and keepdims: Reduction controls.
- Output:
Dense backend tensor or scalar tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.amax.html
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
keepdims (bool)
out (DenseArray | None)
- Return type:
DenseArray
- prod(x, axis=None, dtype=None, keepdims=False, *, out=None)[source]#
Multiply tensor elements using PyTorch.
- Input:
x: Dense backend tensor; axis, dtype, keepdims: Reduction controls.
- Output:
Dense backend tensor or scalar tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.prod.html
- Backend-specific notes:
Multiple-axis products are applied one axis at a time because PyTorch’s
torch.prodreduces a single dimension per call.
- Parameters:
x (DenseArray)
axis (int | Sequence[int] | None)
dtype (Any | None)
keepdims (bool)
out (DenseArray | None)
- Return type:
DenseArray
- trace(x, offset=0, axis1=0, axis2=1, dtype=None)[source]#
Sum diagonal entries using PyTorch.
- Input:
x: Dense backend tensor; offset, axis1, axis2, dtype: Diagonal controls.
- Output:
Dense backend tensor or scalar tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.diagonal.html
- Parameters:
x (DenseArray)
offset (int)
axis1 (int)
axis2 (int)
dtype (Any | None)
- Return type:
DenseArray
- argsort(x, axis=-1, stable=False, descending=False)[source]#
Return sorting indices using PyTorch.
- Input:
x: Dense backend tensor; axis, stable, descending: Sorting controls.
- Output:
Integer tensor of indices.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.argsort.html
- Parameters:
x (DenseArray)
axis (int)
stable (bool)
descending (bool)
- Return type:
DenseArray
- sort(x, axis=-1, stable=False, descending=False, *, out=None)[source]#
Sort tensor values using PyTorch.
- Input:
x: Dense backend tensor; axis, stable, descending: Sorting controls.
- Output:
Dense backend tensor of sorted values.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.sort.html
- Parameters:
x (DenseArray)
axis (int)
stable (bool)
descending (bool)
out (tuple[DenseArray, DenseArray] | None)
- Return type:
DenseArray
- argmin(x, axis=None, keepdims=False)[source]#
Return indices of minimum values using PyTorch.
- Input:
x: Dense backend tensor; axis and keepdims: Reduction controls.
- Output:
Integer tensor of indices.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.argmin.html
- Parameters:
x (DenseArray)
axis (int | None)
keepdims (bool)
- Return type:
DenseArray
- argmax(x, axis=None, keepdims=False)[source]#
Return indices of maximum values using PyTorch.
- Input:
x: Dense backend tensor; axis and keepdims: Reduction controls.
- Output:
Integer tensor of indices.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.argmax.html
- Parameters:
x (DenseArray)
axis (int | None)
keepdims (bool)
- Return type:
DenseArray
- vdot(x, y, *, out=None)[source]#
Compute conjugating vector dot product using PyTorch.
- Input:
x, y: Dense backend tensors.
- Output:
Scalar tensor containing the vector dot product.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.vdot.html
- Parameters:
x (DenseArray)
y (DenseArray)
out (DenseArray | None)
- Return type:
DenseArray
- matmul(a, b, *, out=None)[source]#
Matrix-multiply tensors using PyTorch.
- Input:
a, b: Dense backend tensors.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.matmul.html
- Parameters:
a (DenseArray)
b (DenseArray)
out (DenseArray | None)
- Return type:
DenseArray
- sparse_matmul(a, b, *, reduce='sum')[source]#
Matrix-multiply a sparse tensor by a dense tensor using PyTorch.
- Input:
a: Sparse backend tensor; b: Dense backend tensor or vector.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.sparse.mm.html
- Parameters:
a (SparseArray)
b (DenseArray)
reduce (Literal['sum', 'mean', 'amax', 'amin'])
- Return type:
DenseArray
- kron(a, b, *, out=None)[source]#
Compute the Kronecker product using PyTorch.
- Input:
a, b: Dense backend tensors.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.kron.html
- Parameters:
a (DenseArray)
b (DenseArray)
out (DenseArray | None)
- Return type:
DenseArray
- einsum(subscripts, *operands)[source]#
Evaluate an Einstein summation using PyTorch.
- Input:
subscripts: Einsum expression; operands: Dense backend tensors.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.einsum.html
- Parameters:
subscripts (str)
operands (DenseArray)
- Return type:
DenseArray
- eigh(x, UPLO='L', *, out=None)[source]#
Compute Hermitian eigenvalues and eigenvectors using PyTorch.
- Input:
x: Dense Hermitian or symmetric backend tensor.
- Output:
Tuple of eigenvalues and eigenvectors.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.linalg.eigh.html
- Parameters:
x (DenseArray)
UPLO (Literal['L', 'U'])
out (tuple[DenseArray, DenseArray] | None)
- Return type:
tuple[DenseArray, DenseArray]
- norm(x, ord=None, axis=None, keepdims=False, *, dtype=None, out=None)[source]#
Compute vector or matrix norms using PyTorch.
- Input:
x: Dense backend tensor; ord, axis, keepdims: Norm controls.
- Output:
Dense backend tensor or scalar tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.linalg.norm.html
- Parameters:
x (DenseArray)
ord (int | str | None)
axis (int | Sequence[int] | None)
keepdims (bool)
dtype (Any | None)
out (DenseArray | None)
- Return type:
DenseArray
- solve(A, b, *, left=True, out=None)[source]#
Solve a linear system using PyTorch.
- Input:
A: Coefficient tensor; b: Right-hand side tensor.
- Output:
Dense backend tensor solving
A @ x = b.- See:
https://docs.pytorch.org/docs/stable/generated/torch.linalg.solve.html
- Parameters:
A (DenseArray)
b (DenseArray)
left (bool)
out (DenseArray | None)
- Return type:
DenseArray
- eigvalsh(A, UPLO='L', *, out=None)[source]#
Compute Hermitian eigenvalues using PyTorch.
- Input:
A: Dense Hermitian or symmetric backend tensor.
- Output:
Dense backend tensor of eigenvalues.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.linalg.eigvalsh.html
- Parameters:
A (DenseArray)
UPLO (Literal['L', 'U'])
out (DenseArray | None)
- Return type:
DenseArray
- svd(A, full_matrices=True, compute_uv=True, hermitian=False, *, driver=None, out=None)[source]#
Compute singular value decomposition using PyTorch.
- Input:
A: Dense backend tensor; full_matrices, compute_uv, hermitian: SVD controls.
- Output:
Singular values or tuple
(U, S, Vh).- See:
https://docs.pytorch.org/docs/stable/generated/torch.linalg.svd.html
- Backend-specific notes:
PyTorch does not expose a
hermitianoption for SVD. Whencompute_uvis false, this delegates totorch.linalg.svdvals.
- Parameters:
A (DenseArray)
full_matrices (bool)
compute_uv (bool)
hermitian (bool)
driver (str | None)
out (DenseArray | tuple[DenseArray, DenseArray, DenseArray] | None)
- Return type:
DenseArray | tuple[DenseArray, DenseArray, DenseArray]
- cholesky(A, *, upper=False, out=None)[source]#
Compute a Cholesky factorization using PyTorch.
- Input:
A: Positive-definite dense backend tensor.
- Output:
Dense backend tensor containing the Cholesky factor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.linalg.cholesky.html
- Parameters:
A (DenseArray)
upper (bool)
out (DenseArray | None)
- Return type:
DenseArray
- logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False, *, out=None)[source]#
Compute log-sum-exp using PyTorch.
- Input:
a: Dense backend tensor; axis, b, keepdims, return_sign: Reduction controls.
- Output:
Dense backend tensor, or
(value, sign)whenreturn_signis true.- See:
https://docs.pytorch.org/docs/stable/generated/torch.logsumexp.html
- Backend-specific notes:
Weighted and signed variants are implemented in SpaceCore because PyTorch’s public
logsumexpdoes not expose SciPy-styleborreturn_signparameters.
- Parameters:
a (DenseArray)
axis (int | Sequence[int] | None)
b (DenseArray | None)
keepdims (bool)
return_sign (bool)
out (DenseArray | None)
- Return type:
DenseArray | tuple[DenseArray, DenseArray]
- exp(x, *, out=None)[source]#
Compute elementwise exponential using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.exp.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
- Return type:
DenseArray
- log(x, *, out=None)[source]#
Compute elementwise natural logarithm using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.log.html
- Parameters:
x (DenseArray)
out (DenseArray | None)
- Return type:
DenseArray
- where(condition, x=None, y=None, *, out=None)[source]#
Select values conditionally using PyTorch.
- Input:
condition: Boolean tensor or scalar; x, y: Values to select.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.where.html
- Parameters:
condition (DenseArray | bool)
x (ArrayLike | None)
y (ArrayLike | None)
out (DenseArray | None)
- Return type:
DenseArray
- maximum(x, y, *, out=None)[source]#
Compute elementwise maximum using PyTorch.
- Input:
x, y: Array-like operands.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.maximum.html
- Parameters:
x (ArrayLike)
y (ArrayLike)
out (DenseArray | None)
- Return type:
DenseArray
- minimum(x, y, *, out=None)[source]#
Compute elementwise minimum using PyTorch.
- Input:
x, y: Array-like operands.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.minimum.html
- Parameters:
x (ArrayLike)
y (ArrayLike)
out (DenseArray | None)
- Return type:
DenseArray
- clip(x, a_min=None, a_max=None, *, out=None)[source]#
Clip tensor values using PyTorch.
- Input:
x: Dense backend tensor; a_min, a_max: Lower and upper bounds.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.clamp.html
- Parameters:
x (DenseArray)
a_min (ArrayLike | None)
a_max (ArrayLike | None)
out (DenseArray | None)
- Return type:
DenseArray
- isfinite(x)[source]#
Test finiteness elementwise using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
Boolean dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.isfinite.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- isnan(x)[source]#
Test NaN values elementwise using PyTorch.
- Input:
x: Dense backend tensor.
- Output:
Boolean dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.isnan.html
- Parameters:
x (DenseArray)
- Return type:
DenseArray
- concatenate(arrays, axis=0, dtype=None, *, out=None)[source]#
Concatenate tensors using PyTorch.
- Input:
arrays: Sequence of dense backend tensors; axis: Concatenation axis; dtype: Optional cast.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.cat.html
- Parameters:
arrays (Sequence[DenseArray])
axis (int)
dtype (Any | None)
out (DenseArray | None)
- Return type:
DenseArray
- take(x, indices, axis=None, *, out=None)[source]#
Take tensor elements by index using PyTorch.
- Input:
x: Dense backend tensor; indices: Integer indices; axis: Optional selection axis.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.take.html
- Parameters:
x (DenseArray)
indices (DenseArray)
axis (int | None)
out (DenseArray | None)
- Return type:
DenseArray
- diag(x, k=0, *, out=None)[source]#
Extract or construct a diagonal tensor using PyTorch.
- Input:
x: Dense backend tensor; k: Diagonal offset.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.diag.html
- Parameters:
x (DenseArray)
k (int)
out (DenseArray | None)
- Return type:
DenseArray
- diagonal(x, offset=0, axis1=0, axis2=1)[source]#
Return a tensor diagonal using PyTorch.
- Input:
x: Dense backend tensor; offset, axis1, axis2: Diagonal controls.
- Output:
Dense backend tensor view or value.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.diagonal.html
- Parameters:
x (DenseArray)
offset (int)
axis1 (int)
axis2 (int)
- Return type:
DenseArray
- tril(x, k=0, *, out=None)[source]#
Return the lower triangular part using PyTorch.
- Input:
x: Dense backend tensor; k: Diagonal offset.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.tril.html
- Parameters:
x (DenseArray)
k (int)
out (DenseArray | None)
- Return type:
DenseArray
- triu(x, k=0, *, out=None)[source]#
Return the upper triangular part using PyTorch.
- Input:
x: Dense backend tensor; k: Diagonal offset.
- Output:
Dense backend tensor.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.triu.html
- Parameters:
x (DenseArray)
k (int)
out (DenseArray | None)
- Return type:
DenseArray
- index_set(x, index, values, *, copy=True)[source]#
Set indexed tensor values using PyTorch.
- Input:
x: Dense backend tensor; index: Index expression; values: Replacement values.
- Output:
Tensor with indexed values replaced.
- See:
- Backend-specific notes:
When
copyis true, this clonesxbefore assignment. Otherwise the assignment mutatesxin place.
- Parameters:
x (DenseArray)
index (int | slice | Any | Tuple[Any, ...])
values (DenseArray)
copy (bool)
- index_add(x, index, values, *, copy=True)[source]#
Add values at indexed tensor positions using PyTorch.
- Input:
x: Dense backend tensor; index: Index expression; values: Values to add.
- Output:
Tensor with indexed values incremented.
- See:
- Backend-specific notes:
When
copyis true, this clonesxbefore assignment. Otherwise the assignment mutatesxin place.
- Parameters:
x (DenseArray)
index (int | slice | Any | Tuple[Any, ...])
values (DenseArray)
copy (bool)
- ix_(*args)[source]#
Construct open mesh indices using PyTorch.
- Input:
args: One-dimensional index arrays or array-like objects.
- Output:
Tuple of broadcastable index tensors.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.meshgrid.html
- Parameters:
args (Any)
- Return type:
Any
- fori_loop(lower, upper, body_fun, init_val)[source]#
Run a counted loop eagerly in Python for PyTorch.
- Input:
lower, upper: Integer loop bounds; body_fun: Loop body; init_val: Initial value.
- Output:
Final loop value.
- See:
https://docs.python.org/3/reference/compound_stmts.html#the-for-statement
- Backend-specific notes:
This is an eager Python loop, not a compiled PyTorch control-flow primitive. Tensor operations inside
body_funfollow PyTorch autograd semantics.
- Parameters:
lower (int)
upper (int)
body_fun (Callable[[int, T], T])
init_val (T)
- Return type:
T
- while_loop(cond_fun, body_fun, init_val)[source]#
Run a while loop eagerly in Python for PyTorch.
- Input:
cond_fun: Loop predicate; body_fun: Loop body; init_val: Initial value.
- Output:
Final loop value.
- See:
https://docs.python.org/3/reference/compound_stmts.html#the-while-statement
- Backend-specific notes:
This is an eager Python loop. The predicate is converted to a Python bool each iteration.
- Parameters:
cond_fun (Callable[[T], bool])
body_fun (Callable[[T], T])
init_val (T)
- Return type:
T
- scan(f, init, xs, length=None, reverse=False, unroll=1)[source]#
Run a scan-style loop eagerly in Python for PyTorch.
- Input:
f: Scan body; init: Initial carry; xs: Per-step inputs plus scan options.
- Output:
Tuple of final carry and stacked outputs.
- See:
https://docs.jax.dev/en/latest/_autosummary/jax.lax.scan.html
- Backend-specific notes:
PyTorch has no direct eager equivalent to
jax.lax.scanin this backend. SpaceCore implements a Python loop and stacks tensor leaves at the end.
- Parameters:
f (Callable[[Carry, X], Tuple[Carry, Y]])
init (Carry)
xs (X)
length (int | None)
reverse (bool)
unroll (int)
- Return type:
Tuple[Carry, Y]
- cond(pred, true_fun, false_fun, *operands)[source]#
Run conditional branch selection eagerly in Python for PyTorch.
- Input:
pred: Predicate; true_fun and false_fun: Branch functions; operands: Branch inputs.
- Output:
Result returned by the selected branch.
- See:
https://docs.python.org/3/reference/expressions.html#conditional-expressions
- Backend-specific notes:
This uses Python eager branching, not a staged or compiled control flow primitive.
- Parameters:
pred (bool)
true_fun (Callable[[T], R])
false_fun (Callable[[T], R])
operands (Any)
- Return type:
R
- allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]#
Compare dense tensors elementwise within tolerances using PyTorch.
- Input:
a, b: Dense backend tensors; rtol, atol, equal_nan: Comparison controls.
- Output:
Boolean indicating whether tensors are close.
- See:
https://docs.pytorch.org/docs/stable/generated/torch.allclose.html
- Parameters:
a (DenseArray)
b (DenseArray)
rtol (float)
atol (float)
equal_nan (bool)
- Return type:
bool
- allclose_sparse(a, b, rtol=1e-05, atol=1e-08)[source]#
Compare sparse tensors elementwise within tolerances using PyTorch.
- Input:
a, b: Sparse backend tensors; rtol and atol: Comparison controls.
- Output:
Boolean indicating whether sparse tensors are close.
- See:
- Backend-specific notes:
Sparse tensors are compared by converting both operands to dense tensors before calling
allclose.
- Parameters:
a (SparseArray)
b (SparseArray)
rtol (float)
atol (float)
- Return type:
bool
- property allow_sparse: bool#
Generic backend-agnostic wrapper to sparse-array support flag.
- Input:
None.
- Output:
Boolean indicating whether this backend supports sparse arrays.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- property family: str#
Generic backend-agnostic wrapper to backend family identifier.
- Input:
None.
- Output:
String naming the concrete backend family.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- is_array(x)#
Generic backend-agnostic wrapper to test for any backend array.
- Input:
x: Object to test.
- Output:
True when x is dense or sparse for this backend.
This declaration only specifies the portable SpaceCore interface. See the concrete backend implementation for backend-specific behavior.
- Parameters:
x (Any)
- Return type:
bool