Skip to content
Snippets Groups Projects

Add the `return_eigenvectors` parameter to the call of `operator_spectrum`

Merged Andrija Kostic requested to merge patch-1 into NIFTy_7
1 file
+ 16
3
Compare changes
  • Side-by-side
  • Inline
+ 16
3
@@ -83,7 +83,7 @@ class _DomRemover(LinearOperator):
@@ -83,7 +83,7 @@ class _DomRemover(LinearOperator):
raise TypeError('Operator supports only floating point dtypes')
raise TypeError('Operator supports only floating point dtypes')
def operator_spectrum(A, k, hermitian, which='LM', tol=0):
def operator_spectrum(A, k, hermitian, which='LM', tol=0, return_eigenvectors=False):
'''
'''
Find k eigenvalues and eigenvectors of the endomorphism A.
Find k eigenvalues and eigenvectors of the endomorphism A.
@@ -116,11 +116,19 @@ def operator_spectrum(A, k, hermitian, which='LM', tol=0):
@@ -116,11 +116,19 @@ def operator_spectrum(A, k, hermitian, which='LM', tol=0):
Relative accuracy for eigenvalues (stopping criterion)
Relative accuracy for eigenvalues (stopping criterion)
The default value of 0 implies machine precision.
The default value of 0 implies machine precision.
 
return_eigenvectors: bool, optional
 
Return eigenvectors (True) in addition to eigenvalues
 
 
Returns
Returns
-------
-------
w : ndarray
w : ndarray
Array of k eigenvalues.
Array of k eigenvalues.
 
v : ndarray
 
An array representing the k eigenvectors. The column v[:, i] is the
 
eigenvector corresponding to the eigenvalue w[i].
 
Raises
Raises
------
------
ArpackNoConvergence
ArpackNoConvergence
@@ -139,5 +147,10 @@ def operator_spectrum(A, k, hermitian, which='LM', tol=0):
@@ -139,5 +147,10 @@ def operator_spectrum(A, k, hermitian, which='LM', tol=0):
shape=2*(size,),
shape=2*(size,),
matvec=lambda x: Ar(makeField(Ar.domain, x)).val)
matvec=lambda x: Ar(makeField(Ar.domain, x)).val)
f = ssl.eigsh if hermitian else ssl.eigs
f = ssl.eigsh if hermitian else ssl.eigs
eigs = f(M, k=k, tol=tol, return_eigenvectors=False, which=which)
eigs = f(M, k=k, tol=tol, return_eigenvectors=return_eigenvectors, which=which)
return np.flip(np.sort(eigs), axis=0)
if return_eigenvectors:
 
eigval, eigvec = eigs
 
inds = np.argsort(eigval)
 
return np.flip(eigval[inds]), np.flip(eigvec[:,inds],axis = 1)
 
else:
 
return np.flip(np.sort(eigs))
Loading