Skip to content

Commit

Permalink
Removes unnecessary coder varsize calls
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPaulSharp committed Sep 12, 2024
1 parent 253fde5 commit 8f8bbea
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 187 deletions.
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
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
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

0 comments on commit 8f8bbea

Please sign in to comment.