Python wrappers
Public Python APIs implemented by this engine symbol.Compute for a square float matrix and integer exponent.
Validates that a is at least 2-D, square in the trailing two
axes, and float-typed; dispatches to the backend. The output
shape always matches a's shape (matrix powers preserve shape).
Autograd is not wired — the result is a leaf in the gradient
graph.
Math
Repeated squaring decomposes (its binary representation) and accumulates the result in matrix multiplies.
Shape
a:(..., N, N).- Output: same shape as
a.
References
Knuth, The Art of Computer Programming, Vol. 2 §4.6.3 (right-to-left binary exponentiation). Higham, Functions of Matrices (2008), §1.2.
See Also
inv_op : Used internally when n < 0.
matmul_op : Single-step underlying primitive.
Parameters
aTensorImplPtrInput matrix of shape
(..., N, N).nintInteger exponent. Named
n for parity with the reference framework's matrix_power(a, n) signature; the algorithm refers to it as internally. May be zero, positive, or negative; negative values require to be invertible.Returns
TensorImplPtrTensor of shape (..., N, N) holding (and the identity matrix if n == 0).
Raises
ValueErrorIf
a is not square, fewer than 2-D, or non-float.LinAlgError(At backend level, when
n < 0.) If is singular.Notes
- No backward is registered;
matrix_poweroutputs are leaves. - For graph neural networks is often an adjacency or
normalised Laplacian — large
nis fine because cost grows only logarithmically.