idamnjanovic@8: function solver = SMALL_solve(Problem, solver) idamnjanovic@8: %%% SMALL sparse solver idamnjanovic@8: % Ivan Damnjanovic 2009 idamnjanovic@8: % Function gets as input SMALL structure that contains SPARCO problem to idamnjanovic@8: % be solved, name of the toolbox and solver, and parameters file for idamnjanovic@8: % particular solver. idamnjanovic@8: % idamnjanovic@8: % Outputs are solution, reconstructed signal and time spent idamnjanovic@8: %% idamnjanovic@8: idamnjanovic@8: if isa(Problem.A,'float') idamnjanovic@8: A = Problem.A; idamnjanovic@8: SparseLab_A=Problem.A; idamnjanovic@8: m = size(Problem.A,1); % m is the no. of rows. idamnjanovic@8: n = size(Problem.A,2); % n is the no. of columns. idamnjanovic@8: else idamnjanovic@8: A = @(x) Problem.A(x,1); % The operator idamnjanovic@8: AT = @(y) Problem.A(y,2); % and its transpose. idamnjanovic@8: SparseLab_A =@(mode, m, n, x, I, dim) SL_A(Problem.A, mode, m, n, x, I, dim); idamnjanovic@8: m = Problem.sizeA(1); % m is the no. of rows. idamnjanovic@8: n = Problem.sizeA(2); % n is the no. of columns. idamnjanovic@8: idamnjanovic@1: end idamnjanovic@8: b = Problem.b; % The right-hand-side vector. idamnjanovic@8: %% idamnjanovic@8: fprintf('\nStarting solver %s... \n', solver.name); idamnjanovic@8: start=cputime; idamnjanovic@8: idamnjanovic@8: if strcmpi(solver.toolbox,'sparselab') idamnjanovic@8: y = eval([solver.name,'(SparseLab_A, b, n,',solver.param,');']); idamnjanovic@8: elseif strcmpi(solver.toolbox,'sparsify') idamnjanovic@8: y = eval([solver.name,'(b, A, n, ''P_trans'', AT,',solver.param,');']); idamnjanovic@8: elseif (strcmpi(solver.toolbox,'spgl1')||strcmpi(solver.toolbox,'gpsr')) idamnjanovic@8: y = eval([solver.name,'(b, A,',solver.param,');']); idamnjanovic@8: elseif (strcmpi(solver.toolbox,'SPAMS')) idamnjanovic@8: y = eval([solver.name,'(b, A, solver.param);']); idamnjanovic@8: elseif (strcmpi(solver.toolbox,'SMALL')) idamnjanovic@8: if isa(Problem.A,'float') idamnjanovic@8: y = eval([solver.name,'(A, b, n,',solver.param,');']); idamnjanovic@8: else idamnjanovic@8: y = eval([solver.name,'(A, b, n,',solver.param,',AT);']); idamnjanovic@8: end idamnjanovic@8: idamnjanovic@8: % To introduce new sparse representation algorithm put the files in idamnjanovic@8: % your Matlab path. Next, unique name for your toolbox and idamnjanovic@8: % prefferd API needs to be defined. idamnjanovic@8: % idamnjanovic@8: % elseif strcmpi(solver.toolbox,'') idamnjanovic@8: % idamnjanovic@8: % % - Evaluate the function (solver.name - defined in the main) with idamnjanovic@8: % % parameters given above idamnjanovic@8: % idamnjanovic@8: % y = eval([solver.name,'();']); idamnjanovic@8: idamnjanovic@8: else idamnjanovic@8: printf('\nToolbox has not been registered. Please change SMALL_solver file.\n'); idamnjanovic@8: return idamnjanovic@8: end idamnjanovic@8: idamnjanovic@8: %% idamnjanovic@8: % Sparse representation time idamnjanovic@8: idamnjanovic@8: solver.time = cputime - start; idamnjanovic@8: fprintf('Solver %s finished task in %2f seconds. \n', solver.name, solver.time); idamnjanovic@8: idamnjanovic@8: % geting around out of memory problem when converting big matrix from idamnjanovic@8: % sparse to full... idamnjanovic@8: idamnjanovic@8: if (Problem.sparse==1) idamnjanovic@8: solver.solution = y; idamnjanovic@8: else idamnjanovic@8: solver.solution = full(y); idamnjanovic@8: end idamnjanovic@8: idamnjanovic@8: % Reconstruct the signal from the solution idamnjanovic@8: solver.reconstructed = Problem.reconstruct(solver.solution); idamnjanovic@8: end