forked from libprima/prima
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdv.m
90 lines (72 loc) · 2.56 KB
/
pdv.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function pdv
% PDV tests the Fortran solvers for all precision, debugging flags, and variants.
oldpath = path(); % Record the current path.
restoredefaultpath; % Restore the "right out of the box" path of MATLAB
olddir = pwd(); % Record the current directory.
matlab_implemented = {'newuoa'}; % Solvers that has a MATLAB implementation.
% Prepare the test directory, i.e., `test_dir`.
callstack = dbstack;
funname = callstack(1).name; % Name of the current function
fake_solver_name = funname;
options.compile = true;
test_dir = prepare_test_dir(fake_solver_name, funname, options);
exception = [];
try
% Go to the test directory. This is not really necessary. It will not affect the test, but any
% output (e.g., NEWUOA_output.txt, fort.6) will be dumped to `test_dir`.
cd(test_dir);
% Compile the solvers.
clear('setup');
opt=struct();
opt.single=true;
opt.quadruple=true;
opt.debug=true;
opt.classical=true;
tic
setup(opt);
testprima
toc
solvers = {'cobyla', 'uobyqa', 'newuoa', 'bobyqa', 'lincoa'};
precisions = {'double', 'single', 'quadruple'};
debug_flags = {true, false};
variants = {'modern', 'classical'};
% Show current path information.
showpath(solvers);
% Test the solvers.
fun = @sin;
x0 = 1;
for isol = 1 : length(solvers)
solver = str2func(solvers{isol});
solver
options = struct();
for iprc = 1 : length(precisions)
options.precision = precisions{iprc};
for idbg = 1 : length(debug_flags)
options.debug = debug_flags{idbg};
for ivar = 1 : length(variants)
options.classical = strcmp(variants{ivar}, 'classical');
options.output_xhist = true;
options
format long
[x, f, exitflag, output] = solver(fun, x0, options)
if (ismember(solvers{isol}, matlab_implemented))
options_mat = options;
options_mat.fortran = false;
[x, f, exitflag, output] = solver(fun, x0, options_mat)
end
end
end
end
end
% Show current path information again at the end of test.
showpath(solvers);
catch exception
% Do nothing for the moment.
end
setpath(oldpath); % Restore the path to oldpath.
cd(olddir); % Go back to olddir.
fprintf('\nCurrently in %s\n\n', pwd());
if ~isempty(exception) % Rethrow any exception caught above.
rethrow(exception);
end
end