slepc4py.SLEPc.SVD#
- class slepc4py.SLEPc.SVD#
Bases:
Object
SVD.
Enumerations
SVD convergence test.
SVD convergence reasons.
SVD error type to assess accuracy of computed solutions.
SVD problem type.
SVD stopping test.
SVD TRLanczos bidiagonalization choices for the GSVD case.
SVD types.
SVD desired part of spectrum.
Methods Summary
appendOptionsPrefix
([prefix])Append to the prefix used for searching for all SVD options in the database.
Clear all monitors for an
SVD
object.computeError
(i[, etype])Compute the error associated with the i-th singular triplet.
create
([comm])Create the SVD object.
destroy
()Destroy the SVD object.
errorView
([etype, viewer])Display the errors associated with the computed solution.
getBV
()Get the basis vectors objects associated to the SVD object.
Get the number of converged singular triplets.
Get the reason why the
solve()
iteration was stopped.Get the method used to compute the error estimate used in the convergence test.
Get the eigensolver object associated to the singular value solver.
Get the flag indicating if
A^T*A
is built explicitly.Get the eigensolver object associated to the singular value solver.
Get the flag indicating if \(H(A)\) is built explicitly.
getDS
()Get the direct solver associated to the singular value solver.
Get the number of singular values to compute and the dimension of the subspace.
Get the mode used to handle the transpose of the matrix associated.
Get the current iteration number.
Get if the variant of the Lanczos method to be used is one-sided or two-sided.
Get the list of monitor functions.
Get the matrices associated with the singular value problem.
Get the prefix used for searching for all SVD options in the database.
Get the problem type from the SVD object.
getSignature
([omega])Get the signature matrix defining a hyperbolic singular value problem.
getSingularTriplet
(i[, U, V])Get the i-th triplet of the singular value decomposition.
Get the stopping function.
Get the flag indicating if \(Z=[A;B]\) is built explicitly.
Get bidiagonalization choice used in the GSVD TRLanczos solver.
Get the linear solver object associated with the SVD solver.
Get the locking flag used in the thick-restart Lanczos method.
Get if the variant of the method to be used is one-sided or two-sided.
Get the restart parameter used in the thick-restart Lanczos method.
Get the threshold used in the threshold stopping test.
Get the tolerance and maximum iteration count.
Get the flag indicating if all residual norms must be computed or not.
getType
()Get the SVD type of this object.
getValue
(i)Get the i-th singular value as computed by
solve()
.getVectors
(i, U, V)Get the i-th left and right singular vectors as computed by
solve()
.Get which singular triplets are to be sought.
Tell if the SVD corresponds to a generalized singular value problem.
Tell whether the SVD object corresponds to a hyperbolic singular value problem.
reset
()Reset the SVD object.
setBV
(V[, U])Set basis vectors objects associated to the SVD solver.
setConvergenceTest
(conv)Set how to compute the error estimate used in the convergence test.
setCrossEPS
(eps)Set an eigensolver object associated to the singular value solver.
setCrossExplicitMatrix
([flag])Set if the eigensolver operator \(A^T A\) must be computed.
setCyclicEPS
(eps)Set an eigensolver object associated to the singular value solver.
setCyclicExplicitMatrix
([flag])Set if the eigensolver operator
H(A)
must be computed explicitly.setDS
(ds)Set a direct solver object associated to the singular value solver.
setDimensions
([nsv, ncv, mpd])Set the number of singular values to compute and the dimension of the subspace.
Set SVD options from the options database.
setImplicitTranspose
(mode)Set how to handle the transpose of the matrix associated.
setInitialSpace
([spaceright, spaceleft])Set the initial spaces from which the SVD solver starts to iterate.
setLanczosOneSide
([flag])Set if the variant of the Lanczos method to be used is one-sided or two-sided.
setMonitor
(monitor[, args, kargs])Append a monitor function to the list of monitors.
setOperators
(A[, B])Set the matrices associated with the singular value problem.
setOptionsPrefix
([prefix])Set the prefix used for searching for all SVD options in the database.
setProblemType
(problem_type)Set the type of the singular value problem.
setSignature
([omega])Set the signature matrix defining a hyperbolic singular value problem.
setStoppingTest
(stopping[, args, kargs])Set a function to decide when to stop the outer iteration of the eigensolver.
setTRLanczosExplicitMatrix
([flag])Set if the matrix \(Z=[A;B]\) must be built explicitly.
setTRLanczosGBidiag
(bidiag)Set the bidiagonalization choice to use in the GSVD TRLanczos solver.
setTRLanczosKSP
(ksp)Set a linear solver object associated to the SVD solver.
setTRLanczosLocking
(lock)Toggle between locking and non-locking variants of the method.
setTRLanczosOneSide
([flag])Set if the variant of the method to be used is one-sided or two-sided.
setTRLanczosRestart
(keep)Set the restart parameter for the thick-restart Lanczos method.
setThreshold
(thres[, rel])Set the threshold used in the threshold stopping test.
setTolerances
([tol, max_it])Set the tolerance and maximum iteration count used.
setTrackAll
(trackall)Set flag to compute the residual of all singular triplets.
setType
(svd_type)Set the particular solver to be used in the SVD object.
setUp
()Set up all the necessary internal data structures.
setWhichSingularTriplets
(which)Set which singular triplets are to be sought.
solve
()Solve the singular value problem.
valuesView
([viewer])Display the computed singular values in a viewer.
vectorsView
([viewer])Output computed singular vectors to a viewer.
view
([viewer])Print the SVD data structure.
Attributes Summary
The direct solver (DS) object associated.
The maximum iteration count.
The type of the eigenvalue problem.
The tolerance.
Compute the residual norm of all approximate eigenpairs.
How to handle the transpose of the matrix.
The portion of the spectrum to be sought.
Methods Documentation
- appendOptionsPrefix(prefix=None)#
Append to the prefix used for searching for all SVD options in the database.
Logically collective.
- cancelMonitor()#
Clear all monitors for an
SVD
object.Logically collective.
Source code at slepc4py/SLEPc/SVD.pyx:912
- Return type:
- computeError(i, etype=None)#
Compute the error associated with the i-th singular triplet.
Collective.
Compute the error (based on the residual norm) associated with the i-th singular triplet.
- Parameters:
- Returns:
The relative error bound, computed in various ways from the residual norm \(\sqrt{n_1^2+n_2^2}\) where \(n_1 = \|A v - \sigma u\|_2\), \(n_2 = \|A^T u - \sigma v\|_2\), \(\sigma\) is the singular value, \(u\) and \(v\) are the left and right singular vectors.
- Return type:
Notes
The index
i
should be a value between0
andnconv-1
(seegetConverged()
).
- create(comm=None)#
Create the SVD object.
Collective.
- destroy()#
Destroy the SVD object.
Collective.
Source code at slepc4py/SLEPc/SVD.pyx:168
- Return type:
- errorView(etype=None, viewer=None)#
Display the errors associated with the computed solution.
Collective.
Display the errors and the eigenvalues.
- Parameters:
viewer (petsc4py.PETSc.Viewer | None) – Visualization context; if not provided, the standard output is used.
- Return type:
Notes
By default, this function checks the error of all eigenpairs and prints the eigenvalues if all of them are below the requested tolerance. If the viewer has format
ASCII_INFO_DETAIL
then a table with eigenvalues and corresponding errors is printed.
- getBV()#
Get the basis vectors objects associated to the SVD object.
Not collective.
- Returns:
- Return type:
- getConverged()#
Get the number of converged singular triplets.
Not collective.
- Returns:
Number of converged singular triplets.
- Return type:
Notes
This function should be called after
solve()
has finished.
- getConvergedReason()#
Get the reason why the
solve()
iteration was stopped.Not collective.
- Returns:
Negative value indicates diverged, positive value converged.
- Return type:
- getConvergenceTest()#
Get the method used to compute the error estimate used in the convergence test.
Not collective.
- Returns:
The method used to compute the error estimate used in the convergence test.
- Return type:
- getCrossEPS()#
Get the eigensolver object associated to the singular value solver.
Collective.
- Returns:
The eigensolver object.
- Return type:
- getCrossExplicitMatrix()#
Get the flag indicating if
A^T*A
is built explicitly.Not collective.
- Returns:
True if
A^T*A
is built explicitly.- Return type:
- getCyclicEPS()#
Get the eigensolver object associated to the singular value solver.
Collective.
- Returns:
The eigensolver object.
- Return type:
- getCyclicExplicitMatrix()#
Get the flag indicating if \(H(A)\) is built explicitly.
Not collective.
Get the flag indicating if \(H(A) = [ 0\; A ; A^T\; 0 ]\) is built explicitly.
- Returns:
True if \(H(A)\) is built explicitly.
- Return type:
- getDS()#
Get the direct solver associated to the singular value solver.
Not collective.
- Returns:
The direct solver context.
- Return type:
- getDimensions()#
Get the number of singular values to compute and the dimension of the subspace.
Not collective.
- Returns:
- Return type:
- getImplicitTranspose()#
Get the mode used to handle the transpose of the matrix associated.
Not collective.
Get the mode used to handle the transpose of the matrix associated with the singular value problem.
- Returns:
How to handle the transpose (implicitly or not).
- Return type:
- getIterationNumber()#
Get the current iteration number.
Not collective.
If the call to
solve()
is complete, then it returns the number of iterations carried out by the solution method.- Returns:
Iteration number.
- Return type:
- getLanczosOneSide()#
Get if the variant of the Lanczos method to be used is one-sided or two-sided.
Not collective.
- Returns:
True if the method is one-sided.
- Return type:
- getMonitor()#
Get the list of monitor functions.
Source code at slepc4py/SLEPc/SVD.pyx:908
- Return type:
- getOperators()#
Get the matrices associated with the singular value problem.
Collective.
- Returns:
A (
petsc4py.PETSc.Mat
) – The matrix associated with the singular value problem.B (
petsc4py.PETSc.Mat
) – The second matrix in the case of GSVD.
- Return type:
tuple[petsc4py.PETSc.Mat, petsc4py.PETSc.Mat] | tuple[petsc4py.PETSc.Mat, None]
- getOptionsPrefix()#
Get the prefix used for searching for all SVD options in the database.
Not collective.
- Returns:
The prefix string set for this SVD object.
- Return type:
- getProblemType()#
Get the problem type from the SVD object.
Not collective.
- Returns:
The problem type that was previously set.
- Return type:
- getSignature(omega=None)#
Get the signature matrix defining a hyperbolic singular value problem.
Collective.
- Parameters:
omega (petsc4py.PETSc.Vec | None) – Optional vector to store the diagonal elements of the signature matrix.
- Returns:
A vector containing the diagonal elements of the signature matrix.
- Return type:
- getSingularTriplet(i, U=None, V=None)#
Get the i-th triplet of the singular value decomposition.
Collective.
Get the i-th triplet of the singular value decomposition as computed by
solve()
. The solution consists of the singular value and its left and right singular vectors.- Parameters:
- Returns:
The computed singular value.
- Return type:
Notes
The index
i
should be a value between0
andnconv-1
(seegetConverged()
. Singular triplets are indexed according to the ordering criterion established withsetWhichSingularTriplets()
.
- getStoppingTest()#
Get the stopping function.
Not collective.
Source code at slepc4py/SLEPc/SVD.pyx:877
- Return type:
- getTRLanczosExplicitMatrix()#
Get the flag indicating if \(Z=[A;B]\) is built explicitly.
Not collective.
- Returns:
True if \(Z=[A;B]\) is built explicitly.
- Return type:
- getTRLanczosGBidiag()#
Get bidiagonalization choice used in the GSVD TRLanczos solver.
Not collective.
- Returns:
The bidiagonalization choice.
- Return type:
- getTRLanczosKSP()#
Get the linear solver object associated with the SVD solver.
Collective.
- Returns:
The linear solver object.
- Return type:
- getTRLanczosLocking()#
Get the locking flag used in the thick-restart Lanczos method.
Not collective.
- Returns:
The locking flag.
- Return type:
- getTRLanczosOneSide()#
Get if the variant of the method to be used is one-sided or two-sided.
Not collective.
Get if the variant of the thick-restart Lanczos method to be used is one-sided or two-sided.
- Returns:
True if the method is one-sided.
- Return type:
- getTRLanczosRestart()#
Get the restart parameter used in the thick-restart Lanczos method.
Not collective.
- Returns:
The number of vectors to be kept at restart.
- Return type:
- getThreshold()#
Get the threshold used in the threshold stopping test.
Not collective.
- Returns:
- Return type:
- getTolerances()#
Get the tolerance and maximum iteration count.
Not collective.
Get the tolerance and maximum iteration count used by the default SVD convergence tests.
- Returns:
- Return type:
- getTrackAll()#
Get the flag indicating if all residual norms must be computed or not.
Not collective.
- Returns:
Whether the solver compute all residuals or not.
- Return type:
- getType()#
Get the SVD type of this object.
Not collective.
- Returns:
The solver currently being used.
- Return type:
- getValue(i)#
Get the i-th singular value as computed by
solve()
.Collective.
- Parameters:
i (int) – Index of the solution to be obtained.
- Returns:
The computed singular value.
- Return type:
Notes
The index
i
should be a value between0
andnconv-1
(seegetConverged()
. Singular triplets are indexed according to the ordering criterion established withsetWhichSingularTriplets()
.
- getVectors(i, U, V)#
Get the i-th left and right singular vectors as computed by
solve()
.Collective.
- Parameters:
- Return type:
Notes
The index
i
should be a value between0
andnconv-1
(seegetConverged()
. Singular triplets are indexed according to the ordering criterion established withsetWhichSingularTriplets()
.
- getWhichSingularTriplets()#
Get which singular triplets are to be sought.
Not collective.
- Returns:
The singular values to be sought (either largest or smallest).
- Return type:
- isGeneralized()#
Tell if the SVD corresponds to a generalized singular value problem.
Not collective.
Tell whether the SVD object corresponds to a generalized singular value problem.
- Returns:
True if two matrices were set with
setOperators()
.- Return type:
- isHyperbolic()#
Tell whether the SVD object corresponds to a hyperbolic singular value problem.
Not collective.
- Returns:
True if the problem was specified as hyperbolic.
- Return type:
- reset()#
Reset the SVD object.
Collective.
Source code at slepc4py/SLEPc/SVD.pyx:178
- Return type:
- setBV(V, U=None)#
Set basis vectors objects associated to the SVD solver.
Collective.
- Parameters:
- Return type:
- setConvergenceTest(conv)#
Set how to compute the error estimate used in the convergence test.
Logically collective.
- Parameters:
conv (Conv) – The method used to compute the error estimate used in the convergence test.
- Return type:
- setCrossEPS(eps)#
Set an eigensolver object associated to the singular value solver.
Collective.
- setCrossExplicitMatrix(flag=True)#
Set if the eigensolver operator \(A^T A\) must be computed.
Logically collective.
- setCyclicEPS(eps)#
Set an eigensolver object associated to the singular value solver.
Collective.
- setCyclicExplicitMatrix(flag=True)#
Set if the eigensolver operator
H(A)
must be computed explicitly.Logically collective.
Set if the eigensolver operator \(H(A) = [ 0\; A ; A^T\; 0 ]\) must be computed explicitly.
- setDS(ds)#
Set a direct solver object associated to the singular value solver.
Collective.
- setDimensions(nsv=None, ncv=None, mpd=None)#
Set the number of singular values to compute and the dimension of the subspace.
Logically collective.
- Parameters:
- Return type:
Notes
Use
DECIDE
forncv
andmpd
to assign a reasonably good value, which is dependent on the solution method.The parameters
ncv
andmpd
are intimately related, so that the user is advised to set one of them at most. Normal usage is the following:In cases where
nsv
is small, the user setsncv
(a reasonable default is 2 *nsv
).In cases where
nsv
is large, the user setsmpd
.
The value of
ncv
should always be betweennsv
and (nsv
+mpd
), typicallyncv
=nsv
+mpd
. Ifnsv
is not too large,mpd
=nsv
is a reasonable choice, otherwise a smaller value should be used.
- setFromOptions()#
Set SVD options from the options database.
Collective.
This routine must be called before
setUp()
if the user is to be allowed to set the solver type.Notes
To see all options, run your program with the
-help
option.Source code at slepc4py/SLEPc/SVD.pyx:299
- Return type:
- setImplicitTranspose(mode)#
Set how to handle the transpose of the matrix associated.
Logically collective.
Set how to handle the transpose of the matrix associated with the singular value problem.
Notes
By default, the transpose of the matrix is explicitly built (if the matrix has defined the MatTranspose operation).
If this flag is set to true, the solver does not build the transpose, but handles it implicitly via MatMultTranspose().
- setInitialSpace(spaceright=None, spaceleft=None)#
Set the initial spaces from which the SVD solver starts to iterate.
Collective.
- Parameters:
- Return type:
- setLanczosOneSide(flag=True)#
Set if the variant of the Lanczos method to be used is one-sided or two-sided.
Logically collective.
Notes
By default, a two-sided variant is selected, which is sometimes slightly more robust. However, the one-sided variant is faster because it avoids the orthogonalization associated to left singular vectors. It also saves the memory required for storing such vectors.
- setMonitor(monitor, args=None, kargs=None)#
Append a monitor function to the list of monitors.
Logically collective.
- setOperators(A, B=None)#
Set the matrices associated with the singular value problem.
Collective.
- Parameters:
- Return type:
- setOptionsPrefix(prefix=None)#
Set the prefix used for searching for all SVD options in the database.
Logically collective.
- Parameters:
prefix (str | None) – The prefix string to prepend to all SVD option requests.
- Return type:
Notes
A hyphen (-) must NOT be given at the beginning of the prefix name. The first character of all runtime options is AUTOMATICALLY the hyphen.
For example, to distinguish between the runtime options for two different SVD contexts, one could call:
S1.setOptionsPrefix("svd1_") S2.setOptionsPrefix("svd2_")
- setProblemType(problem_type)#
Set the type of the singular value problem.
Logically collective.
- Parameters:
problem_type (ProblemType) – The problem type to be set.
- Return type:
- setSignature(omega=None)#
Set the signature matrix defining a hyperbolic singular value problem.
Collective.
- setStoppingTest(stopping, args=None, kargs=None)#
Set a function to decide when to stop the outer iteration of the eigensolver.
Logically collective.
- setTRLanczosExplicitMatrix(flag=True)#
Set if the matrix \(Z=[A;B]\) must be built explicitly.
Logically collective.
- setTRLanczosGBidiag(bidiag)#
Set the bidiagonalization choice to use in the GSVD TRLanczos solver.
Logically collective.
- Parameters:
bidiag (TRLanczosGBidiag) – The bidiagonalization choice.
- Return type:
- setTRLanczosKSP(ksp)#
Set a linear solver object associated to the SVD solver.
Collective.
- Parameters:
ksp (petsc4py.PETSc.KSP) – The linear solver object.
- Return type:
- setTRLanczosLocking(lock)#
Toggle between locking and non-locking variants of the method.
Logically collective.
Toggle between locking and non-locking variants of the thick-restart Lanczos method.
Notes
The default is to lock converged singular triplets when the method restarts. This behaviour can be changed so that all directions are kept in the working subspace even if already converged to working accuracy (the non-locking variant).
- setTRLanczosOneSide(flag=True)#
Set if the variant of the method to be used is one-sided or two-sided.
Logically collective.
Set if the variant of the thick-restart Lanczos method to be used is one-sided or two-sided.
Notes
By default, a two-sided variant is selected, which is sometimes slightly more robust. However, the one-sided variant is faster because it avoids the orthogonalization associated to left singular vectors.
- setTRLanczosRestart(keep)#
Set the restart parameter for the thick-restart Lanczos method.
Logically collective.
Set the restart parameter for the thick-restart Lanczos method, in particular the proportion of basis vectors that must be kept after restart.
Notes
Allowed values are in the range [0.1,0.9]. The default is 0.5.
- setThreshold(thres, rel=False)#
Set the threshold used in the threshold stopping test.
Logically collective.
- Parameters:
- Return type:
Notes
This function internally sets a special stopping test based on the threshold, where singular values are computed in sequence until one of the computed singular values is below/above the threshold (depending on whether largest or smallest singular values are computed).
In the case of largest singular values, the threshold can be made relative with respect to the largest singular value (i.e., the matrix norm).
- setTolerances(tol=None, max_it=None)#
Set the tolerance and maximum iteration count used.
Logically collective.
Set the tolerance and maximum iteration count used by the default SVD convergence tests.
- Parameters:
- Return type:
Notes
Use
DECIDE
formax_it
to assign a reasonably good value, which is dependent on the solution method.
- setTrackAll(trackall)#
Set flag to compute the residual of all singular triplets.
Logically collective.
Set if the solver must compute the residual of all approximate singular triplets or not.
- setType(svd_type)#
Set the particular solver to be used in the SVD object.
Logically collective.
Notes
See
SVD.Type
for available methods. The default is CROSS. Normally, it is best to usesetFromOptions()
and then set the SVD type from the options database rather than by using this routine. Using the options database provides the user with maximum flexibility in evaluating the different available methods.
- setUp()#
Set up all the necessary internal data structures.
Collective.
Set up all the internal data structures necessary for the execution of the singular value solver.
Notes
This function need not be called explicitly in most cases, since
solve()
calls it. It can be useful when one wants to measure the set-up time separately from the solve time.Source code at slepc4py/SLEPc/SVD.pyx:923
- Return type:
- setWhichSingularTriplets(which)#
Set which singular triplets are to be sought.
Logically collective.
- Parameters:
which (Which) – The singular values to be sought (either largest or smallest).
- Return type:
- solve()#
Solve the singular value problem.
Collective.
Source code at slepc4py/SLEPc/SVD.pyx:940
- Return type:
- valuesView(viewer=None)#
Display the computed singular values in a viewer.
Collective.
- vectorsView(viewer=None)#
Output computed singular vectors to a viewer.
Collective.
- view(viewer=None)#
Print the SVD data structure.
Collective.
Attributes Documentation
- ds#
The direct solver (DS) object associated.
- max_it#
The maximum iteration count.
- problem_type#
The type of the eigenvalue problem.
- tol#
The tolerance.
- track_all#
Compute the residual norm of all approximate eigenpairs.
- transpose_mode#
How to handle the transpose of the matrix.
- which#
The portion of the spectrum to be sought.