|
3 | 3 | #include <limits> |
4 | 4 | #include <vector> |
5 | 5 |
|
6 | | -template <typename T> |
7 | | -void expect_arith_instantiate() { |
8 | | - using stan::math::pow; |
9 | | - using std::pow; |
10 | | - auto a1 = pow(T(1.0), 1); |
11 | | - auto b1 = pow(T(1.0), 1.0); |
12 | | - auto c1 = pow(1, T(1.0)); |
13 | | - auto d1 = pow(1.0, T(1.0)); |
14 | | - auto e1 = pow(T(1.0), T(1.0)); |
15 | | - |
16 | | - auto a2 = pow(std::complex<T>(1.0), 1); |
17 | | - auto b2 = pow(std::complex<T>(1.0), 1.0); |
18 | | - auto c2 = pow(1, std::complex<T>(1.0)); |
19 | | - auto d2 = pow(1.0, std::complex<T>(1.0)); |
20 | | - auto e2 = pow(std::complex<T>(1.0), std::complex<T>(1.0)); |
21 | | - auto f2 = pow(std::complex<double>(1.0), std::complex<T>(1.0)); |
22 | | - auto g2 = pow(std::complex<T>(1.0), std::complex<double>(1.0)); |
23 | | -} |
24 | | - |
25 | | -// this one's been tricky to instantiate, so test all instances |
26 | | -TEST(mathMixScalFun, powInstantiations) { |
27 | | - using stan::math::fvar; |
28 | | - using stan::math::var; |
29 | | - expect_arith_instantiate<double>(); |
30 | | - expect_arith_instantiate<var>(); |
31 | | - expect_arith_instantiate<fvar<double>>(); |
32 | | - expect_arith_instantiate<fvar<fvar<double>>>(); |
33 | | - expect_arith_instantiate<fvar<var>>(); |
34 | | - expect_arith_instantiate<fvar<fvar<var>>>(); |
35 | | -} |
36 | | - |
37 | | -TEST(mathMixScalFun, pow) { |
38 | | - auto f = [](const auto& x1, const auto& x2) { |
39 | | - using stan::math::pow; |
40 | | - using std::pow; |
41 | | - return pow(x1, x2); |
42 | | - }; |
43 | | - stan::test::expect_ad(f, -0.4, 0.5); |
44 | | - stan::test::expect_ad(f, 0.5, 0.5); |
45 | | - stan::test::expect_ad(f, 0.5, 1.0); |
46 | | - stan::test::expect_ad(f, 0.5, 1.2); |
47 | | - stan::test::expect_ad(f, 0.5, 5.0); |
48 | | - stan::test::expect_ad(f, 1.0, 2.0); |
49 | | - stan::test::expect_ad(f, 3.0, 4.0); |
50 | | - for (double y = -2; y <= 4; y += 0.5) |
51 | | - stan::test::expect_ad(f, 4.0, y); |
52 | | - |
53 | | - double nan = std::numeric_limits<double>::quiet_NaN(); |
54 | | - stan::test::expect_ad(f, 1.0, nan); |
55 | | - stan::test::expect_ad(f, nan, 1.0); |
56 | | - stan::test::expect_ad(f, nan, nan); |
57 | | - |
58 | | - Eigen::VectorXd in1(3); |
59 | | - in1 << 0.5, 3.4, 5.2; |
60 | | - Eigen::VectorXd in2(3); |
61 | | - in2 << 3.3, 0.9, 6.7; |
62 | | - stan::test::expect_ad_vectorized_binary(f, in1, in2); |
63 | | -} |
64 | 6 | TEST(mathMixFun, complexPow) { |
65 | 7 | auto f = [](const auto& x1, const auto& x2) { |
66 | 8 | using stan::math::pow; |
|
0 commit comments