tensor.slinalg – Linear Algebra Ops Using Scipy

Note

This module is not imported by default. You need to import it to use it.

API

class theano.tensor.slinalg.Cholesky(lower=True, on_error='raise')[source]

Return a triangular matrix square root of positive semi-definite x.

L = cholesky(X, lower=True) implies dot(L, L.T) == X.

Parameters:
  • lower (bool, default=True) – Whether to return the lower or upper cholesky factor
  • on_error (['raise', 'nan']) – If on_error is set to ‘raise’, this Op will raise a scipy.linalg.LinAlgError if the matrix is not positive definite. If on_error is set to ‘nan’, it will return a matrix containing nans instead.
L_op(inputs, outputs, gradients)[source]

Cholesky decomposition reverse-mode gradient update.

Symbolic expression for reverse-mode Cholesky gradient taken from [1]

References

[1]I. Murray, “Differentiation of the Cholesky decomposition”, http://arxiv.org/abs/1602.07527
make_node(x)[source]

Create a “apply” nodes for the inputs in that order.

perform(node, inputs, outputs)[source]

Required: Calculate the function on the inputs and put the variables in the output storage. Return None.

Parameters:
  • node (Apply instance) – Contains the symbolic inputs and outputs.
  • inputs (list) – Sequence of inputs (immutable).
  • output_storage (list) – List of mutable 1-element lists (do not change the length of these lists)

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a Numpy ndarray, with the right number of dimensions, and the correct dtype. Its shape and stride pattern, can be arbitrary. It not is guaranteed that it was produced by a previous call to impl. It could be allocated by another Op impl is free to reuse it as it sees fit, or to discard it and allocate new memory.

Raises:MethodNotDefined – The subclass does not override this method.
class theano.tensor.slinalg.CholeskyGrad(lower=True)[source]
make_node(x, l, dz)[source]

Create a “apply” nodes for the inputs in that order.

perform(node, inputs, outputs)[source]

Implements the “reverse-mode” gradient [2] for the Cholesky factorization of a positive-definite matrix.

References

[2]S. P. Smith. “Differentiation of the Cholesky Algorithm”. Journal of Computational and Graphical Statistics, Vol. 4, No. 2 (Jun.,1995), pp. 134-147 http://www.jstor.org/stable/1390762
class theano.tensor.slinalg.Eigvalsh(lower=True)[source]

Generalized eigenvalues of a Hermitian positive definite eigensystem.

make_node(a, b)[source]

Create a “apply” nodes for the inputs in that order.

perform(node, inputs, outputs)[source]

Required: Calculate the function on the inputs and put the variables in the output storage. Return None.

Parameters:
  • node (Apply instance) – Contains the symbolic inputs and outputs.
  • inputs (list) – Sequence of inputs (immutable).
  • output_storage (list) – List of mutable 1-element lists (do not change the length of these lists)

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a Numpy ndarray, with the right number of dimensions, and the correct dtype. Its shape and stride pattern, can be arbitrary. It not is guaranteed that it was produced by a previous call to impl. It could be allocated by another Op impl is free to reuse it as it sees fit, or to discard it and allocate new memory.

Raises:MethodNotDefined – The subclass does not override this method.
class theano.tensor.slinalg.EigvalshGrad(lower=True)[source]

Gradient of generalized eigenvalues of a Hermitian positive definite eigensystem.

make_node(a, b, gw)[source]

Create a “apply” nodes for the inputs in that order.

perform(node, inputs, outputs)[source]

Required: Calculate the function on the inputs and put the variables in the output storage. Return None.

Parameters:
  • node (Apply instance) – Contains the symbolic inputs and outputs.
  • inputs (list) – Sequence of inputs (immutable).
  • output_storage (list) – List of mutable 1-element lists (do not change the length of these lists)

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a Numpy ndarray, with the right number of dimensions, and the correct dtype. Its shape and stride pattern, can be arbitrary. It not is guaranteed that it was produced by a previous call to impl. It could be allocated by another Op impl is free to reuse it as it sees fit, or to discard it and allocate new memory.

Raises:MethodNotDefined – The subclass does not override this method.
class theano.tensor.slinalg.Expm[source]

Compute the matrix exponential of a square array.

make_node(A)[source]

Create a “apply” nodes for the inputs in that order.

perform(node, inputs, outputs)[source]

Required: Calculate the function on the inputs and put the variables in the output storage. Return None.

Parameters:
  • node (Apply instance) – Contains the symbolic inputs and outputs.
  • inputs (list) – Sequence of inputs (immutable).
  • output_storage (list) – List of mutable 1-element lists (do not change the length of these lists)

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a Numpy ndarray, with the right number of dimensions, and the correct dtype. Its shape and stride pattern, can be arbitrary. It not is guaranteed that it was produced by a previous call to impl. It could be allocated by another Op impl is free to reuse it as it sees fit, or to discard it and allocate new memory.

Raises:MethodNotDefined – The subclass does not override this method.
class theano.tensor.slinalg.ExpmGrad[source]

Gradient of the matrix exponential of a square array.

make_node(A, gw)[source]

Create a “apply” nodes for the inputs in that order.

perform(node, inputs, outputs)[source]

Required: Calculate the function on the inputs and put the variables in the output storage. Return None.

Parameters:
  • node (Apply instance) – Contains the symbolic inputs and outputs.
  • inputs (list) – Sequence of inputs (immutable).
  • output_storage (list) – List of mutable 1-element lists (do not change the length of these lists)

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a Numpy ndarray, with the right number of dimensions, and the correct dtype. Its shape and stride pattern, can be arbitrary. It not is guaranteed that it was produced by a previous call to impl. It could be allocated by another Op impl is free to reuse it as it sees fit, or to discard it and allocate new memory.

Raises:MethodNotDefined – The subclass does not override this method.
class theano.tensor.slinalg.Solve(A_structure='general', lower=False, overwrite_A=False, overwrite_b=False)[source]

Solve a system of linear equations.

For on CPU and GPU.

L_op(inputs, outputs, output_gradients)[source]

Reverse-mode gradient updates for matrix solve operation c = A \ b.

Symbolic expression for updates taken from [3].

References

[3]M. B. Giles, “An extended collection of matrix derivative results for forward and reverse mode automatic differentiation”, http://eprints.maths.ox.ac.uk/1079/
make_node(A, b)[source]

Create a “apply” nodes for the inputs in that order.

perform(node, inputs, output_storage)[source]

Required: Calculate the function on the inputs and put the variables in the output storage. Return None.

Parameters:
  • node (Apply instance) – Contains the symbolic inputs and outputs.
  • inputs (list) – Sequence of inputs (immutable).
  • output_storage (list) – List of mutable 1-element lists (do not change the length of these lists)

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a Numpy ndarray, with the right number of dimensions, and the correct dtype. Its shape and stride pattern, can be arbitrary. It not is guaranteed that it was produced by a previous call to impl. It could be allocated by another Op impl is free to reuse it as it sees fit, or to discard it and allocate new memory.

Raises:MethodNotDefined – The subclass does not override this method.
theano.tensor.slinalg.kron(a, b)[source]

Kronecker product.

Same as scipy.linalg.kron(a, b).

Parameters:
  • a (array_like) –
  • b (array_like) –
Returns:

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.

theano.tensor.slinalg.solve_symmetric = Solve{('symmetric', False, False, False)}[source]

Optimized implementation of theano.tensor.slinalg.solve() when A is symmetric.

theano.tensor.slinalg.solve(a, b)[source]

Solves the equation a x = b for x, where a is a matrix and b can be either a vector or a matrix.

Note

Parameters:
  • a ((M, M) symbolix matrix) – A square matrix
  • b ((M,) or (M, N) symbolic vector or matrix) – Right hand side matrix in a x = b
Returns:

x – x will have the same shape as b

Return type:

(M, ) or (M, N) symbolic vector or matrix

theano.tensor.slinalg.solve_lower_triangular(a, b)[source]

Optimized implementation of theano.tensor.slinalg.solve() when A is lower triangular.

theano.tensor.slinalg.solve_upper_triangular(a, b)[source]

Optimized implementation of theano.tensor.slinalg.solve() when A is upper triangular.