I believe the syntax of eigs() was meant to mimic MATLAB. In principle we could return a custom-purpose type as the result. Note, however, that not all fields will be populated, depending on what was requested.
> Any function that depends only on the eigenvalues and eigenvectors can take > either an Eigen or an EigsResult because they have the same field names. No, it is not sufficient to have the same field names if you truly meant to have EigsResult be a drop-in replacement for Eigen. The fields have to have the same dimensions as well. Note that eigs by default only returns 6 eigenpairs, which could confuse any code expecting to have all of them computed. Worse if you specify ritzvec=false, in which case you would get a Nx0 array of EigsResults.vectors and any code expecting the presence of eigenvectors would fail. You could insert runtime checks in all the functions you use that want to use both Eigen and EigsResults to check for all these cases, but at that point you might as well write specialized methods that use EigResults. Thanks, Jiahao Chen Staff Research Scientist MIT Computer Science and Artificial Intelligence Laboratory On Wed, Mar 4, 2015 at 8:48 AM, James Fairbanks <jpfairba...@gmail.com> wrote: > We have Base.LinAlg.eig return a tuple of (values,vectors) and > Base.LinAlg.eigfact returns a type for the result Base.LinAlg.Eigen. But > Base.LinAlg.eigs returns a tuple would it be worth having a variant of eigs > that returns a type such as EigsResult? > > @doc """a type for the output of eigs > > > "eigs" returns the "nev" requested eigenvalues in "d", the > corresponding Ritz vectors "v" (only if "ritzvec=true"), the > number of converged eigenvalues "nconv", the number of iterations > "niter" and the number of matrix vector multiplications > "nmult", as well as the final residual vector "resid". > > > """ -> > type EigsResult{T, R} > values::Array{T,1} > vectors::Array{T,2} > nconv::Int64 > niter::Int64 > nmult::Int64 > resid::Array{R,1} > end > > > function EigsResult(A; args...) > @show args > tupl = eigs(A; args...) > T = eltype(tupl[1]) > R = eltype(tupl[end]) > EigsResult{T,R}(tupl...) > end > > Any function that depends only on the eigenvalues and eigenvectors can take > either an Eigen or an EigsResult because they have the same field names. > > James Fairbanks