comparison util/SMALL_solve.m @ 8:33850553b702

(none)
author idamnjanovic
date Mon, 22 Mar 2010 10:56:54 +0000
parents 7750624e0c73
children bcc748594b61
comparison
equal deleted inserted replaced
7:0151f1ea080d 8:33850553b702
1 function SMALL = SMALL_solve(SMALL) 1 function solver = SMALL_solve(Problem, solver)
2 % Ivan Damnjanovic 2009 2 %%% SMALL sparse solver
3 % Function gets as input SMALL structure that contains SPARCO problem to 3 % Ivan Damnjanovic 2009
4 % be solved, name of the toolbox and solver, and parameters file for particular solver 4 % Function gets as input SMALL structure that contains SPARCO problem to
5 % Outputs are solution, reconstructed signal and time spent 5 % be solved, name of the toolbox and solver, and parameters file for
6 %% 6 % particular solver.
7 7 %
8 A = @(x) SMALL.Problem.A(x,1); % The operator 8 % Outputs are solution, reconstructed signal and time spent
9 AT = @(y) SMALL.Problem.A(y,2); % and its transpose. 9 %%
10 b = SMALL.Problem.b; % The right-hand-side vector. 10
11 m = SMALL.Problem.sizeA(1); % m is the no. of rows. 11 if isa(Problem.A,'float')
12 n = SMALL.Problem.sizeA(2); % n is the no. of columns. 12 A = Problem.A;
13 13 SparseLab_A=Problem.A;
14 fprintf('\nStarting solver %s... \n', SMALL.solver.name); 14 m = size(Problem.A,1); % m is the no. of rows.
15 start=cputime; 15 n = size(Problem.A,2); % n is the no. of columns.
16 %% 16 else
17 if strcmpi(SMALL.solver.toolbox,'sparselab') 17 A = @(x) Problem.A(x,1); % The operator
18 y = eval([SMALL.solver.name,'(''SL_A'', b, n,',SMALL.solver.param,');']); 18 AT = @(y) Problem.A(y,2); % and its transpose.
19 elseif strcmpi(SMALL.solver.toolbox,'sparsify') 19 SparseLab_A =@(mode, m, n, x, I, dim) SL_A(Problem.A, mode, m, n, x, I, dim);
20 y = eval([SMALL.solver.name,'(b, A, n, ''P_trans'', AT,',SMALL.solver.param,');']); 20 m = Problem.sizeA(1); % m is the no. of rows.
21 elseif (strcmpi(SMALL.solver.toolbox,'spgl1')||strcmpi(SMALL.solver.toolbox,'gpsr')) 21 n = Problem.sizeA(2); % n is the no. of columns.
22 y = eval([SMALL.solver.name,'(b, A,',SMALL.solver.param,');']); 22
23 else
24 y = eval([SMALL.solver.name,'(A, b, n,',SMALL.solver.param,',AT);']);
25 end
26 %%
27 SMALL.solver.time = cputime - start;
28 fprintf('Solver %s finished task in %2f seconds. \n', SMALL.solver.name, SMALL.solver.time);
29 SMALL.solver.solution = full(y);
30 SMALL.solver.reconstructed = SMALL.Problem.reconstruct(SMALL.solver.solution);
31 end 23 end
32 24 b = Problem.b; % The right-hand-side vector.
25 %%
26 fprintf('\nStarting solver %s... \n', solver.name);
27 start=cputime;
28
29 if strcmpi(solver.toolbox,'sparselab')
30 y = eval([solver.name,'(SparseLab_A, b, n,',solver.param,');']);
31 elseif strcmpi(solver.toolbox,'sparsify')
32 y = eval([solver.name,'(b, A, n, ''P_trans'', AT,',solver.param,');']);
33 elseif (strcmpi(solver.toolbox,'spgl1')||strcmpi(solver.toolbox,'gpsr'))
34 y = eval([solver.name,'(b, A,',solver.param,');']);
35 elseif (strcmpi(solver.toolbox,'SPAMS'))
36 y = eval([solver.name,'(b, A, solver.param);']);
37 elseif (strcmpi(solver.toolbox,'SMALL'))
38 if isa(Problem.A,'float')
39 y = eval([solver.name,'(A, b, n,',solver.param,');']);
40 else
41 y = eval([solver.name,'(A, b, n,',solver.param,',AT);']);
42 end
43
44 % To introduce new sparse representation algorithm put the files in
45 % your Matlab path. Next, unique name <TolboxID> for your toolbox and
46 % prefferd API <Preffered_API> needs to be defined.
47 %
48 % elseif strcmpi(solver.toolbox,'<ToolboxID>')
49 %
50 % % - Evaluate the function (solver.name - defined in the main) with
51 % % parameters given above
52 %
53 % y = eval([solver.name,'(<Preffered_API>);']);
54
55 else
56 printf('\nToolbox has not been registered. Please change SMALL_solver file.\n');
57 return
58 end
59
60 %%
61 % Sparse representation time
62
63 solver.time = cputime - start;
64 fprintf('Solver %s finished task in %2f seconds. \n', solver.name, solver.time);
65
66 % geting around out of memory problem when converting big matrix from
67 % sparse to full...
68
69 if (Problem.sparse==1)
70 solver.solution = y;
71 else
72 solver.solution = full(y);
73 end
74
75 % Reconstruct the signal from the solution
76 solver.reconstructed = Problem.reconstruct(solver.solution);
77 end