Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes unnecessary coder varsize calls #267

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions compile/fullCompile/makeCompileArgsFull.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ARGS_1_1.oilChiDataPresent = coder.typeof(0,[1 maxArraySize],[0 1]);
ARGS_1_1.numberOfContrasts = coder.typeof(0);
ARGS_1_1.geometry = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_1.useImaginary = coder.typeof(true,[1 1],[0 0]);
ARGS_1_1.useImaginary = coder.typeof(true);
ARGS_1_1.contrastBackgroundParams = coder.typeof(0,[1 maxArraySize],[0 1]);
ARGS_1_1.contrastBackgroundActions = coder.typeof(0,[1 maxArraySize],[0 1]);
ARGS_1_1.contrastQzshifts = coder.typeof(0,[1 maxArraySize],[0 1]);
Expand Down Expand Up @@ -45,7 +45,7 @@
ARGS_1_2 = cell([1 21]);
ARG = coder.typeof(0,[1 2]);
ARGS_1_2{1} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
ARG = coder.typeof(0,[maxDataSize 5],[1 1]);
ARG = coder.typeof(0,[maxDataSize 5],[1 1]);
ARGS_1_2{2} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
ARG = coder.typeof(0,[1 2]);
ARGS_1_2{3} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
Expand Down Expand Up @@ -75,7 +75,7 @@
ARGS_1_2{15} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
ARG = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_2{16} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
ARG = coder.typeof(0,[maxArraySize 5],[1 1]);
ARG = coder.typeof(0,[maxArraySize 5],[1 1]);
ARGS_1_2{17} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
ARG = coder.typeof(0,[1 2]);
ARGS_1_2{18} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
Expand Down Expand Up @@ -108,8 +108,8 @@
ARGS_1_4.funcTolerance = coder.typeof(0);
ARGS_1_4.maxFuncEvals = coder.typeof(0);
ARGS_1_4.maxIterations = coder.typeof(0);
ARGS_1_4.updateFreq = coder.typeof(0,[1 1]);
ARGS_1_4.updatePlotFreq = coder.typeof(0,[1 1]);
ARGS_1_4.updateFreq = coder.typeof(0);
ARGS_1_4.updatePlotFreq = coder.typeof(0);
ARGS_1_4.populationSize = coder.typeof(0);
ARGS_1_4.fWeight = coder.typeof(0);
ARGS_1_4.crossoverProbability = coder.typeof(0);
Expand All @@ -120,10 +120,10 @@
ARGS_1_4.nMCMC = coder.typeof(0);
ARGS_1_4.propScale = coder.typeof(0);
ARGS_1_4.nsTolerance = coder.typeof(0);
ARGS_1_4.nSamples = coder.typeof(0,[1 1]);
ARGS_1_4.nChains = coder.typeof(0,[1 1]);
ARGS_1_4.jumpProbability = coder.typeof(0,[1 1]);
ARGS_1_4.pUnitGamma = coder.typeof(0,[1 1]);
ARGS_1_4.nSamples = coder.typeof(0);
ARGS_1_4.nChains = coder.typeof(0);
ARGS_1_4.jumpProbability = coder.typeof(0);
ARGS_1_4.pUnitGamma = coder.typeof(0);
ARGS_1_4.boundHandling = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_4.adaptPCR = coder.typeof(true);
ARGS_1_4_checks = struct;
Expand Down
18 changes: 9 additions & 9 deletions compile/reflectivityCalculation/makeCompileArgs.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ARGS_1_1.oilChiDataPresent = coder.typeof(0,[1 maxArraySize],[0 1]);
ARGS_1_1.numberOfContrasts = coder.typeof(0);
ARGS_1_1.geometry = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_1.useImaginary = coder.typeof(true,[1 1],[0 0]);
ARGS_1_1.useImaginary = coder.typeof(true);
ARGS_1_1.contrastBackgroundParams = coder.typeof(0,[1 maxArraySize],[0 1]);
ARGS_1_1.contrastBackgroundActions = coder.typeof(0,[1 maxArraySize],[0 1]);
ARGS_1_1.contrastQzshifts = coder.typeof(0,[1 maxArraySize],[0 1]);
Expand Down Expand Up @@ -45,7 +45,7 @@
ARGS_1_2 = cell([1 21]);
ARG = coder.typeof(0,[1 2]);
ARGS_1_2{1} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
ARG = coder.typeof(0,[maxDataSize 5],[1 1]);
ARG = coder.typeof(0,[maxDataSize 5],[1 1]);
ARGS_1_2{2} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
ARG = coder.typeof(0,[1 2]);
ARGS_1_2{3} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
Expand Down Expand Up @@ -75,7 +75,7 @@
ARGS_1_2{15} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
ARG = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_2{16} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
ARG = coder.typeof(0,[maxArraySize 5],[1 1]);
ARG = coder.typeof(0,[maxArraySize 5],[1 1]);
ARGS_1_2{17} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
ARG = coder.typeof(0,[1 2]);
ARGS_1_2{18} = coder.typeof({ARG}, [1 maxArraySize],[0 1]);
Expand Down Expand Up @@ -108,8 +108,8 @@
ARGS_1_4.funcTolerance = coder.typeof(0);
ARGS_1_4.maxFuncEvals = coder.typeof(0);
ARGS_1_4.maxIterations = coder.typeof(0);
ARGS_1_4.updateFreq = coder.typeof(0,[1 1]);
ARGS_1_4.updatePlotFreq = coder.typeof(0,[1 1]);
ARGS_1_4.updateFreq = coder.typeof(0);
ARGS_1_4.updatePlotFreq = coder.typeof(0);
ARGS_1_4.populationSize = coder.typeof(0);
ARGS_1_4.fWeight = coder.typeof(0);
ARGS_1_4.crossoverProbability = coder.typeof(0);
Expand All @@ -120,10 +120,10 @@
ARGS_1_4.nMCMC = coder.typeof(0);
ARGS_1_4.propScale = coder.typeof(0);
ARGS_1_4.nsTolerance = coder.typeof(0);
ARGS_1_4.nSamples = coder.typeof(0,[1 1]);
ARGS_1_4.nChains = coder.typeof(0,[1 1]);
ARGS_1_4.jumpProbability = coder.typeof(0,[1 1]);
ARGS_1_4.pUnitGamma = coder.typeof(0,[1 1]);
ARGS_1_4.nSamples = coder.typeof(0);
ARGS_1_4.nChains = coder.typeof(0);
ARGS_1_4.jumpProbability = coder.typeof(0);
ARGS_1_4.pUnitGamma = coder.typeof(0);
ARGS_1_4.boundHandling = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_4.adaptPCR = coder.typeof(true);
ARGS_1_4_checks = struct;
Expand Down
2 changes: 1 addition & 1 deletion minimisers/DE/deopt.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

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

coder.varsize('problemStruct.resample',[Inf,1],[1 0]);
coder.varsize('problemStruct.resample',[Inf 1],[1 0]);
coder.varsize('FVr_bestmem',[1 Inf],[0 1]);
coder.varsize('FVr_bestmemit',[1 Inf],[0 1]);

Expand Down
28 changes: 2 additions & 26 deletions minimisers/DE/runDE.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
F_VTR = controls.targetValue; %Value to reach
I_D = length(problemStruct.fitParams);

FVr_minbound = problemStruct.fitLimits(:,1)';
FVr_maxbound = problemStruct.fitLimits(:,2)';
FVr_minbound = problemStruct.fitLimits(:,1)';
FVr_maxbound = problemStruct.fitLimits(:,2)';
I_bnd_constr = 1; %1: use bounds as bound constraints, 0: no bound constraints

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

%Tell compiler abut variable sizes
coder.varsize('S_struct.I_lentol', [Inf 1],[1 0]);
coder.varsize('S_struct.FVr_x', [1 Inf],[0 1]);
coder.varsize('S_struct.FVr_lim_up', [1 Inf],[0 1]);
coder.varsize('S_struct.FVr_lim_lo', [1 Inf],[0 1]);

coder.varsize('S_struct.I_NP', [1 1],[0 0]);
coder.varsize('S_struct.fWeight', [1 1],[0 0]);
coder.varsize('S_struct.F_CR', [1 1],[0 0]);
coder.varsize('S_struct.I_D', [1 1],[0 0]);
coder.varsize('S_struct.FVr_minbound', [1 Inf],[0 1]);
coder.varsize('S_struct.FVr_maxbound', [1 Inf],[0 1]);
coder.varsize('S_struct.I_bnd_constr', [1 1],[0 0]);
coder.varsize('S_struct.I_itermax', [1 1],[0 0]);
coder.varsize('S_struct.F_VTR', [1 1],[0 0]);
coder.varsize('S_struct.I_strategy', [1 1],[0 0]);
coder.varsize('S_struct.I_refresh', [1 1],[0 0]);
coder.varsize('S_struct.I_plotting', [1 1],[0 0]);
coder.varsize('S_struct.FM_pop',[Inf 2],[1 0]);
coder.varsize('S_struct.FVr_bestmem',[1 Inf],[0 1]);
coder.varsize('FVr_bestmem',[1 Inf],[0 1]);

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


function [S_MSE,result] = intrafun(p,problemStruct,problemCells,problemLimits,controls)

coder.varsize('S_MSE.I_nc',[1 1],[0 0]);
coder.varsize('S_MSE.FVr_ca',[1 1],[0 0]);
coder.varsize('S_MSE.I_no',[1 1],[0 0]);
coder.varsize('S_MSE.FVr_oa',[1 1],[0 0]);

problemStruct.fitParams = p';
problemStruct = unpackParams(problemStruct,controls);
Expand Down
2 changes: 1 addition & 1 deletion minimisers/DREAM/functions/drawCR.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
% Generates CR values based on current crossover probabilities

CR = [1,1];
coder.varsize('CR',[1e2,1e6],[1,1]);
coder.varsize('CR',[1e2 1e6],[1 1]);

if DREAMPar.adaptPCR

Expand Down
1 change: 0 additions & 1 deletion minimisers/DREAM/functions/initializeDREAM.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@

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

lCR = zeros(1,DREAMPar.nCR);
delta_tot = zeros(1,DREAMPar.nCR);
Expand Down
6 changes: 0 additions & 6 deletions minimisers/NS/runNestedSampler.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
checks = controls.checks;
[problemStruct,fitNames] = packParams(problemStruct,problemCells,problemLimits,checks);

nestSamples = [0 0 ; 0 0];
coder.varsize('nest_samples');

postSamples = [0 0 ; 0 0];
coder.varsize('post_samples');

logZ = 0;
H = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
numberOfContrasts = problemStruct.numberOfContrasts;

vals = zeros(1,3);
coder.varsize('vals',[1e4 1e4],[1 1]);

rowVals = zeros(1,3);
coder.varsize('rowVals',[1 1e4],[0 1]);

refXVals = makeCell(numberOfContrasts, 1, rowVals); %cell(numberOfContrasts,1);
refYVals = makeCell(numberOfContrasts, 1, vals); %cell(numberOfContrasts,1);
Expand Down
19 changes: 6 additions & 13 deletions targetFunctions/+domainsTF/+customLayers/processCustomFunction.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
% contrasts.

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

for i = 1:numberOfContrasts
resampledLayers{i,1} = [1, 1]; % Type def as double (size not important)
resampledLayers{i,2} = [1, 1];
tempResampledLayers{i,1} = [0 0 0 0 0];
tempResampledLayers{i,2} = [0 0 0 0 0];
resampledLayers{i,1} = [0 0 0 0 0];
resampledLayers{i,2} = [0 0 0 0 0];
end
coder.varsize('tempResampledLayers{:}',[10000 6],[1 1]);
coder.varsize('resampledLayers{:}',[10000 6],[1 1]);

bulkOuts = bulkOutArray(contrastBulkOuts);
Expand All @@ -28,10 +23,10 @@
% Find values of 'bulkIn' and 'bulkOut' for this
% contrast...
thisContrastLayers1 = [1 1 1]; % typeDef
coder.varsize('thisContrastLayers1',[10000, 6],[1 1]);
coder.varsize('thisContrastLayers1',[10000 6],[1 1]);

thisContrastLayers2 = [1 1 1]; % typeDef
coder.varsize('thisContrastLayers2',[10000, 6],[1 1]);
coder.varsize('thisContrastLayers2',[10000 6],[1 1]);

thisBulkIn = bulkInArray(contrastBulkIns(i));
thisBulkOut = bulkOuts(i);
Expand All @@ -55,10 +50,8 @@
thisContrastLayers2 = applyHydrationImag(thisContrastLayers2,thisBulkIn,thisBulkOut);
end

tempResampledLayers{i,1} = thisContrastLayers1;
tempResampledLayers{i,2} = thisContrastLayers2;
resampledLayers{i,1} = thisContrastLayers1;
resampledLayers{i,2} = thisContrastLayers2;
end

resampledLayers = tempResampledLayers;

end
19 changes: 7 additions & 12 deletions targetFunctions/+domainsTF/+customXY/processCustomFunction.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
% contrasts.

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

for i = 1:numberOfContrasts
slds{i,1} = [1,1]; % Type def as double (size not important)
slds{i,2} = [1,1];
tempSLDs{i,1} = [0 0];
tempSLDs{i,2} = [0 0];
slds{i,1} = [0 0];
slds{i,2} = [0 0];
end
coder.varsize('tempSLDs{:}',[10000 3],[1 1]); % 3 columns to allow for potential imaginary curve
coder.varsize('slds{:}',[10000 3],[1 1]); % 3 columns to allow for potential imaginary curve

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

if isnan(str2double(functionHandle))
[tempSLDs{i, 1}, subRoughs(i)] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 1);
[tempSLDs{i, 2}, ~] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 2);
[slds{i, 1}, subRoughs(i)] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 1);
[slds{i, 2}, ~] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 2);
else
[tempSLDs{i, 1}, subRoughs(i)] = callCppFunction(functionHandle, params, thisBulkIn, bulkOuts, i-1, 0);
[tempSLDs{i, 2}, ~] = callCppFunction(functionHandle, params, thisBulkIn, bulkOuts, i-1, 1);
[slds{i, 1}, subRoughs(i)] = callCppFunction(functionHandle, params, thisBulkIn, bulkOuts, i-1, 0);
[slds{i, 2}, ~] = callCppFunction(functionHandle, params, thisBulkIn, bulkOuts, i-1, 1);
end
end

slds = tempSLDs;
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
% contrasts.

% Do some pre-definitions to keep the compiler happy...
tempResampledLayers = cell(numberOfContrasts,1);
resampledLayers = cell(numberOfContrasts,1);
subRoughs = zeros(numberOfContrasts,1);

for i = 1:numberOfContrasts
resampledLayers{i} = [1 , 1]; % Type def as double (size not important)
tempResampledLayers{i} = [0 0 0 0 0];
resampledLayers{i} = [0 0 0 0 0];
end
coder.varsize('tempResampledLayers{:}',[10000 6],[1 1]);
coder.varsize('resampledLayers{:}',[10000 6],[1 1]);

bulkOuts = bulkOutArray(contrastBulkOuts);
for i = 1:numberOfContrasts % TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's..
Expand All @@ -27,7 +25,7 @@
thisBulkOut = bulkOuts(i);

thisContrastLayers = [1 1 1]; % typeDef
coder.varsize('thisContrastLayers',[10000, 6],[1 1]);
coder.varsize('thisContrastLayers',[10000 6],[1 1]);
if isnan(str2double(functionHandle))
[thisContrastLayers,subRoughs(i)] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 0);
else
Expand All @@ -43,9 +41,7 @@
thisContrastLayers = applyHydrationImag(thisContrastLayers,thisBulkIn,thisBulkOut);
end

tempResampledLayers{i} = thisContrastLayers;
resampledLayers{i} = thisContrastLayers;
end

resampledLayers = tempResampledLayers;

end
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
function [slds,subRoughs] = processCustomFunction(contrastBulkIns,contrastBulkOuts,...
bulkInArray,bulkOutArray,cCustFiles,numberOfContrasts,customFiles,params)
bulkInArray,bulkOutArray,cCustFiles,numberOfContrasts,customFiles,params)

% Top-level function for processing custom XY profiles for all the
% contrasts.

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

for i = 1:numberOfContrasts
slds{i} = [1,1]; % Type def as double (size not important)
tempSLDs{i} = [0 0];
slds{i} = [0 0];
end
coder.varsize('tempSLDs{:}',[10000 3],[1 1]); % 3 columns to allow for potential imaginary curve
coder.varsize('slds{:}',[10000 3],[1 1]); % 3 columns to allow for potential imaginary curve

bulkOuts = bulkOutArray(contrastBulkOuts);
for i = 1:numberOfContrasts % TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's..
Expand All @@ -26,11 +24,9 @@
thisBulkIn = bulkInArray(contrastBulkIns(i));

if isnan(str2double(functionHandle))
[tempSLDs{i}, subRoughs(i)] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 0);
[slds{i}, subRoughs(i)] = callMatlabFunction(functionHandle, params, thisBulkIn, bulkOuts, i, 0);
else
[tempSLDs{i}, subRoughs(i)] = callCppFunction(functionHandle, params, thisBulkIn, bulkOuts, i-1, -1);
[slds{i}, subRoughs(i)] = callCppFunction(functionHandle, params, thisBulkIn, bulkOuts, i-1, -1);
end
end

slds = tempSLDs;
end
10 changes: 2 additions & 8 deletions targetFunctions/+nonPolarisedTF/coreLayersCalculation.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@
%

% Pre-definition for Coder
thisSldLaysIm = [0 0];
sldProfile = [0 0];
sldProfileIm = [0 0];
coder.varsize('thisSldLays',[10000 3],[1 1]);
coder.varsize('thisSldLaysIm',[10000 3],[1 1]);
coder.varsize('sldProfile',[10000 3],[1 1]);
coder.varsize('sldProfileIm',[10000 3],[1 1]);

% Build up the layers matrix for this contrast
if ~useImaginary
Expand All @@ -79,6 +75,7 @@
thisSldLaysIm = [theseLayers(:,1) theseLayers(:,3:end)];
else
thisSldLays = theseLayers;
thisSldLaysIm = [0 0]; % Dummy value for coder
end

sldProfile = makeSLDProfiles(bulkIn,bulkOut,thisSldLays,ssubs,repeatLayers);
Expand All @@ -90,9 +87,6 @@
% the bulk phases..
sldProfileIm = makeSLDProfiles(0,0,thisSldLaysIm,ssubs,repeatLayers);
end

else
sldProfile = [0 0];
end

% If required, then resample the SLD
Expand Down
Loading