Skip to content

Commit e067a15

Browse files
committed
250907.121439.CST matlab: misc small improvements
1 parent b672545 commit e067a15

File tree

7 files changed

+17
-29
lines changed

7 files changed

+17
-29
lines changed

matlab/interfaces/private/postprima.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
invoker_list = [invoker_list, strcat(invoker_list, '.m')];
5050
callstack = dbstack;
5151
funname = callstack(1).name; % Name of the current function
52-
if (length(callstack) == 1) || ~ismember(callstack(2).name, invoker_list)
52+
if length(callstack) > 1 && ismember(callstack(2).name, invoker_list)
53+
invoker = callstack(2).name; % Name of the function who calls this function
54+
else
5355
% Private/unexpected error
5456
error(sprintf('%s:InvalidInvoker', funname), ...
5557
'%s: UNEXPECTED ERROR: %s should only be called by %s.', funname, funname, strjoin(invoker_list, ', '));
56-
else
57-
invoker = callstack(2).name; % Name of the function who calls this function
5858
end
5959

6060
% Verify the input before starting the real business

matlab/interfaces/private/preprima.m

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
invoker_list = [invoker_list, strcat(invoker_list, '.m')];
3131
callstack = dbstack;
3232
funname = callstack(1).name; % Name of the current function
33-
if (length(callstack) == 1 || ~ismember(callstack(2).name, invoker_list))
33+
if length(callstack) > 1 && ismember(callstack(2).name, invoker_list)
34+
invoker = callstack(2).name; % Name of the function who calls this function
35+
else
3436
% Private/unexpected error
3537
error(sprintf('%s:InvalidInvoker', funname), ...
3638
'%s: UNEXPECTED ERROR: %s should only be called by %s.', funname, funname, strjoin(invoker_list, ', '));
37-
else
38-
invoker = callstack(2).name; % Name of the function who calls this function
3939
end
4040

4141
if (nargin ~= 1) && (nargin ~= 10)
@@ -435,11 +435,7 @@
435435

436436
if ~isempty(unknown_fields)
437437
wid = sprintf('%s:UnknownProbField', invoker);
438-
if length(unknown_fields) == 1
439-
wmsg = sprintf('%s: problem with an unknown field %s; it is ignored.', invoker, strjoin(unknown_fields, ', '));
440-
else
441-
wmsg = sprintf('%s: problem with unknown fields %s; they are ignored.', invoker, strjoin(unknown_fields, ', '));
442-
end
438+
wmsg = sprintf('%s: problem with unknown field(s) %s, which will be ignored.', invoker, strjoin(unknown_fields, ', '));
443439
warning(wid, '%s', wmsg);
444440
warnings = [warnings, wmsg];
445441
end
@@ -1023,11 +1019,7 @@
10231019
% even though we have declared that this field will be ignored.
10241020
if ~isempty(unknown_fields)
10251021
wid = sprintf('%s:UnknownOption', invoker);
1026-
if length(unknown_fields) == 1
1027-
wmsg = sprintf('%s: unknown option %s; it is ignored.', invoker, strjoin(unknown_fields, ', '));
1028-
else
1029-
wmsg = sprintf('%s: unknown options %s; they are ignored.', invoker, strjoin(unknown_fields, ', '));
1030-
end
1022+
wmsg = sprintf('%s: unknown option(s) %s, which will be ignored.', invoker, strjoin(unknown_fields, ', '));
10311023
warning(wid, '%s', wmsg);
10321024
warnings = [warnings, wmsg];
10331025
end

matlab/setup_tools/package_info.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
invoker_list = {'prima', 'preprima', 'parse_input'};
2222
callstack = dbstack;
2323
funname = callstack(1).name; % Name of the current function
24-
if (length(callstack) == 1 || ~ismember(callstack(2).name, invoker_list))
24+
if length(callstack) > 1 && ismember(callstack(2).name, invoker_list)
25+
invoker = callstack(2).name; % Name of the function who calls this function
26+
else
2527
% Private/unexpected error
2628
error(sprintf('%s:InvalidInvoker', funname), ...
2729
'%s: UNEXPECTED ERROR: %s should only be called by %s.', funname, funname, strjoin(invoker_list, ', '));
28-
else
29-
invoker = callstack(2).name; % Name of the function who calls this function
3030
end
3131

3232
name = 'PRIMA';

matlab/tests/parallel.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function parallel(solver, options)
7171

7272
%ticBytes(gcp)
7373

74-
parfor i = 1:np
74+
parfor ip = 1:np
7575
fprintf('\n>>>>>> Parallel test for %s, %d-th run <<<<<<\n', solver_name, i);
7676
test(solver, n, solver_options, random_seed + i);
7777
end

matlab/tests/private/isequiv.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,10 @@ function isequiv(solvers, options)
385385
test_options.npt = floor(2*rand*n);
386386
end
387387
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388-
if 1 <= ir && ir <= 20
388+
if rand < 0.5
389389
% The TOUGH tests
390-
% We must pass the random seed `rseed` to `tough` to ensure reproducibility.
390+
prob = tough(prob, rseed); % We must pass the random seed `rseed` to `tough` to ensure reproducibility.
391391
test_options.chkfunval = false; % The checking would fail due to noise.
392-
prob = tough(prob, rseed);
393-
else
394-
prob.objective = objective;
395-
prob.nonlcon = nonlcon;
396392
end
397393
prob.options = test_options;
398394

matlab/tests/private/isintnum.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
function is_intnum = isintnum(x)
2-
is_intnum = isnumeric(x) && numel(x) == 1 && abs(x-round(x)) <= eps;
2+
is_intnum = isnumeric(x) && isscalar(x) && abs(x-round(x)) <= eps;

matlab/tests/recursive.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function recursive(solver, options)
6464
solver_options.maxfun = min(100*n, 5e3);
6565
fun = @chrosen;
6666
for i = 1 : depth
67-
fun = @(x) rfun(x, fun, solver, n, solver_options);
67+
fun = @(x) rfun(x, fun, solver, solver_options);
6868
end
6969

7070
% Conduct the test
@@ -89,7 +89,7 @@ function recursive(solver, options)
8989

9090

9191
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92-
function f = rfun(x, fun, solver, n, solver_options)
92+
function f = rfun(x, fun, solver, solver_options)
9393
%RFUN defines a function of x by minimizing fun([x; y]) with respect to y in R^2 using a solver.
9494
solver_options.iprint = 0;
9595
solver_options.rhoend = 1.0e-2;

0 commit comments

Comments
 (0)