Home > tt2 > solve > tt_iterapp.m

tt_iterapp

PURPOSE ^

Apply TT matrix operator to TT vector and error gracefully.

SYNOPSIS ^

function y = tt_iterapp(op,afun,atype,afcnstr,x,eps,max_rank,max_swp,varargin)

DESCRIPTION ^

Apply TT matrix operator to TT vector and error gracefully.
   TT_ITERAPP(OP,AFUN,ATYPE,AFCNSTR,X) applies matrix operator AFUN to vector
   X. If ATYPE is 'matrix, then AFUN is a matrix and the OP is applied
   directly. OP is either 'mtimes' or 'mldivide'.
   ATYPE and AFCNSTR are used in case of error.
   ITERAPP(OP,AFUN,ATYPE,AFCNSTR,X,P1,P2,...) allows extra arguments to
   AFUN(X,P1,P2,...) although this usage is now discouraged in favor of
   using anonymous functions.
   AFUN(X,P1,P2,...,PN,TFLAG) should accept a TFLAG as its final input if
   the calling function is BICG, LSQR or QMR. TFLAG is either 'transp' or
   'notransp' depending on whether A' OP X or A OP X is required.
   ITERAPP is designed for use by iterative methods like PCG which
   require matrix operators AFUN representing matrices A to operate on
   vectors X and return A*X and may also have operators MFUN representing
   preconditioning matrices M operate on vectors X and return M\X.

   See also BICG, BICGSTAB, CGS, GMRES, LSQR, MINRES, PCG, QMR, SYMMLQ.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function y = tt_iterapp(op,afun,atype,afcnstr,x,eps,max_rank,max_swp,varargin)
0002 %Apply TT matrix operator to TT vector and error gracefully.
0003 %   TT_ITERAPP(OP,AFUN,ATYPE,AFCNSTR,X) applies matrix operator AFUN to vector
0004 %   X. If ATYPE is 'matrix, then AFUN is a matrix and the OP is applied
0005 %   directly. OP is either 'mtimes' or 'mldivide'.
0006 %   ATYPE and AFCNSTR are used in case of error.
0007 %   ITERAPP(OP,AFUN,ATYPE,AFCNSTR,X,P1,P2,...) allows extra arguments to
0008 %   AFUN(X,P1,P2,...) although this usage is now discouraged in favor of
0009 %   using anonymous functions.
0010 %   AFUN(X,P1,P2,...,PN,TFLAG) should accept a TFLAG as its final input if
0011 %   the calling function is BICG, LSQR or QMR. TFLAG is either 'transp' or
0012 %   'notransp' depending on whether A' OP X or A OP X is required.
0013 %   ITERAPP is designed for use by iterative methods like PCG which
0014 %   require matrix operators AFUN representing matrices A to operate on
0015 %   vectors X and return A*X and may also have operators MFUN representing
0016 %   preconditioning matrices M operate on vectors X and return M\X.
0017 %
0018 %   See also BICG, BICGSTAB, CGS, GMRES, LSQR, MINRES, PCG, QMR, SYMMLQ.
0019 
0020 %   Copyright 1984-2008 The MathWorks, Inc.
0021 %   $Revision: 1.7.4.4 $ $Date: 2008/06/20 08:01:27 $
0022 
0023 
0024 matvec_alg='mv+compr';   % produce matvec via tt_mv, and then tt_compr2
0025 % matvec_alg='mvk3';         % produce matvec via tt_mvk2
0026 % matvec_alg='smv+compr'; % produce matvec via SparseMatVec
0027 % matvec_alg='mv'; % Just a tt_mv (I guess we have to do a compression by ourselves)
0028 
0029 if strcmp(atype,'matrix')
0030     switch lower(op)
0031         case 'mtimes'
0032             if (strcmp(matvec_alg,'mvk3'))
0033                 y = tt_mvk3(afun, x, eps, 'rmax', max_rank, 'nswp', max_swp, 'verb', 0);                
0034             end;
0035             if (strcmp(matvec_alg,'mv+compr'))
0036                 y = tt_mv(afun, x);
0037                 y = tt_compr2(y, eps, max_rank);
0038             end;
0039             if (strcmp(matvec_alg,'smv+compr'))
0040                 y = tt_smv(afun, x);
0041                 y = tt_compr2(y, eps, max_rank);
0042             end;
0043             if (strcmp(matvec_alg,'mv'))
0044                 y = tt_mv(afun, x);
0045             end;            
0046         case 'mldivide'
0047             if (strcmp(matvec_alg,'mvk3'))
0048                 y = tt_mvk3(afun, x, eps, 'rmax', max_rank, 'nswp', max_swp);                
0049             end;
0050             if (strcmp(matvec_alg,'mv+compr'))
0051                 y = tt_mv(afun, x);
0052                 y = tt_compr2(y, eps, max_rank);
0053             end;
0054             if (strcmp(matvec_alg,'smv+compr'))
0055                 y = tt_smv(afun, x);
0056                 y = tt_compr2(y, eps, max_rank);
0057             end;
0058             if (strcmp(matvec_alg,'mv'))
0059                 y = tt_mv(afun, x);
0060             end;                        
0061         otherwise
0062             error('MATLAB:iterapp:InvalidOp', 'Invalid operation.')
0063     end
0064 else
0065     try
0066             y = afun(x,eps,max_rank,varargin{:});
0067     catch ME
0068         error('MATLAB:InvalidInput', ['user supplied %s ==> %s\n' ...
0069             'failed with the following error:\n\n%s'], ...
0070             atype,afcnstr, ME.message);
0071     end
0072 end

Generated on Wed 08-Feb-2012 18:20:24 by m2html © 2005