-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds code to ensure parameter array indices are valid (#236)
* Refactors code to be more explicit about use of resolution parameters * Adds new routine "checkIndices.m" * Refactors "checkIndices" to be called from "parseClassToStruct" * Updates errors in "checkIndices" * Addresses review comments * Fixes tests * Restores defaults for "contrastDomainRatios"
- Loading branch information
1 parent
02d87fb
commit 2257620
Showing
36 changed files
with
241 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
function checkIndices(problemStruct) | ||
% Make sure that the indices provided lie within the bounds of the | ||
% corresponding array. | ||
|
||
numBackgroundParams = length(problemStruct.backgroundParams); | ||
for i = 1:length(problemStruct.contrastBackgrounds) | ||
index = problemStruct.contrastBackgrounds(i); | ||
if index < 1 || index > numBackgroundParams | ||
throw(exceptions.indexOutOfRange(sprintf('contrastBackgrounds(%i) is %i, which is outside the range of backgroundParams', i, index))); | ||
end | ||
end | ||
|
||
numQzshifts = length(problemStruct.qzshifts); | ||
for i = 1:length(problemStruct.contrastQzshifts) | ||
index = problemStruct.contrastQzshifts(i); | ||
if index < 1 || index > numQzshifts | ||
throw(exceptions.indexOutOfRange(sprintf('contrastQzshifts(%i) is %i, which is outside the range of qzshifts', i, index))); | ||
end | ||
end | ||
|
||
numScalefactors = length(problemStruct.scalefactors); | ||
for i = 1:length(problemStruct.contrastScalefactors) | ||
index = problemStruct.contrastScalefactors(i); | ||
if index < 1 || index > numScalefactors | ||
throw(exceptions.indexOutOfRange(sprintf('contrastScalefactors(%i) is %i, which is outside the range of scalefactors', i, index))); | ||
end | ||
end | ||
|
||
numBulkIns = length(problemStruct.bulkIn); | ||
for i = 1:length(problemStruct.contrastBulkIns) | ||
index = problemStruct.contrastBulkIns(i); | ||
if index < 1 || index > numBulkIns | ||
throw(exceptions.indexOutOfRange(sprintf('contrastBulkIns(%i) is %i, which is outside the range of bulkIn', i, index))); | ||
end | ||
end | ||
|
||
numBulkOuts = length(problemStruct.bulkOut); | ||
for i = 1:length(problemStruct.contrastBulkOuts) | ||
index = problemStruct.contrastBulkOuts(i); | ||
if index < 1 || index > numBulkOuts | ||
throw(exceptions.indexOutOfRange(sprintf('contrastBulkOuts(%i) is %i, which is outside the range of bulkOut', i, index))); | ||
end | ||
end | ||
|
||
numResolutionParams = length(problemStruct.resolutionParams); | ||
for i = 1:length(problemStruct.contrastResolutionParams) | ||
index = problemStruct.contrastResolutionParams(i); | ||
if (index < 1 && index ~= -1) || index > numResolutionParams | ||
throw(exceptions.indexOutOfRange(sprintf('contrastResolutionParams(%i) is %i, which is outside the range of resolutionParams', i, index))); | ||
end | ||
end | ||
|
||
numDomainRatios = length(problemStruct.domainRatio); | ||
for i = 1:length(problemStruct.contrastDomainRatios) | ||
index = problemStruct.contrastDomainRatios(i); | ||
if (index < 1 && index ~= -1) || index > numDomainRatios | ||
throw(exceptions.indexOutOfRange(sprintf('contrastDomainRatios(%i) is %i, which is outside the range of domainRatio', i, index))); | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.