theano.gpuarray.linalg – Linear algebra operation

Warning

Some operation need Magma to be installed and the Theano flags config.magma__enabled=True to be activated. See also the flags config.magma__include_path and config.magma__library_path.

Linalg Op

class theano.gpuarray.linalg.GpuCholesky(lower=True, inplace=False)[source]

CUSOLVER GPU Cholesky Op.

Given a real positive definite matrix A returns either a lower triangular matrix L such that A == dot(L, L.T) if lower == True else returns an upper triangular matrix U such that A == dot(U.T, U) if lower == False.

Parameters

lower – Whether to return a lower rather than upper triangular decomposition.

L_op(inputs, outputs, gradients)[source]

Construct a graph for the L-operator.

This method is primarily used by tensor.Lop and dispatches to PureOp.grad by default.

The L-operator computes a row vector times the Jacobian. The mathematical relationship is v \frac{\partial f(x)}{\partial x}. The L-operator is also supported for generic tensors (not only for vectors).

Parameters
  • inputs (list of Variable) –

  • outputs (list of Variable) –

  • output_grads (list of Variable) –

make_node(inp)[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) – The symbolic Apply node that represents this computation.

  • inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.

  • output_storage (list of list) – List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.

  • params (tuple) – A tuple containing the values of each entry in __props__.

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 is not guaranteed that such pre-set values were produced by a previous call to this PureOp.perform; they could’ve been allocated by another PureOp’s perform method. A PureOp is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

Raises

MethodNotDefined – The subclass does not override this method.

prepare_node(node, storage_map, compute_map, impl)[source]

Make any special modifications that the Op needs before doing make_thunk().

This can modify the node inplace and should return nothing.

It can be called multiple time with different impl. It is the op responsibility to don’t re-prepare the node when it isn’t good to do so.

class theano.gpuarray.linalg.GpuCublasTriangularSolve(lower=True, trans='N')[source]

CUBLAS GPU Triangular Solve Op.

Parameters
  • lower – Whether system is lower-triangular (True) or upper-triangular (False).

  • trans – Whether to take the transpose of the input matrix or not.

L_op(inputs, outputs, output_gradients)[source]

Construct a graph for the L-operator.

This method is primarily used by tensor.Lop and dispatches to PureOp.grad by default.

The L-operator computes a row vector times the Jacobian. The mathematical relationship is v \frac{\partial f(x)}{\partial x}. The L-operator is also supported for generic tensors (not only for vectors).

Parameters
  • inputs (list of Variable) –

  • outputs (list of Variable) –

  • output_grads (list of Variable) –

make_node(inp1, inp2)[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) – The symbolic Apply node that represents this computation.

  • inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.

  • output_storage (list of list) – List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.

  • params (tuple) – A tuple containing the values of each entry in __props__.

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 is not guaranteed that such pre-set values were produced by a previous call to this PureOp.perform; they could’ve been allocated by another PureOp’s perform method. A PureOp is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

Raises

MethodNotDefined – The subclass does not override this method.

prepare_node(node, storage_map, compute_map, impl)[source]

Make any special modifications that the Op needs before doing make_thunk().

This can modify the node inplace and should return nothing.

It can be called multiple time with different impl. It is the op responsibility to don’t re-prepare the node when it isn’t good to do so.

class theano.gpuarray.linalg.GpuCusolverSolve(A_structure='general', trans='N', inplace=False)[source]

CUSOLVER GPU solver OP.

Parameters

trans – Whether to take the transpose of the input matrix or not.

L_op(inputs, outputs, output_gradients)[source]

Construct a graph for the L-operator.

This method is primarily used by tensor.Lop and dispatches to PureOp.grad by default.

The L-operator computes a row vector times the Jacobian. The mathematical relationship is v \frac{\partial f(x)}{\partial x}. The L-operator is also supported for generic tensors (not only for vectors).

Parameters
  • inputs (list of Variable) –

  • outputs (list of Variable) –

  • output_grads (list of Variable) –

make_node(inp1, inp2)[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) – The symbolic Apply node that represents this computation.

  • inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.

  • output_storage (list of list) – List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.

  • params (tuple) – A tuple containing the values of each entry in __props__.

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 is not guaranteed that such pre-set values were produced by a previous call to this PureOp.perform; they could’ve been allocated by another PureOp’s perform method. A PureOp is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

Raises

MethodNotDefined – The subclass does not override this method.

prepare_node(node, storage_map, compute_map, impl)[source]

Make any special modifications that the Op needs before doing make_thunk().

This can modify the node inplace and should return nothing.

It can be called multiple time with different impl. It is the op responsibility to don’t re-prepare the node when it isn’t good to do so.

class theano.gpuarray.linalg.GpuMagmaBase(func_files, func_name=None)[source]

Base class for magma related operations. Add the necessary headers, libraries and optionally the location of headers and library.

c_header_dirs()[source]

Optional: Return a list of header search paths required by code returned by this class.

Examples

return [‘/usr/local/include’, ‘/opt/weirdpath/src/include’]

Provides search paths for headers, in addition to those in any relevant environment variables.

Hint: for unix compilers, these are the things that get ‘-I’ prefixed in the compiler cmdline.

Raises

MethodNotDefined – Subclass does not implement this method.

c_headers()[source]

Optional: Return a list of header files required by code returned by this class.

Examples

return [‘<iostream>’, ‘<math.h>’, ‘/full/path/to/header.h’]

These strings will be prefixed with “#include ” and inserted at the beginning of the c source code.

Strings in this list that start neither with ‘<’ nor ‘”’ will be enclosed in double-quotes.

Raises

MethodNotDefined – Subclass does not implement this method.

c_lib_dirs()[source]

Optional: Return a list of library search paths required by code returned by this class.

Examples

return [‘/usr/local/lib’, ‘/opt/weirdpath/build/libs’].

Provides search paths for libraries, in addition to those in any relevant environment variables (e.g. LD_LIBRARY_PATH).

Hint: for unix compilers, these are the things that get ‘-L’ prefixed in the compiler cmdline.

Raises

MethodNotDefined – Subclass does not implement this method.

c_libraries()[source]

Optional: Return a list of libraries required by code returned by this class.

Examples

return [‘gsl’, ‘gslcblas’, ‘m’, ‘fftw3’, ‘g2c’].

The compiler will search the directories specified by the environment variable LD_LIBRARY_PATH in addition to any returned by c_lib_dirs.

Hint: for unix compilers, these are the things that get ‘-l’ prefixed in the compiler cmdline.

Raises

MethodNotDefined – Subclass does not implement this method.

prepare_node(node, storage_map, compute_map, impl)[source]

Make any special modifications that the Op needs before doing make_thunk().

This can modify the node inplace and should return nothing.

It can be called multiple time with different impl. It is the op responsibility to don’t re-prepare the node when it isn’t good to do so.

class theano.gpuarray.linalg.GpuMagmaCholesky(lower=True, inplace=False)[source]

Computes the cholesky decomposition of a matrix A using magma library.

make_node(A)[source]

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

class theano.gpuarray.linalg.GpuMagmaEigh(UPLO='L', compute_v=True)[source]

Computes the eigen decomposition of a symmetric matrix A using magma library.

Parameters
  • UPLO (Specifies whether the calculation is done with the lower triangular) – part of matrix (L, default) or the upper triangular part (U).

  • compute_v (If True, computes eigenvalues and eigenvectors (True,) – default). If False, computes only eigenvalues of matrix.

make_node(A)[source]

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

class theano.gpuarray.linalg.GpuMagmaMatrixInverse(inplace=False)[source]

Computes the inverse of a matrix A using magma library.

make_node(A)[source]

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

class theano.gpuarray.linalg.GpuMagmaQR(complete=True)[source]

Computes the qr decomposition of a matrix A using magma library.

Parameters

complete (If False, returns only R.) –

Warning

Because of implementation constraints, this Op returns outputs in order R, Q. Use theano.gpuarray.linalg.gpu_qr() to get them in expected order Q, R.

make_node(A)[source]

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

class theano.gpuarray.linalg.GpuMagmaSVD(full_matrices=True, compute_uv=True)[source]

Computes the svd of a matrix A using magma library.

Warning

Because of implementation constraints, this Op returns outputs in order S, U, VT. Use theano.gpuarray.linalg.gpu_svd() to get them in expected order U, S, VT.

make_node(A)[source]

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

prepare_node(node, storage_map, compute_map, impl)[source]

Make any special modifications that the Op needs before doing make_thunk().

This can modify the node inplace and should return nothing.

It can be called multiple time with different impl. It is the op responsibility to don’t re-prepare the node when it isn’t good to do so.

theano.gpuarray.linalg.gpu_matrix_inverse(a)[source]

This function performs the matrix inverse on GPU.

Returns

a_inv

Return type

matrix

theano.gpuarray.linalg.gpu_qr(a, complete=True)[source]

This function performs the QR on GPU.

Parameters

complete (bool, optional) – If False, returns only r.

Returns

Q, R

Return type

matrices

theano.gpuarray.linalg.gpu_svd(a, full_matrices=1, compute_uv=1)[source]

This function performs the SVD on GPU.

Parameters
  • full_matrices (bool, optional) – If True (default), u and v have the shapes (M, M) and (N, N), respectively. Otherwise, the shapes are (M, K) and (K, N), respectively, where K = min(M, N).

  • compute_uv (bool, optional) – Whether or not to compute u and v in addition to s. True by default.

Returns

U, V, D

Return type

matrices