Skip to content

Commit dcac15f

Browse files
committed
Incorrect domain restriction
1 parent bf8bbbc commit dcac15f

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

stan/math/prim/fun/hypergeometric_1F0.hpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#define STAN_MATH_PRIM_FUN_HYPERGEOMETRIC_1F0_HPP
33

44
#include <stan/math/prim/meta.hpp>
5+
#include <stan/math/prim/err/check_less.hpp>
56
#include <stan/math/prim/fun/boost_policy.hpp>
6-
#include <stan/math/prim/fun/floor.hpp>
77
#include <boost/math/special_functions/hypergeometric_1F0.hpp>
8+
#include <cmath>
89

910
namespace stan {
1011
namespace math {
@@ -28,16 +29,8 @@ namespace math {
2829
*/
2930
template <typename Ta, typename Tz, require_all_arithmetic_t<Ta, Tz>* = nullptr>
3031
auto hypergeometric_1f0(const Ta& a, const Tz& z) {
31-
bool condition_1 = z == 1.0;
32-
bool condition_2 = (1.0 - z < 0.0) && floor(a) != a;
33-
if (condition_1 || condition_2) {
34-
std::stringstream msg;
35-
msg << "Hypergeometric 1F0 is undefined when z == 1.0 or "
36-
<< "1 - z < 0 and a not an integer, but the following "
37-
<< "arguments provided: "
38-
<< "a: " << a << ", z: " << z << std::endl;
39-
throw std::domain_error(msg.str());
40-
}
32+
constexpr const char* function = "hypergeometric_1f0";
33+
check_less("hypergeometric_1f0", "abs(z)", std::abs(z), 1.0);
4134

4235
return boost::math::hypergeometric_1F0(a, z, boost_policy_t<>());
4336
}

test/unit/math/mix/fun/hypergeometric_1F0_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ TEST(mathMixScalFun, hypergeometric_1f0) {
66
return hypergeometric_1f0(x1, x2);
77
};
88

9-
stan::test::expect_ad(f, 0.5, 3.3);
9+
stan::test::expect_ad(f, 5, 0.3);
1010
stan::test::expect_ad(f, 3.4, 0.9);
11-
stan::test::expect_ad(f, 5.2, 6.7);
12-
stan::test::expect_ad(f, 7.5, 1.8);
11+
stan::test::expect_ad(f, 3.4, 0.1);
12+
stan::test::expect_ad(f, 5, -0.7);
13+
stan::test::expect_ad(f, 7, -0.1);
14+
stan::test::expect_ad(f, 2.8, 0.8);
1315
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ TEST(MathFunctions, hypergeometric_1f0Double) {
77
using stan::math::hypergeometric_1f0;
88
using stan::math::inv;
99

10-
EXPECT_FLOAT_EQ(-inv(27.0), hypergeometric_1f0(3, 4));
11-
EXPECT_FLOAT_EQ(inv(25.0), hypergeometric_1f0(2, -4.0));
12-
EXPECT_FLOAT_EQ(inv(65536), hypergeometric_1f0(16.0, 3));
13-
EXPECT_FLOAT_EQ(531441.0, hypergeometric_1f0(-6.0, 10.0));
10+
EXPECT_FLOAT_EQ(4.62962962963, hypergeometric_1f0(3, 0.4));
11+
EXPECT_FLOAT_EQ(0.510204081633, hypergeometric_1f0(2, -0.4));
12+
EXPECT_FLOAT_EQ(300.906354890, hypergeometric_1f0(16.0, 0.3));
13+
EXPECT_FLOAT_EQ(0.531441, hypergeometric_1f0(-6.0, 0.1));
1414
}
1515

1616
TEST(MathFunctions, hypergeometric_1f0_throw) {
1717
using stan::math::hypergeometric_1f0;
1818

1919
EXPECT_THROW(hypergeometric_1f0(2.1, 1.0), std::domain_error);
2020
EXPECT_THROW(hypergeometric_1f0(0.5, 1.5), std::domain_error);
21+
EXPECT_THROW(hypergeometric_1f0(0.5, -1.0), std::domain_error);
22+
EXPECT_THROW(hypergeometric_1f0(0.5, -1.5), std::domain_error);
2123
}

0 commit comments

Comments
 (0)