tensor.slinalg
– Linear Algebra Ops Using Scipy#
Note
This module is not imported by default. You need to import it to use it.
API#
- pytensor.tensor.slinalg.kron(a, b)[source]#
Kronecker product.
Same as scipy.linalg.kron(a, b).
- Parameters:
a (array_like) –
b (array_like) –
- Return type:
array_like with a.ndim + b.ndim - 2 dimensions
Notes
numpy.kron(a, b) != scipy.linalg.kron(a, b)! They don’t have the same shape and order when a.ndim != b.ndim != 2.
- pytensor.tensor.slinalg.solve(a, b, *, assume_a='gen', lower=False, check_finite=True, b_ndim: Optional[int] = None)[source]#
Solves the linear equation set
a * x = b
for the unknownx
for squarea
matrix.If the data matrix is known to be a particular type then supplying the corresponding string to
assume_a
key chooses the dedicated solver. The available options aregeneric matrix
‘gen’
symmetric
‘sym’
hermitian
‘her’
positive definite
‘pos’
If omitted,
'gen'
is the default structure.The datatype of the arrays define which solver is called regardless of the values. In other words, even when the complex array entries have precisely zero imaginary parts, the complex solver will be called based on the data type of the array.
- Parameters:
a ((..., N, N) array_like) – Square input data
b ((..., N, NRHS) array_like) – Input data for the right hand side.
lower (bool, optional) – If True, only the data contained in the lower triangle of
a
. Default is to use upper triangle. (ignored for'gen'
)check_finite (bool, optional) – Whether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.
assume_a (str, optional) – Valid entries are explained above.
b_ndim (int) – Whether the core case of b is a vector (1) or matrix (2). This will influence how batched dimensions are interpreted.
- pytensor.tensor.slinalg.solve_continuous_lyapunov(A: TensorLike, Q: TensorLike) TensorVariable [source]#
Solve the continuous Lyapunov equation \(A X + X A^H + Q = 0\).
- Parameters:
A – Square matrix of shape
N x N
; must have the same shape asQ
.Q – Square matrix of shape
N x N
; must have the same shape asA
.
- Returns:
Square matrix of shape
N x N
, representing the solution to theLyapunov equation
- pytensor.tensor.slinalg.solve_discrete_are(A, B, Q, R, enforce_Q_symmetric=False) TensorVariable [source]#
Solve the discrete Algebraic Riccati equation \(A^TXA - X - (A^TXB)(R + B^TXB)^{-1}(B^TXA) + Q = 0\).
- Parameters:
A (ArrayLike) – Square matrix of shape M x M
B (ArrayLike) – Square matrix of shape M x M
Q (ArrayLike) – Symmetric square matrix of shape M x M
R (ArrayLike) – Square matrix of shape N x N
enforce_Q_symmetric (bool) – If True, the provided Q matrix is transformed to 0.5 * (Q + Q.T) to ensure symmetry
- Returns:
X – Square matrix of shape M x M, representing the solution to the DARE
- Return type:
pt.matrix
- pytensor.tensor.slinalg.solve_discrete_lyapunov(A: TensorLike, Q: TensorLike, method: Literal['direct', 'bilinear'] = 'direct') TensorVariable [source]#
Solve the discrete Lyapunov equation \(A X A^H - X = Q\).
- Parameters:
A – Square matrix of shape N x N; must have the same shape as Q
Q – Square matrix of shape N x N; must have the same shape as A
method – Solver method used, one of
"direct"
or"bilinear"
."direct"
solves the problem directly via matrix inversion. This has a pure PyTensor implementation and can thus be cross-compiled to supported backends, and should be preferred whenN
is not large. The direct method scales poorly with the size ofN
, and the bilinear can be used in these cases.
- Returns:
Square matrix of shape
N x N
, representing the solution to theLyapunov equation
- pytensor.tensor.slinalg.solve_triangular(a: TensorVariable, b: TensorVariable, *, trans: Union[int, str] = 0, lower: bool = False, unit_diagonal: bool = False, check_finite: bool = True, b_ndim: Optional[int] = None) TensorVariable [source]#
Solve the equation
a x = b
forx
, assuminga
is a triangular matrix.- Parameters:
a – Square input data
b – Input data for the right hand side.
lower (bool, optional) – Use only data contained in the lower triangle of
a
. Default is to use upper triangle.trans ({0, 1, 2, ‘N’, ‘T’, ‘C’}, optional) – Type of system to solve: trans system 0 or ‘N’ a x = b 1 or ‘T’ a^T x = b 2 or ‘C’ a^H x = b
unit_diagonal (bool, optional) – If True, diagonal elements of
a
are assumed to be 1 and will not be referenced.check_finite (bool, optional) – Whether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.
b_ndim (int) – Whether the core case of b is a vector (1) or matrix (2). This will influence how batched dimensions are interpreted.