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 Loperator.
This method is primarily used by Lop and dispatches to Op.grad by default.
The Loperator computes a row vector times the Jacobian. The mathematical relationship is . The Loperator 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]¶ Construct an Apply node that represent the application of this operation to the given inputs.
This must be implemented by subclasses.
Returns: node – The constructed Apply node. Return type: Apply

perform
(node, inputs, outputs)[source]¶ Calculate the function on the inputs and put the variables in the output storage.
Parameters:  node (Apply) – The symbolic Apply node that represents this computation.
 inputs (Sequence) – Immutable sequence of nonsymbolic/numeric inputs. These are the values of each Variable in node.inputs.
 output_storage (list of list) – List of mutable singleelement lists (do not change the length of these lists). Each sublist corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sublists.
 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 preset values were produced by a previous call to this Op.perform; they could’ve been allocated by another Op’s perform method. A Op is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

prepare_node
(node, storage_map, compute_map, impl)[source]¶ Make any special modifications that the Op needs before doing Op.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 reprepare 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 lowertriangular (True) or uppertriangular (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 Loperator.
This method is primarily used by Lop and dispatches to Op.grad by default.
The Loperator computes a row vector times the Jacobian. The mathematical relationship is . The Loperator 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]¶ Construct an Apply node that represent the application of this operation to the given inputs.
This must be implemented by subclasses.
Returns: node – The constructed Apply node. Return type: Apply

perform
(node, inputs, outputs)[source]¶ Calculate the function on the inputs and put the variables in the output storage.
Parameters:  node (Apply) – The symbolic Apply node that represents this computation.
 inputs (Sequence) – Immutable sequence of nonsymbolic/numeric inputs. These are the values of each Variable in node.inputs.
 output_storage (list of list) – List of mutable singleelement lists (do not change the length of these lists). Each sublist corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sublists.
 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 preset values were produced by a previous call to this Op.perform; they could’ve been allocated by another Op’s perform method. A Op is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

prepare_node
(node, storage_map, compute_map, impl)[source]¶ Make any special modifications that the Op needs before doing Op.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 reprepare 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 Loperator.
This method is primarily used by Lop and dispatches to Op.grad by default.
The Loperator computes a row vector times the Jacobian. The mathematical relationship is . The Loperator 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]¶ Construct an Apply node that represent the application of this operation to the given inputs.
This must be implemented by subclasses.
Returns: node – The constructed Apply node. Return type: Apply

perform
(node, inputs, outputs)[source]¶ Calculate the function on the inputs and put the variables in the output storage.
Parameters:  node (Apply) – The symbolic Apply node that represents this computation.
 inputs (Sequence) – Immutable sequence of nonsymbolic/numeric inputs. These are the values of each Variable in node.inputs.
 output_storage (list of list) – List of mutable singleelement lists (do not change the length of these lists). Each sublist corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sublists.
 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 preset values were produced by a previous call to this Op.perform; they could’ve been allocated by another Op’s perform method. A Op is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

prepare_node
(node, storage_map, compute_map, impl)[source]¶ Make any special modifications that the Op needs before doing Op.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 reprepare the node when it isn’t good to do so.


class
theano.gpuarray.linalg.
GpuMagmaBase
(func_files: Union[str, List[str]], func_name: Optional[str] = None)[source]¶ Base class for magma related operations. Add the necessary headers, libraries and optionally the location of headers and library.

c_header_dirs
(**kwargs)[source]¶ Return a list of header search paths required by code returned by this class.
Provides search paths for headers, in addition to those in any relevant environment variables.
Note: for Unix compilers, these are the things that get I prefixed in the compiler command line arguments.
Examples
 def c_header_dirs(self, **kwargs):
 return [‘/usr/local/include’, ‘/opt/weirdpath/src/include’]

c_headers
(**kwargs)[source]¶ Return a list of header files required by code returned by this class.
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 doublequotes.Examples
 def c_headers(self, **kwargs):
 return [‘<iostream>’, ‘<math.h>’, ‘/full/path/to/header.h’]

c_lib_dirs
(**kwargs)[source]¶ Return a list of library search paths required by code returned by this class.
Provides search paths for libraries, in addition to those in any relevant environment variables (e.g.
LD_LIBRARY_PATH
).Note: for Unix compilers, these are the things that get
L
prefixed in the compiler command line arguments.Examples
 def c_lib_dirs(self, **kwargs):
 return [‘/usr/local/lib’, ‘/opt/weirdpath/build/libs’].

c_libraries
(**kwargs)[source]¶ Return a list of libraries required by code returned by this class.
The compiler will search the directories specified by the environment variable LD_LIBRARY_PATH in addition to any returned by c_lib_dirs.
Note: for Unix compilers, these are the things that get
l
prefixed in the compiler command line arguments.Examples
 def c_libraries(self, **kwargs):
 return [‘gsl’, ‘gslcblas’, ‘m’, ‘fftw3’, ‘g2c’].

prepare_node
(node, storage_map, compute_map, impl)[source]¶ Make any special modifications that the Op needs before doing Op.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 reprepare 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 using magma library.

class
theano.gpuarray.linalg.
GpuMagmaEigh
(UPLO='L', compute_v=True)[source]¶ Computes the eigen decomposition of a symmetric matrix 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.

class
theano.gpuarray.linalg.
GpuMagmaMatrixInverse
(inplace=False)[source]¶ Computes the inverse of a matrix using magma library.

class
theano.gpuarray.linalg.
GpuMagmaQR
(complete=True)[source]¶ Computes the qr decomposition of a matrix using magma library.
Parameters: complete (If False, returns only R
.) –Warning
Because of implementation constraints, this Op returns outputs in order
R, Q
. Usetheano.gpuarray.linalg.gpu_qr()
to get them in expected orderQ, R
.

class
theano.gpuarray.linalg.
GpuMagmaSVD
(full_matrices=True, compute_uv=True)[source]¶ Computes the svd of a matrix using magma library.
Warning
Because of implementation constraints, this Op returns outputs in order
S, U, VT
. Usetheano.gpuarray.linalg.gpu_svd()
to get them in expected orderU, S, VT
.
get_params
(node)[source]¶ Try to detect params from the op if Op.params_type is set to a ParamsType.

make_node
(A)[source]¶ Construct an Apply node that represent the application of this operation to the given inputs.
This must be implemented by subclasses.
Returns: node – The constructed Apply node. Return type: Apply

prepare_node
(node, storage_map, compute_map, impl)[source]¶ Make any special modifications that the Op needs before doing Op.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 reprepare 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