Skip to content

Commit

Permalink
IsotropicCovarianceModel throw if inputDimension=0
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmure committed Jun 6, 2024
1 parent af13c83 commit 5f62d30
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/Base/Stat/IsotropicCovarianceModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ IsotropicCovarianceModel::IsotropicCovarianceModel(const CovarianceModel & oneDi
const UnsignedInteger inputDimension)
: CovarianceModelImplementation(inputDimension)
{
if (!inputDimension)
throw InvalidArgumentException(HERE) << "In IsotropicCovarianceModel, the supplied inputDimension must be nonzero.";
setKernel(oneDimensional);
}

Expand Down
10 changes: 10 additions & 0 deletions lib/test/t_KrigingAlgorithm_isotropic_std.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ int main(int, char *[])
assert_almost_equal(krigingFittedCovarianceModel.getAmplitude()[0], 6.65231, 0.0, 1e-4);
}

try
{
IsotropicCovarianceModel(SquaredExponential(), 0);
throw InvalidDimensionException(HERE) << "Invalid IsotropicCovarianceModel should have thrown";
}
catch(const InvalidArgumentException &)
{
// nothing to do
}

}
catch (TestFailed & ex)
{
Expand Down
6 changes: 6 additions & 0 deletions python/test/t_KrigingAlgorithm_isotropic_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ def fitKriging(covarianceModel):
ott.assert_almost_equal(
krigingFittedCovarianceModel.getAmplitude()[0], 6.65231, 0.0, 1e-4
)

try:
ot.IsotropicCovarianceModel(ot.SquaredExponential(), 0)
raise ValueError("Invalid IsotropicCovarianceModel should have thrown")
except TypeError:
pass

0 comments on commit 5f62d30

Please sign in to comment.