nimEigen: Spectral Decomposition of a Matrix

View source: R/distributions_implementations.R

nimEigenR Documentation

Spectral Decomposition of a Matrix


Computes eigenvalues and eigenvectors of a numeric matrix.


nimEigen(x, symmetric = FALSE, only.values = FALSE)



a numeric matrix (double or integer) whose spectral decomposition is to be computed.


if TRUE, the matrix is guarranteed to be symmetric, and only its lower triangle (diagonal included) is used. Otherwise, the matrix is checked for symmetry. Default is FALSE.


if TRUE, only the eigenvalues are computed, otherwise both eigenvalues and eigenvectors are computed. Setting only.values = TRUE can speed up eigendecompositions, especially for large matrices. Default is FALSE.


Computes the spectral decomposition of a numeric matrix using the Eigen C++ template library. In a nimbleFunction, eigen is identical to nimEigen. If the matrix is symmetric, a faster and more accurate algorithm will be used to compute the eigendecomposition. Note that non-symmetric matrices can have complex eigenvalues, which are not supported by NIMBLE. If a complex eigenvalue or a complex element of an eigenvector is detected, a warning will be issued and that element will be returned as NaN.

Additionally, returnType(eigenNimbleList()) can be used within a link{nimbleFunction} to specify that the function will return a nimbleList generated by the nimEigen function. eigenNimbleList() can also be used to define a nested nimbleList element. See the User Manual for usage examples.


The spectral decomposition of x is returned as a nimbleList with elements:

  • values vector containing the eigenvalues of x, sorted in decreasing order. Since x is required to be symmetric, all eigenvalues will be real numbers.

  • vectors. matrix with columns containing the eigenvectors of x, or an empty matrix if only.values is TRUE.


NIMBLE development team

See Also

nimSvd for singular value decompositions in NIMBLE.


eigenvaluesDemoFunction <- nimbleFunction(
   setup = function(){
     demoMatrix <- diag(4) + 2
   run = function(){
     eigenvalues <- eigen(demoMatrix, symmetric = TRUE)$values

nimble documentation built on March 18, 2022, 8:03 p.m.