Tensor NumPy-parity ergonomics#
The generated Python API reference documents the compiled
tensor surface produced by the binding generator. On top of that, a thin
pure Python convenience layer (einsums/__init__.py) installs the
NumPy-style attributes and operators that array users reach for reflexively.
These are added in Python, so they are invisible to
the binding-driven docs and are documented here instead. They are installed
on every runtime tensor and view class:
RuntimeTensorF, RuntimeTensorD, RuntimeTensorC, RuntimeTensorZ
and the RuntimeTensorView{F,D,C,Z} variants. RuntimeTensor below
stands for any of them.
Added in version 2.0.0.
Note
@ (matmul) and the arithmetic operators do not fall through to
NumPy. They dispatch to einsums.linalg so the work stays on
Einsums code paths, and they are recorded into the active graph when used
inside cg.capture.
Array attributes#
- class einsums.RuntimeTensor#
- shape: tuple[int, ...]#
Axis sizes, built from
rank()/dim()(works on tensors and views). Read-only.
- dtype#
The NumPy dtype matching the class’s BLAS letter (
Ffor float32,Dfor float64,Cfor complex64,Zfor complex128). Read-only.
- T#
Zero-copy reversed-axis (transpose) view. Graph-aware: inside
cg.captureit routes throughcg.permute_viewso the view is recorded with the correct reversed dims/strides. Read-only.
- __array__(dtype=None, copy=None)#
NumPy array protocol. Zero-copy via the buffer protocol unless a
dtypecast orcopy=Trueforces a copy, sonp.asarray(t)andnp.array(t)work directly.
Views and copies#
- transpose(*axes)#
Zero-copy permuted view (NumPy semantics):
transpose()reverses axes,transpose(0, 2, 1)/transpose((0, 2, 1))permute them. Negative axes allowed. Graph-aware.
- swapaxes(axis1, axis2)#
Zero-copy view with two axes exchanged.
- copy()#
A fresh dense tensor holding a copy of this one (like NumPy).
Reductions#
- sum()#
Sum of all elements. Normally returns a Python scalar, but inside a
cg.captureblock, returns a graph[1]tensor.
- mean()#
Arithmetic mean (
sum() / size).
- max()#
Maximum element. Only defined for totally-ordered types, such as real types.
Operators#
- __matmul__(other)#
A @ B. matrix-matrix (gemm) or matrix-vector (gemv) viaeinsums.linalg, recorded into the graph under capture. The right-hand side must be another Einsums tensor with a matching dtype. Two vectors (inner product) raise an exception. For these cases, useeinsums.linalg.dot.
- __add__(other)#
Element-wise addition.
othermay be another Einsums tensor or a scalar. Dispatches toeinsums.linalg. Graph-aware. Reflected and in-place forms are provided to match NumPy:__radd__,__sub__,__rsub__,__mul__,__rmul__,__truediv__,__neg__,__pos__, and the in-place__iadd__,__isub__,__imul__,__itruediv__.