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.

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 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.

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.

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 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.

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.

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 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.

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