Skip to content

Commit 5487610

Browse files
authored
Removes unnecessary coder varsize calls (#267)
* Removes unnecessary coder varsize calls * Removes varsize calls from minimisers * Correction
1 parent 253fde5 commit 5487610

File tree

17 files changed

+126
-220
lines changed

17 files changed

+126
-220
lines changed

compile/fullCompile/makeCompileArgsFull.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
ARGS_1_1.oilChiDataPresent = coder.typeof(0,[1 maxArraySize],[0 1]);
1717
ARGS_1_1.numberOfContrasts = coder.typeof(0);
1818
ARGS_1_1.geometry = coder.typeof('X',[1 maxArraySize],[0 1]);
19-
ARGS_1_1.useImaginary = coder.typeof(true,[1 1],[0 0]);
19+
ARGS_1_1.useImaginary = coder.typeof(true);
2020
ARGS_1_1.contrastBackgroundParams = coder.typeof(0,[1 maxArraySize],[0 1]);
2121
ARGS_1_1.contrastBackgroundActions = coder.typeof(0,[1 maxArraySize],[0 1]);
2222
ARGS_1_1.contrastQzshifts = coder.typeof(0,[1 maxArraySize],[0 1]);
@@ -45,7 +45,7 @@
4545
ARGS_1_2 = cell([1 21]);
4646
ARG = coder.typeof(0,[1 2]);
4747
ARGS_1_2{1} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
48-
ARG = coder.typeof(0,[maxDataSize 5],[1 1]);
48+
ARG = coder.typeof(0,[maxDataSize 5],[1 1]);
4949
ARGS_1_2{2} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
5050
ARG = coder.typeof(0,[1 2]);
5151
ARGS_1_2{3} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
@@ -75,7 +75,7 @@
7575
ARGS_1_2{15} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
7676
ARG = coder.typeof('X',[1 maxArraySize],[0 1]);
7777
ARGS_1_2{16} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
78-
ARG = coder.typeof(0,[maxArraySize 5],[1 1]);
78+
ARG = coder.typeof(0,[maxArraySize 5],[1 1]);
7979
ARGS_1_2{17} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
8080
ARG = coder.typeof(0,[1 2]);
8181
ARGS_1_2{18} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
@@ -108,8 +108,8 @@
108108
ARGS_1_4.funcTolerance = coder.typeof(0);
109109
ARGS_1_4.maxFuncEvals = coder.typeof(0);
110110
ARGS_1_4.maxIterations = coder.typeof(0);
111-
ARGS_1_4.updateFreq = coder.typeof(0,[1 1]);
112-
ARGS_1_4.updatePlotFreq = coder.typeof(0,[1 1]);
111+
ARGS_1_4.updateFreq = coder.typeof(0);
112+
ARGS_1_4.updatePlotFreq = coder.typeof(0);
113113
ARGS_1_4.populationSize = coder.typeof(0);
114114
ARGS_1_4.fWeight = coder.typeof(0);
115115
ARGS_1_4.crossoverProbability = coder.typeof(0);
@@ -120,10 +120,10 @@
120120
ARGS_1_4.nMCMC = coder.typeof(0);
121121
ARGS_1_4.propScale = coder.typeof(0);
122122
ARGS_1_4.nsTolerance = coder.typeof(0);
123-
ARGS_1_4.nSamples = coder.typeof(0,[1 1]);
124-
ARGS_1_4.nChains = coder.typeof(0,[1 1]);
125-
ARGS_1_4.jumpProbability = coder.typeof(0,[1 1]);
126-
ARGS_1_4.pUnitGamma = coder.typeof(0,[1 1]);
123+
ARGS_1_4.nSamples = coder.typeof(0);
124+
ARGS_1_4.nChains = coder.typeof(0);
125+
ARGS_1_4.jumpProbability = coder.typeof(0);
126+
ARGS_1_4.pUnitGamma = coder.typeof(0);
127127
ARGS_1_4.boundHandling = coder.typeof('X',[1 maxArraySize],[0 1]);
128128
ARGS_1_4.adaptPCR = coder.typeof(true);
129129
ARGS_1_4_checks = struct;

compile/reflectivityCalculation/makeCompileArgs.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
ARGS_1_1.oilChiDataPresent = coder.typeof(0,[1 maxArraySize],[0 1]);
1717
ARGS_1_1.numberOfContrasts = coder.typeof(0);
1818
ARGS_1_1.geometry = coder.typeof('X',[1 maxArraySize],[0 1]);
19-
ARGS_1_1.useImaginary = coder.typeof(true,[1 1],[0 0]);
19+
ARGS_1_1.useImaginary = coder.typeof(true);
2020
ARGS_1_1.contrastBackgroundParams = coder.typeof(0,[1 maxArraySize],[0 1]);
2121
ARGS_1_1.contrastBackgroundActions = coder.typeof(0,[1 maxArraySize],[0 1]);
2222
ARGS_1_1.contrastQzshifts = coder.typeof(0,[1 maxArraySize],[0 1]);
@@ -45,7 +45,7 @@
4545
ARGS_1_2 = cell([1 21]);
4646
ARG = coder.typeof(0,[1 2]);
4747
ARGS_1_2{1} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
48-
ARG = coder.typeof(0,[maxDataSize 5],[1 1]);
48+
ARG = coder.typeof(0,[maxDataSize 5],[1 1]);
4949
ARGS_1_2{2} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
5050
ARG = coder.typeof(0,[1 2]);
5151
ARGS_1_2{3} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
@@ -75,7 +75,7 @@
7575
ARGS_1_2{15} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
7676
ARG = coder.typeof('X',[1 maxArraySize],[0 1]);
7777
ARGS_1_2{16} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
78-
ARG = coder.typeof(0,[maxArraySize 5],[1 1]);
78+
ARG = coder.typeof(0,[maxArraySize 5],[1 1]);
7979
ARGS_1_2{17} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
8080
ARG = coder.typeof(0,[1 2]);
8181
ARGS_1_2{18} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
@@ -108,8 +108,8 @@
108108
ARGS_1_4.funcTolerance = coder.typeof(0);
109109
ARGS_1_4.maxFuncEvals = coder.typeof(0);
110110
ARGS_1_4.maxIterations = coder.typeof(0);
111-
ARGS_1_4.updateFreq = coder.typeof(0,[1 1]);
112-
ARGS_1_4.updatePlotFreq = coder.typeof(0,[1 1]);
111+
ARGS_1_4.updateFreq = coder.typeof(0);
112+
ARGS_1_4.updatePlotFreq = coder.typeof(0);
113113
ARGS_1_4.populationSize = coder.typeof(0);
114114
ARGS_1_4.fWeight = coder.typeof(0);
115115
ARGS_1_4.crossoverProbability = coder.typeof(0);
@@ -120,10 +120,10 @@
120120
ARGS_1_4.nMCMC = coder.typeof(0);
121121
ARGS_1_4.propScale = coder.typeof(0);
122122
ARGS_1_4.nsTolerance = coder.typeof(0);
123-
ARGS_1_4.nSamples = coder.typeof(0,[1 1]);
124-
ARGS_1_4.nChains = coder.typeof(0,[1 1]);
125-
ARGS_1_4.jumpProbability = coder.typeof(0,[1 1]);
126-
ARGS_1_4.pUnitGamma = coder.typeof(0,[1 1]);
123+
ARGS_1_4.nSamples = coder.typeof(0);
124+
ARGS_1_4.nChains = coder.typeof(0);
125+
ARGS_1_4.jumpProbability = coder.typeof(0);
126+
ARGS_1_4.pUnitGamma = coder.typeof(0);
127127
ARGS_1_4.boundHandling = coder.typeof('X',[1 maxArraySize],[0 1]);
128128
ARGS_1_4.adaptPCR = coder.typeof(true);
129129
ARGS_1_4_checks = struct;

minimisers/DE/deopt.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484

8585
%-----This is just for notational convenience and to keep the code uncluttered.--------
8686

87-
coder.varsize('problemStruct.resample',[Inf,1],[1 0]);
87+
coder.varsize('problemStruct.resample',[Inf 1],[1 0]);
8888
coder.varsize('FVr_bestmem',[1 Inf],[0 1]);
8989
coder.varsize('FVr_bestmemit',[1 Inf],[0 1]);
9090

minimisers/DE/runDE.m

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
F_VTR = controls.targetValue; %Value to reach
55
I_D = length(problemStruct.fitParams);
66

7-
FVr_minbound = problemStruct.fitLimits(:,1)';
8-
FVr_maxbound = problemStruct.fitLimits(:,2)';
7+
FVr_minbound = problemStruct.fitLimits(:,1)';
8+
FVr_maxbound = problemStruct.fitLimits(:,2)';
99
I_bnd_constr = 1; %1: use bounds as bound constraints, 0: no bound constraints
1010

1111
% I_NP number of population members
@@ -56,26 +56,7 @@
5656
FVr_lim_lo = -ones(1,I_lentol); %lower limit is -1
5757

5858
%Tell compiler abut variable sizes
59-
coder.varsize('S_struct.I_lentol', [Inf 1],[1 0]);
60-
coder.varsize('S_struct.FVr_x', [1 Inf],[0 1]);
61-
coder.varsize('S_struct.FVr_lim_up', [1 Inf],[0 1]);
62-
coder.varsize('S_struct.FVr_lim_lo', [1 Inf],[0 1]);
63-
64-
coder.varsize('S_struct.I_NP', [1 1],[0 0]);
65-
coder.varsize('S_struct.fWeight', [1 1],[0 0]);
66-
coder.varsize('S_struct.F_CR', [1 1],[0 0]);
67-
coder.varsize('S_struct.I_D', [1 1],[0 0]);
68-
coder.varsize('S_struct.FVr_minbound', [1 Inf],[0 1]);
69-
coder.varsize('S_struct.FVr_maxbound', [1 Inf],[0 1]);
70-
coder.varsize('S_struct.I_bnd_constr', [1 1],[0 0]);
71-
coder.varsize('S_struct.I_itermax', [1 1],[0 0]);
72-
coder.varsize('S_struct.F_VTR', [1 1],[0 0]);
73-
coder.varsize('S_struct.I_strategy', [1 1],[0 0]);
74-
coder.varsize('S_struct.I_refresh', [1 1],[0 0]);
75-
coder.varsize('S_struct.I_plotting', [1 1],[0 0]);
76-
coder.varsize('S_struct.FM_pop',[Inf 2],[1 0]);
7759
coder.varsize('S_struct.FVr_bestmem',[1 Inf],[0 1]);
78-
coder.varsize('FVr_bestmem',[1 Inf],[0 1]);
7960

8061
%-----tie all important values to a structure that can be passed along----
8162
S_struct.I_lentol = I_lentol;
@@ -111,11 +92,6 @@
11192

11293

11394
function [S_MSE,result] = intrafun(p,problemStruct,problemCells,problemLimits,controls)
114-
115-
coder.varsize('S_MSE.I_nc',[1 1],[0 0]);
116-
coder.varsize('S_MSE.FVr_ca',[1 1],[0 0]);
117-
coder.varsize('S_MSE.I_no',[1 1],[0 0]);
118-
coder.varsize('S_MSE.FVr_oa',[1 1],[0 0]);
11995

12096
problemStruct.fitParams = p';
12197
problemStruct = unpackParams(problemStruct,controls);

minimisers/DREAM/functions/drawCR.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
% Generates CR values based on current crossover probabilities
33

44
CR = [1,1];
5-
coder.varsize('CR',[1e2,1e6],[1,1]);
5+
coder.varsize('CR',[1e2 1e6],[1 1]);
66

77
if DREAMPar.adaptPCR
88

minimisers/DREAM/functions/initializeDREAM.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060

6161
% Generate the actula CR value, lCR and delta_tot
6262
CR = drawCR(DREAMPar,pCR);
63-
%coder.varsize('CR',[100 1e4],[1 1]);
6463

6564
lCR = zeros(1,DREAMPar.nCR);
6665
delta_tot = zeros(1,DREAMPar.nCR);

minimisers/NS/runNestedSampler.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
checks = controls.checks;
44
[problemStruct,fitNames] = packParams(problemStruct,problemCells,problemLimits,checks);
55

6-
nestSamples = [0 0 ; 0 0];
7-
coder.varsize('nest_samples');
8-
9-
postSamples = [0 0 ; 0 0];
10-
coder.varsize('post_samples');
11-
126
logZ = 0;
137
H = 0;
148

minimisers/generalUtils/bayesStats/refPercentileConfidenceIntervals.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
numberOfContrasts = problemStruct.numberOfContrasts;
3030

3131
vals = zeros(1,3);
32-
coder.varsize('vals',[1e4 1e4],[1 1]);
33-
3432
rowVals = zeros(1,3);
35-
coder.varsize('rowVals',[1 1e4],[0 1]);
3633

3734
refXVals = makeCell(numberOfContrasts, 1, rowVals); %cell(numberOfContrasts,1);
3835
refYVals = makeCell(numberOfContrasts, 1, vals); %cell(numberOfContrasts,1);

targetFunctions/+domainsTF/+customLayers/processCustomFunction.m

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55
% contrasts.
66

77
% Do some pre-definitions to keep the compiler happy...
8-
%totNumCalcs = numberOfContrasts * 2;
9-
tempResampledLayers = cell(numberOfContrasts,2);
108
resampledLayers = cell(numberOfContrasts,2);
119
subRoughs = zeros(numberOfContrasts,1);
1210

1311
for i = 1:numberOfContrasts
14-
resampledLayers{i,1} = [1, 1]; % Type def as double (size not important)
15-
resampledLayers{i,2} = [1, 1];
16-
tempResampledLayers{i,1} = [0 0 0 0 0];
17-
tempResampledLayers{i,2} = [0 0 0 0 0];
12+
resampledLayers{i,1} = [0 0 0 0 0];
13+
resampledLayers{i,2} = [0 0 0 0 0];
1814
end
19-
coder.varsize('tempResampledLayers{:}',[10000 6],[1 1]);
2015
coder.varsize('resampledLayers{:}',[10000 6],[1 1]);
2116

2217
bulkOuts = bulkOutArray(contrastBulkOuts);
@@ -28,10 +23,10 @@
2823
% Find values of 'bulkIn' and 'bulkOut' for this
2924
% contrast...
3025
thisContrastLayers1 = [1 1 1]; % typeDef
31-
coder.varsize('thisContrastLayers1',[10000, 6],[1 1]);
26+
coder.varsize('thisContrastLayers1',[10000 6],[1 1]);
3227

3328
thisContrastLayers2 = [1 1 1]; % typeDef
34-
coder.varsize('thisContrastLayers2',[10000, 6],[1 1]);
29+
coder.varsize('thisContrastLayers2',[10000 6],[1 1]);
3530

3631
thisBulkIn = bulkInArray(contrastBulkIns(i));
3732
thisBulkOut = bulkOuts(i);
@@ -55,10 +50,8 @@
5550
thisContrastLayers2 = applyHydrationImag(thisContrastLayers2,thisBulkIn,thisBulkOut);
5651
end
5752

58-
tempResampledLayers{i,1} = thisContrastLayers1;
59-
tempResampledLayers{i,2} = thisContrastLayers2;
53+
resampledLayers{i,1} = thisContrastLayers1;
54+
resampledLayers{i,2} = thisContrastLayers2;
6055
end
6156

62-
resampledLayers = tempResampledLayers;
63-
6457
end

targetFunctions/+domainsTF/+customXY/processCustomFunction.m

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
% contrasts.
66

77
% Do some pre-definitions to keep the compiler happy...
8-
tempSLDs = cell(numberOfContrasts,2);
98
slds = cell(numberOfContrasts,2);
109
subRoughs = zeros(numberOfContrasts,1);
1110

1211
for i = 1:numberOfContrasts
13-
slds{i,1} = [1,1]; % Type def as double (size not important)
14-
slds{i,2} = [1,1];
15-
tempSLDs{i,1} = [0 0];
16-
tempSLDs{i,2} = [0 0];
12+
slds{i,1} = [0 0];
13+
slds{i,2} = [0 0];
1714
end
18-
coder.varsize('tempSLDs{:}',[10000 3],[1 1]); % 3 columns to allow for potential imaginary curve
15+
coder.varsize('slds{:}',[10000 3],[1 1]); % 3 columns to allow for potential imaginary curve
1916

2017
bulkOuts = bulkOutArray(contrastBulkOuts);
2118
for i = 1:numberOfContrasts % TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's..
@@ -27,13 +24,11 @@
2724
thisBulkIn = bulkInArray(contrastBulkIns(i));
2825

2926
if isnan(str2double(functionHandle))
30-
[tempSLDs{i, 1}, subRoughs(i)] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 1);
31-
[tempSLDs{i, 2}, ~] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 2);
27+
[slds{i, 1}, subRoughs(i)] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 1);
28+
[slds{i, 2}, ~] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 2);
3229
else
33-
[tempSLDs{i, 1}, subRoughs(i)] = callCppFunction(functionHandle, params, thisBulkIn, bulkOuts, i-1, 0);
34-
[tempSLDs{i, 2}, ~] = callCppFunction(functionHandle, params, thisBulkIn, bulkOuts, i-1, 1);
30+
[slds{i, 1}, subRoughs(i)] = callCppFunction(functionHandle, params, thisBulkIn, bulkOuts, i-1, 0);
31+
[slds{i, 2}, ~] = callCppFunction(functionHandle, params, thisBulkIn, bulkOuts, i-1, 1);
3532
end
3633
end
37-
38-
slds = tempSLDs;
3934
end

0 commit comments

Comments
 (0)