Skip to content

Commit 44c91c9

Browse files
authored
Merge pull request #3084 from stan-dev/fix/gp_matern32-indexing-error
Fix index-out-of-bounds in gp_matern32_cov
2 parents 8a09048 + 59c9ac6 commit 44c91c9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

stan/math/prim/fun/gp_matern32_cov.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ gp_matern32_cov(const std::vector<Eigen::Matrix<T_x, -1, 1>> &x,
118118
return cov;
119119
}
120120
const char *function = "gp_matern32_cov";
121-
size_t l_size = length_scale.size();
122121
for (size_t n = 0; n < x_size; ++n) {
123122
check_not_nan(function, "x", x[n]);
124123
}
125124

126125
check_positive_finite(function, "magnitude", sigma);
127126
check_positive_finite(function, "length scale", length_scale);
128127

129-
for (size_t n = 0; n < x_size; ++n) {
128+
size_t l_size = length_scale.size();
129+
for (size_t n = 0; n < l_size; ++n) {
130130
check_not_nan(function, "length scale", length_scale[n]);
131131
}
132132

test/unit/math/prim/fun/gp_matern32_cov_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,12 @@ TEST(MathPrimMat, check_dim_mismatch_gp_matern32_cov) {
543543
EXPECT_THROW(stan::math::gp_matern32_cov(x1, x2, sig, l),
544544
std::invalid_argument);
545545
}
546+
547+
TEST(MathPrimMat, check_indexing_vector_vector_gp_matern32_cov) {
548+
int p = 1;
549+
int num_nodes = 10;
550+
std::vector<Eigen::Matrix<double, -1, 1>> x(num_nodes,
551+
stan::math::zeros_vector(p));
552+
EXPECT_NO_THROW(
553+
stan::math::gp_matern32_cov(x, 1.3, std::vector<double>{0.7}));
554+
}

0 commit comments

Comments
 (0)