Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 1 | // This file is part of Eigen, a lightweight C++ template library |
Benoit Jacob | 6347b1d | 2009-05-22 20:25:33 +0200 | [diff] [blame] | 2 | // for linear algebra. |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 3 | // |
Gael Guennebaud | 28e64b0 | 2010-06-24 23:21:58 +0200 | [diff] [blame] | 4 | // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 5 | // |
Benoit Jacob | 69124cf | 2012-07-13 14:42:47 -0400 | [diff] [blame] | 6 | // This Source Code Form is subject to the terms of the Mozilla |
| 7 | // Public License v. 2.0. If a copy of the MPL was not distributed |
| 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
Gael Guennebaud | 19bc418 | 2013-02-25 01:17:44 +0100 | [diff] [blame] | 9 | |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 10 | #include "main.h" |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 11 | |
Rasmus Munk Larsen | cdd8fdc | 2021-01-18 13:25:16 +0000 | [diff] [blame] | 12 | |
| 13 | // Test the corner cases of pow(x, y) for real types. |
| 14 | template<typename Scalar> |
| 15 | void pow_test() { |
| 16 | const Scalar zero = Scalar(0); |
Rasmus Munk Larsen | be0574e | 2021-02-17 02:50:32 +0000 | [diff] [blame^] | 17 | const Scalar eps = std::numeric_limits<Scalar>::epsilon(); |
Rasmus Munk Larsen | cdd8fdc | 2021-01-18 13:25:16 +0000 | [diff] [blame] | 18 | const Scalar one = Scalar(1); |
Rasmus Munk Larsen | 6e3b795 | 2021-02-05 16:58:49 -0800 | [diff] [blame] | 19 | const Scalar two = Scalar(2); |
| 20 | const Scalar three = Scalar(3); |
Rasmus Munk Larsen | cdd8fdc | 2021-01-18 13:25:16 +0000 | [diff] [blame] | 21 | const Scalar sqrt_half = Scalar(std::sqrt(0.5)); |
| 22 | const Scalar sqrt2 = Scalar(std::sqrt(2)); |
| 23 | const Scalar inf = std::numeric_limits<Scalar>::infinity(); |
| 24 | const Scalar nan = std::numeric_limits<Scalar>::quiet_NaN(); |
Rasmus Munk Larsen | be0574e | 2021-02-17 02:50:32 +0000 | [diff] [blame^] | 25 | const Scalar denorm_min = std::numeric_limits<Scalar>::denorm_min(); |
Rasmus Munk Larsen | 6e3b795 | 2021-02-05 16:58:49 -0800 | [diff] [blame] | 26 | const Scalar min = (std::numeric_limits<Scalar>::min)(); |
| 27 | const Scalar max = (std::numeric_limits<Scalar>::max)(); |
Rasmus Munk Larsen | be0574e | 2021-02-17 02:50:32 +0000 | [diff] [blame^] | 28 | const Scalar max_exp = (static_cast<Scalar>(std::numeric_limits<Scalar>::max_exponent) * Scalar(EIGEN_LN2)) / eps; |
| 29 | |
Rasmus Munk Larsen | 6e3b795 | 2021-02-05 16:58:49 -0800 | [diff] [blame] | 30 | const static Scalar abs_vals[] = {zero, |
Rasmus Munk Larsen | be0574e | 2021-02-17 02:50:32 +0000 | [diff] [blame^] | 31 | denorm_min, |
| 32 | min, |
| 33 | eps, |
Rasmus Munk Larsen | 6e3b795 | 2021-02-05 16:58:49 -0800 | [diff] [blame] | 34 | sqrt_half, |
| 35 | one, |
| 36 | sqrt2, |
| 37 | two, |
| 38 | three, |
Rasmus Munk Larsen | be0574e | 2021-02-17 02:50:32 +0000 | [diff] [blame^] | 39 | max_exp, |
Rasmus Munk Larsen | 6e3b795 | 2021-02-05 16:58:49 -0800 | [diff] [blame] | 40 | max, |
| 41 | inf, |
| 42 | nan}; |
Rasmus Munk Larsen | be0574e | 2021-02-17 02:50:32 +0000 | [diff] [blame^] | 43 | const int abs_cases = 13; |
Rasmus Munk Larsen | cdd8fdc | 2021-01-18 13:25:16 +0000 | [diff] [blame] | 44 | const int num_cases = 2*abs_cases * 2*abs_cases; |
| 45 | // Repeat the same value to make sure we hit the vectorized path. |
| 46 | const int num_repeats = 32; |
| 47 | Array<Scalar, Dynamic, Dynamic> x(num_repeats, num_cases); |
| 48 | Array<Scalar, Dynamic, Dynamic> y(num_repeats, num_cases); |
Rasmus Munk Larsen | cdd8fdc | 2021-01-18 13:25:16 +0000 | [diff] [blame] | 49 | int count = 0; |
| 50 | for (int i = 0; i < abs_cases; ++i) { |
| 51 | const Scalar abs_x = abs_vals[i]; |
| 52 | for (int sign_x = 0; sign_x < 2; ++sign_x) { |
| 53 | Scalar x_case = sign_x == 0 ? -abs_x : abs_x; |
| 54 | for (int j = 0; j < abs_cases; ++j) { |
| 55 | const Scalar abs_y = abs_vals[j]; |
| 56 | for (int sign_y = 0; sign_y < 2; ++sign_y) { |
| 57 | Scalar y_case = sign_y == 0 ? -abs_y : abs_y; |
| 58 | for (int repeat = 0; repeat < num_repeats; ++repeat) { |
| 59 | x(repeat, count) = x_case; |
| 60 | y(repeat, count) = y_case; |
Rasmus Munk Larsen | cdd8fdc | 2021-01-18 13:25:16 +0000 | [diff] [blame] | 61 | } |
| 62 | ++count; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | Array<Scalar, Dynamic, Dynamic> actual = x.pow(y); |
| 69 | const Scalar tol = test_precision<Scalar>(); |
| 70 | bool all_pass = true; |
| 71 | for (int i = 0; i < 1; ++i) { |
| 72 | for (int j = 0; j < num_cases; ++j) { |
Rasmus Munk Larsen | be0574e | 2021-02-17 02:50:32 +0000 | [diff] [blame^] | 73 | Scalar e = static_cast<Scalar>(std::pow(x(i,j), y(i,j))); |
Rasmus Munk Larsen | cdd8fdc | 2021-01-18 13:25:16 +0000 | [diff] [blame] | 74 | Scalar a = actual(i, j); |
Antonio Sanchez | e0d13ea | 2021-01-23 11:02:35 -0800 | [diff] [blame] | 75 | bool fail = !(a==e) && !internal::isApprox(a, e, tol) && !((numext::isnan)(a) && (numext::isnan)(e)); |
Rasmus Munk Larsen | cdd8fdc | 2021-01-18 13:25:16 +0000 | [diff] [blame] | 76 | all_pass &= !fail; |
| 77 | if (fail) { |
| 78 | std::cout << "pow(" << x(i,j) << "," << y(i,j) << ") = " << a << " != " << e << std::endl; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | VERIFY(all_pass); |
| 83 | } |
| 84 | |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 85 | template<typename ArrayType> void array(const ArrayType& m) |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 86 | { |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 87 | typedef typename ArrayType::Scalar Scalar; |
Gael Guennebaud | d476cad | 2016-06-25 10:12:06 +0200 | [diff] [blame] | 88 | typedef typename ArrayType::RealScalar RealScalar; |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 89 | typedef Array<Scalar, ArrayType::RowsAtCompileTime, 1> ColVectorType; |
| 90 | typedef Array<Scalar, 1, ArrayType::ColsAtCompileTime> RowVectorType; |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 91 | |
Hauke Heibel | f1679c7 | 2010-06-20 17:37:56 +0200 | [diff] [blame] | 92 | Index rows = m.rows(); |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 93 | Index cols = m.cols(); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 94 | |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 95 | ArrayType m1 = ArrayType::Random(rows, cols), |
| 96 | m2 = ArrayType::Random(rows, cols), |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 97 | m3(rows, cols); |
Christoph Hertzberg | 3be9f5c | 2015-04-16 13:25:20 +0200 | [diff] [blame] | 98 | ArrayType m4 = m1; // copy constructor |
| 99 | VERIFY_IS_APPROX(m1, m4); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 100 | |
Gael Guennebaud | 627595a | 2009-06-10 11:20:30 +0200 | [diff] [blame] | 101 | ColVectorType cv1 = ColVectorType::Random(rows); |
| 102 | RowVectorType rv1 = RowVectorType::Random(cols); |
| 103 | |
Benoit Jacob | 4716040 | 2010-10-25 10:15:22 -0400 | [diff] [blame] | 104 | Scalar s1 = internal::random<Scalar>(), |
Hauke Heibel | 8cb3e36 | 2012-03-02 16:27:27 +0100 | [diff] [blame] | 105 | s2 = internal::random<Scalar>(); |
| 106 | |
Gael Guennebaud | 59dc1da | 2008-09-03 17:16:28 +0000 | [diff] [blame] | 107 | // scalar addition |
Gael Guennebaud | c70d542 | 2010-01-18 22:54:20 +0100 | [diff] [blame] | 108 | VERIFY_IS_APPROX(m1 + s1, s1 + m1); |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 109 | VERIFY_IS_APPROX(m1 + s1, ArrayType::Constant(rows,cols,s1) + m1); |
Gael Guennebaud | c70d542 | 2010-01-18 22:54:20 +0100 | [diff] [blame] | 110 | VERIFY_IS_APPROX(s1 - m1, (-m1)+s1 ); |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 111 | VERIFY_IS_APPROX(m1 - s1, m1 - ArrayType::Constant(rows,cols,s1)); |
| 112 | VERIFY_IS_APPROX(s1 - m1, ArrayType::Constant(rows,cols,s1) - m1); |
| 113 | VERIFY_IS_APPROX((m1*Scalar(2)) - s2, (m1+m1) - ArrayType::Constant(rows,cols,s2) ); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 114 | m3 = m1; |
Gael Guennebaud | c70d542 | 2010-01-18 22:54:20 +0100 | [diff] [blame] | 115 | m3 += s2; |
| 116 | VERIFY_IS_APPROX(m3, m1 + s2); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 117 | m3 = m1; |
Gael Guennebaud | c70d542 | 2010-01-18 22:54:20 +0100 | [diff] [blame] | 118 | m3 -= s1; |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 119 | VERIFY_IS_APPROX(m3, m1 - s1); |
| 120 | |
Hauke Heibel | f578dc7 | 2010-12-16 17:34:13 +0100 | [diff] [blame] | 121 | // scalar operators via Maps |
| 122 | m3 = m1; |
| 123 | ArrayType::Map(m1.data(), m1.rows(), m1.cols()) -= ArrayType::Map(m2.data(), m2.rows(), m2.cols()); |
| 124 | VERIFY_IS_APPROX(m1, m3 - m2); |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 125 | |
Hauke Heibel | f578dc7 | 2010-12-16 17:34:13 +0100 | [diff] [blame] | 126 | m3 = m1; |
| 127 | ArrayType::Map(m1.data(), m1.rows(), m1.cols()) += ArrayType::Map(m2.data(), m2.rows(), m2.cols()); |
| 128 | VERIFY_IS_APPROX(m1, m3 + m2); |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 129 | |
Hauke Heibel | f578dc7 | 2010-12-16 17:34:13 +0100 | [diff] [blame] | 130 | m3 = m1; |
| 131 | ArrayType::Map(m1.data(), m1.rows(), m1.cols()) *= ArrayType::Map(m2.data(), m2.rows(), m2.cols()); |
| 132 | VERIFY_IS_APPROX(m1, m3 * m2); |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 133 | |
Hauke Heibel | f578dc7 | 2010-12-16 17:34:13 +0100 | [diff] [blame] | 134 | m3 = m1; |
| 135 | m2 = ArrayType::Random(rows,cols); |
| 136 | m2 = (m2==0).select(1,m2); |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 137 | ArrayType::Map(m1.data(), m1.rows(), m1.cols()) /= ArrayType::Map(m2.data(), m2.rows(), m2.cols()); |
Hauke Heibel | f578dc7 | 2010-12-16 17:34:13 +0100 | [diff] [blame] | 138 | VERIFY_IS_APPROX(m1, m3 / m2); |
Gael Guennebaud | 05ad083 | 2008-07-19 13:03:23 +0000 | [diff] [blame] | 139 | |
Gael Guennebaud | 59dc1da | 2008-09-03 17:16:28 +0000 | [diff] [blame] | 140 | // reductions |
Gael Guennebaud | 42af587 | 2013-02-23 22:58:14 +0100 | [diff] [blame] | 141 | VERIFY_IS_APPROX(m1.abs().colwise().sum().sum(), m1.abs().sum()); |
| 142 | VERIFY_IS_APPROX(m1.abs().rowwise().sum().sum(), m1.abs().sum()); |
| 143 | using std::abs; |
| 144 | VERIFY_IS_MUCH_SMALLER_THAN(abs(m1.colwise().sum().sum() - m1.sum()), m1.abs().sum()); |
| 145 | VERIFY_IS_MUCH_SMALLER_THAN(abs(m1.rowwise().sum().sum() - m1.sum()), m1.abs().sum()); |
Gael Guennebaud | 28e139a | 2013-02-23 23:06:45 +0100 | [diff] [blame] | 146 | if (!internal::isMuchSmallerThan(abs(m1.sum() - (m1+m2).sum()), m1.abs().sum(), test_precision<Scalar>())) |
Hauke Heibel | 83e3c45 | 2010-12-16 18:53:02 +0100 | [diff] [blame] | 147 | VERIFY_IS_NOT_APPROX(((m1+m2).rowwise().sum()).sum(), m1.sum()); |
Gael Guennebaud | 66e99ab | 2016-06-06 15:11:41 +0200 | [diff] [blame] | 148 | VERIFY_IS_APPROX(m1.colwise().sum(), m1.colwise().redux(internal::scalar_sum_op<Scalar,Scalar>())); |
Gael Guennebaud | 627595a | 2009-06-10 11:20:30 +0200 | [diff] [blame] | 149 | |
| 150 | // vector-wise ops |
| 151 | m3 = m1; |
| 152 | VERIFY_IS_APPROX(m3.colwise() += cv1, m1.colwise() + cv1); |
| 153 | m3 = m1; |
| 154 | VERIFY_IS_APPROX(m3.colwise() -= cv1, m1.colwise() - cv1); |
| 155 | m3 = m1; |
| 156 | VERIFY_IS_APPROX(m3.rowwise() += rv1, m1.rowwise() + rv1); |
| 157 | m3 = m1; |
| 158 | VERIFY_IS_APPROX(m3.rowwise() -= rv1, m1.rowwise() - rv1); |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 159 | |
Gael Guennebaud | 0a18eec | 2014-09-19 13:25:28 +0200 | [diff] [blame] | 160 | // Conversion from scalar |
| 161 | VERIFY_IS_APPROX((m3 = s1), ArrayType::Constant(rows,cols,s1)); |
| 162 | VERIFY_IS_APPROX((m3 = 1), ArrayType::Constant(rows,cols,1)); |
| 163 | VERIFY_IS_APPROX((m3.topLeftCorner(rows,cols) = 1), ArrayType::Constant(rows,cols,1)); |
| 164 | typedef Array<Scalar, |
| 165 | ArrayType::RowsAtCompileTime==Dynamic?2:ArrayType::RowsAtCompileTime, |
| 166 | ArrayType::ColsAtCompileTime==Dynamic?2:ArrayType::ColsAtCompileTime, |
| 167 | ArrayType::Options> FixedArrayType; |
Gael Guennebaud | 543529d | 2019-01-22 15:30:50 +0100 | [diff] [blame] | 168 | { |
| 169 | FixedArrayType f1(s1); |
| 170 | VERIFY_IS_APPROX(f1, FixedArrayType::Constant(s1)); |
| 171 | FixedArrayType f2(numext::real(s1)); |
| 172 | VERIFY_IS_APPROX(f2, FixedArrayType::Constant(numext::real(s1))); |
| 173 | FixedArrayType f3((int)100*numext::real(s1)); |
| 174 | VERIFY_IS_APPROX(f3, FixedArrayType::Constant((int)100*numext::real(s1))); |
| 175 | f1.setRandom(); |
| 176 | FixedArrayType f4(f1.data()); |
| 177 | VERIFY_IS_APPROX(f4, f1); |
| 178 | } |
| 179 | #if EIGEN_HAS_CXX11 |
| 180 | { |
| 181 | FixedArrayType f1{s1}; |
| 182 | VERIFY_IS_APPROX(f1, FixedArrayType::Constant(s1)); |
| 183 | FixedArrayType f2{numext::real(s1)}; |
| 184 | VERIFY_IS_APPROX(f2, FixedArrayType::Constant(numext::real(s1))); |
| 185 | FixedArrayType f3{(int)100*numext::real(s1)}; |
| 186 | VERIFY_IS_APPROX(f3, FixedArrayType::Constant((int)100*numext::real(s1))); |
| 187 | f1.setRandom(); |
| 188 | FixedArrayType f4{f1.data()}; |
| 189 | VERIFY_IS_APPROX(f4, f1); |
| 190 | } |
| 191 | #endif |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 192 | |
Gael Guennebaud | d476cad | 2016-06-25 10:12:06 +0200 | [diff] [blame] | 193 | // pow |
| 194 | VERIFY_IS_APPROX(m1.pow(2), m1.square()); |
| 195 | VERIFY_IS_APPROX(pow(m1,2), m1.square()); |
| 196 | VERIFY_IS_APPROX(m1.pow(3), m1.cube()); |
| 197 | VERIFY_IS_APPROX(pow(m1,3), m1.cube()); |
| 198 | VERIFY_IS_APPROX((-m1).pow(3), -m1.cube()); |
| 199 | VERIFY_IS_APPROX(pow(2*m1,3), 8*m1.cube()); |
| 200 | ArrayType exponents = ArrayType::Constant(rows, cols, RealScalar(2)); |
| 201 | VERIFY_IS_APPROX(Eigen::pow(m1,exponents), m1.square()); |
| 202 | VERIFY_IS_APPROX(m1.pow(exponents), m1.square()); |
| 203 | VERIFY_IS_APPROX(Eigen::pow(2*m1,exponents), 4*m1.square()); |
| 204 | VERIFY_IS_APPROX((2*m1).pow(exponents), 4*m1.square()); |
| 205 | VERIFY_IS_APPROX(Eigen::pow(m1,2*exponents), m1.square().square()); |
| 206 | VERIFY_IS_APPROX(m1.pow(2*exponents), m1.square().square()); |
Gael Guennebaud | e61cee7 | 2016-07-04 11:49:03 +0200 | [diff] [blame] | 207 | VERIFY_IS_APPROX(Eigen::pow(m1(0,0), exponents), ArrayType::Constant(rows,cols,m1(0,0)*m1(0,0))); |
Gael Guennebaud | d476cad | 2016-06-25 10:12:06 +0200 | [diff] [blame] | 208 | |
Gael Guennebaud | 0a18eec | 2014-09-19 13:25:28 +0200 | [diff] [blame] | 209 | // Check possible conflicts with 1D ctor |
| 210 | typedef Array<Scalar, Dynamic, 1> OneDArrayType; |
Gael Guennebaud | 543529d | 2019-01-22 15:30:50 +0100 | [diff] [blame] | 211 | { |
| 212 | OneDArrayType o1(rows); |
| 213 | VERIFY(o1.size()==rows); |
| 214 | OneDArrayType o2(static_cast<int>(rows)); |
| 215 | VERIFY(o2.size()==rows); |
| 216 | } |
| 217 | #if EIGEN_HAS_CXX11 |
| 218 | { |
| 219 | OneDArrayType o1{rows}; |
| 220 | VERIFY(o1.size()==rows); |
| 221 | OneDArrayType o4{int(rows)}; |
| 222 | VERIFY(o4.size()==rows); |
| 223 | } |
| 224 | #endif |
| 225 | // Check possible conflicts with 2D ctor |
| 226 | typedef Array<Scalar, Dynamic, Dynamic> TwoDArrayType; |
| 227 | typedef Array<Scalar, 2, 1> ArrayType2; |
| 228 | { |
| 229 | TwoDArrayType o1(rows,cols); |
| 230 | VERIFY(o1.rows()==rows); |
| 231 | VERIFY(o1.cols()==cols); |
| 232 | TwoDArrayType o2(static_cast<int>(rows),static_cast<int>(cols)); |
| 233 | VERIFY(o2.rows()==rows); |
| 234 | VERIFY(o2.cols()==cols); |
| 235 | |
| 236 | ArrayType2 o3(rows,cols); |
| 237 | VERIFY(o3(0)==Scalar(rows) && o3(1)==Scalar(cols)); |
| 238 | ArrayType2 o4(static_cast<int>(rows),static_cast<int>(cols)); |
| 239 | VERIFY(o4(0)==Scalar(rows) && o4(1)==Scalar(cols)); |
| 240 | } |
| 241 | #if EIGEN_HAS_CXX11 |
| 242 | { |
| 243 | TwoDArrayType o1{rows,cols}; |
| 244 | VERIFY(o1.rows()==rows); |
| 245 | VERIFY(o1.cols()==cols); |
| 246 | TwoDArrayType o2{int(rows),int(cols)}; |
| 247 | VERIFY(o2.rows()==rows); |
| 248 | VERIFY(o2.cols()==cols); |
| 249 | |
| 250 | ArrayType2 o3{rows,cols}; |
| 251 | VERIFY(o3(0)==Scalar(rows) && o3(1)==Scalar(cols)); |
| 252 | ArrayType2 o4{int(rows),int(cols)}; |
| 253 | VERIFY(o4(0)==Scalar(rows) && o4(1)==Scalar(cols)); |
| 254 | } |
| 255 | #endif |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 258 | template<typename ArrayType> void comparisons(const ArrayType& m) |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 259 | { |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 260 | using std::abs; |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 261 | typedef typename ArrayType::Scalar Scalar; |
Benoit Jacob | 874ff5a | 2009-01-26 17:56:04 +0000 | [diff] [blame] | 262 | typedef typename NumTraits<Scalar>::Real RealScalar; |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 263 | |
Hauke Heibel | f1679c7 | 2010-06-20 17:37:56 +0200 | [diff] [blame] | 264 | Index rows = m.rows(); |
| 265 | Index cols = m.cols(); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 266 | |
Benoit Jacob | 4716040 | 2010-10-25 10:15:22 -0400 | [diff] [blame] | 267 | Index r = internal::random<Index>(0, rows-1), |
| 268 | c = internal::random<Index>(0, cols-1); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 269 | |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 270 | ArrayType m1 = ArrayType::Random(rows, cols), |
Gael Guennebaud | 9fc1c92 | 2015-06-22 16:48:27 +0200 | [diff] [blame] | 271 | m2 = ArrayType::Random(rows, cols), |
| 272 | m3(rows, cols), |
| 273 | m4 = m1; |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 274 | |
Gael Guennebaud | 9fc1c92 | 2015-06-22 16:48:27 +0200 | [diff] [blame] | 275 | m4 = (m4.abs()==Scalar(0)).select(1,m4); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 276 | |
Gael Guennebaud | c70d542 | 2010-01-18 22:54:20 +0100 | [diff] [blame] | 277 | VERIFY(((m1 + Scalar(1)) > m1).all()); |
| 278 | VERIFY(((m1 - Scalar(1)) < m1).all()); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 279 | if (rows*cols>1) |
| 280 | { |
| 281 | m3 = m1; |
| 282 | m3(r,c) += 1; |
Gael Guennebaud | c70d542 | 2010-01-18 22:54:20 +0100 | [diff] [blame] | 283 | VERIFY(! (m1 < m3).all() ); |
| 284 | VERIFY(! (m1 > m3).all() ); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 285 | } |
Christoph Hertzberg | 494fa99 | 2015-05-07 17:28:40 +0200 | [diff] [blame] | 286 | VERIFY(!(m1 > m2 && m1 < m2).any()); |
| 287 | VERIFY((m1 <= m2 || m1 >= m2).all()); |
Gael Guennebaud | 627595a | 2009-06-10 11:20:30 +0200 | [diff] [blame] | 288 | |
Christoph Hertzberg | 36052c4 | 2013-10-17 15:37:29 +0200 | [diff] [blame] | 289 | // comparisons array to scalar |
Gael Guennebaud | c70d542 | 2010-01-18 22:54:20 +0100 | [diff] [blame] | 290 | VERIFY( (m1 != (m1(r,c)+1) ).any() ); |
Christoph Hertzberg | 36052c4 | 2013-10-17 15:37:29 +0200 | [diff] [blame] | 291 | VERIFY( (m1 > (m1(r,c)-1) ).any() ); |
| 292 | VERIFY( (m1 < (m1(r,c)+1) ).any() ); |
| 293 | VERIFY( (m1 == m1(r,c) ).any() ); |
| 294 | |
| 295 | // comparisons scalar to array |
| 296 | VERIFY( ( (m1(r,c)+1) != m1).any() ); |
| 297 | VERIFY( ( (m1(r,c)-1) < m1).any() ); |
| 298 | VERIFY( ( (m1(r,c)+1) > m1).any() ); |
| 299 | VERIFY( ( m1(r,c) == m1).any() ); |
Gael Guennebaud | 627595a | 2009-06-10 11:20:30 +0200 | [diff] [blame] | 300 | |
Gael Guennebaud | 59dc1da | 2008-09-03 17:16:28 +0000 | [diff] [blame] | 301 | // test Select |
Gael Guennebaud | c70d542 | 2010-01-18 22:54:20 +0100 | [diff] [blame] | 302 | VERIFY_IS_APPROX( (m1<m2).select(m1,m2), m1.cwiseMin(m2) ); |
| 303 | VERIFY_IS_APPROX( (m1>m2).select(m1,m2), m1.cwiseMax(m2) ); |
Gael Guennebaud | 9f79558 | 2009-12-16 19:18:40 +0100 | [diff] [blame] | 304 | Scalar mid = (m1.cwiseAbs().minCoeff() + m1.cwiseAbs().maxCoeff())/Scalar(2); |
Gael Guennebaud | 59dc1da | 2008-09-03 17:16:28 +0000 | [diff] [blame] | 305 | for (int j=0; j<cols; ++j) |
| 306 | for (int i=0; i<rows; ++i) |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 307 | m3(i,j) = abs(m1(i,j))<mid ? 0 : m1(i,j); |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 308 | VERIFY_IS_APPROX( (m1.abs()<ArrayType::Constant(rows,cols,mid)) |
| 309 | .select(ArrayType::Zero(rows,cols),m1), m3); |
Gael Guennebaud | e14aa8c | 2008-09-03 17:56:06 +0000 | [diff] [blame] | 310 | // shorter versions: |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 311 | VERIFY_IS_APPROX( (m1.abs()<ArrayType::Constant(rows,cols,mid)) |
Gael Guennebaud | 59dc1da | 2008-09-03 17:16:28 +0000 | [diff] [blame] | 312 | .select(0,m1), m3); |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 313 | VERIFY_IS_APPROX( (m1.abs()>=ArrayType::Constant(rows,cols,mid)) |
Gael Guennebaud | 59dc1da | 2008-09-03 17:16:28 +0000 | [diff] [blame] | 314 | .select(m1,0), m3); |
Gael Guennebaud | e14aa8c | 2008-09-03 17:56:06 +0000 | [diff] [blame] | 315 | // even shorter version: |
Gael Guennebaud | c70d542 | 2010-01-18 22:54:20 +0100 | [diff] [blame] | 316 | VERIFY_IS_APPROX( (m1.abs()<mid).select(0,m1), m3); |
Gael Guennebaud | 627595a | 2009-06-10 11:20:30 +0200 | [diff] [blame] | 317 | |
Gael Guennebaud | 56c7e16 | 2009-01-24 15:22:44 +0000 | [diff] [blame] | 318 | // count |
Gael Guennebaud | c70d542 | 2010-01-18 22:54:20 +0100 | [diff] [blame] | 319 | VERIFY(((m1.abs()+1)>RealScalar(0.1)).count() == rows*cols); |
Benoit Jacob | aaaade4 | 2010-05-30 16:00:58 -0400 | [diff] [blame] | 320 | |
Gael Guennebaud | 35c1158 | 2011-05-31 22:17:34 +0200 | [diff] [blame] | 321 | // and/or |
| 322 | VERIFY( (m1<RealScalar(0) && m1>RealScalar(0)).count() == 0); |
| 323 | VERIFY( (m1<RealScalar(0) || m1>=RealScalar(0)).count() == rows*cols); |
| 324 | RealScalar a = m1.abs().mean(); |
| 325 | VERIFY( (m1<-a || m1>a).count() == (m1.abs()>a).count()); |
| 326 | |
Gael Guennebaud | 12e1ebb | 2018-07-12 17:16:40 +0200 | [diff] [blame] | 327 | typedef Array<Index, Dynamic, 1> ArrayOfIndices; |
Gael Guennebaud | 4ebb804 | 2010-06-02 09:45:57 +0200 | [diff] [blame] | 328 | |
Gael Guennebaud | 9f79558 | 2009-12-16 19:18:40 +0100 | [diff] [blame] | 329 | // TODO allows colwise/rowwise for array |
Benoit Jacob | aaaade4 | 2010-05-30 16:00:58 -0400 | [diff] [blame] | 330 | VERIFY_IS_APPROX(((m1.abs()+1)>RealScalar(0.1)).colwise().count(), ArrayOfIndices::Constant(cols,rows).transpose()); |
| 331 | VERIFY_IS_APPROX(((m1.abs()+1)>RealScalar(0.1)).rowwise().count(), ArrayOfIndices::Constant(rows, cols)); |
Benoit Jacob | e800999 | 2008-11-03 22:47:00 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 334 | template<typename ArrayType> void array_real(const ArrayType& m) |
Gael Guennebaud | 0ce5bc0 | 2010-01-27 23:23:59 +0100 | [diff] [blame] | 335 | { |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 336 | using std::abs; |
Gael Guennebaud | 9b9177f | 2013-07-05 13:35:34 +0200 | [diff] [blame] | 337 | using std::sqrt; |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 338 | typedef typename ArrayType::Scalar Scalar; |
Gael Guennebaud | 0ce5bc0 | 2010-01-27 23:23:59 +0100 | [diff] [blame] | 339 | typedef typename NumTraits<Scalar>::Real RealScalar; |
| 340 | |
Hauke Heibel | f1679c7 | 2010-06-20 17:37:56 +0200 | [diff] [blame] | 341 | Index rows = m.rows(); |
| 342 | Index cols = m.cols(); |
Gael Guennebaud | 0ce5bc0 | 2010-01-27 23:23:59 +0100 | [diff] [blame] | 343 | |
Benoit Jacob | e277586 | 2010-04-28 18:51:38 -0400 | [diff] [blame] | 344 | ArrayType m1 = ArrayType::Random(rows, cols), |
Gael Guennebaud | c695cbf | 2013-06-24 13:33:44 +0200 | [diff] [blame] | 345 | m2 = ArrayType::Random(rows, cols), |
Gael Guennebaud | 9fc1c92 | 2015-06-22 16:48:27 +0200 | [diff] [blame] | 346 | m3(rows, cols), |
| 347 | m4 = m1; |
Benoit Steiner | 8314962 | 2015-12-10 13:13:45 -0800 | [diff] [blame] | 348 | |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 349 | m4 = (m4.abs()==Scalar(0)).select(Scalar(1),m4); |
Gael Guennebaud | 0ce5bc0 | 2010-01-27 23:23:59 +0100 | [diff] [blame] | 350 | |
Gael Guennebaud | 9b1ad5e | 2012-03-09 12:08:06 +0100 | [diff] [blame] | 351 | Scalar s1 = internal::random<Scalar>(); |
| 352 | |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 353 | // these tests are mostly to check possible compilation issues with free-functions. |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 354 | VERIFY_IS_APPROX(m1.sin(), sin(m1)); |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 355 | VERIFY_IS_APPROX(m1.cos(), cos(m1)); |
Deanna Hood | f89fcef | 2015-03-11 13:13:30 +1000 | [diff] [blame] | 356 | VERIFY_IS_APPROX(m1.tan(), tan(m1)); |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 357 | VERIFY_IS_APPROX(m1.asin(), asin(m1)); |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 358 | VERIFY_IS_APPROX(m1.acos(), acos(m1)); |
Jitse Niesen | de150b1 | 2014-06-19 15:12:33 +0100 | [diff] [blame] | 359 | VERIFY_IS_APPROX(m1.atan(), atan(m1)); |
Deanna Hood | f89fcef | 2015-03-11 13:13:30 +1000 | [diff] [blame] | 360 | VERIFY_IS_APPROX(m1.sinh(), sinh(m1)); |
| 361 | VERIFY_IS_APPROX(m1.cosh(), cosh(m1)); |
| 362 | VERIFY_IS_APPROX(m1.tanh(), tanh(m1)); |
Rasmus Munk Larsen | 28ba1b2 | 2019-01-11 17:45:37 -0800 | [diff] [blame] | 363 | #if EIGEN_HAS_CXX11_MATH |
| 364 | VERIFY_IS_APPROX(m1.tanh().atanh(), atanh(tanh(m1))); |
| 365 | VERIFY_IS_APPROX(m1.sinh().asinh(), asinh(sinh(m1))); |
| 366 | VERIFY_IS_APPROX(m1.cosh().acosh(), acosh(cosh(m1))); |
| 367 | #endif |
Rasmus Munk Larsen | d6e283b | 2018-08-13 11:14:50 -0700 | [diff] [blame] | 368 | VERIFY_IS_APPROX(m1.logistic(), logistic(m1)); |
Gael Guennebaud | 2f7e261 | 2016-07-08 11:13:55 +0200 | [diff] [blame] | 369 | |
Deanna Hood | a5e4997 | 2015-03-11 08:56:42 +1000 | [diff] [blame] | 370 | VERIFY_IS_APPROX(m1.arg(), arg(m1)); |
Deanna Hood | 31fdd67 | 2015-03-11 06:39:23 +1000 | [diff] [blame] | 371 | VERIFY_IS_APPROX(m1.round(), round(m1)); |
Ilya Tokar | 19876ce | 2019-12-16 16:00:35 -0500 | [diff] [blame] | 372 | VERIFY_IS_APPROX(m1.rint(), rint(m1)); |
Deanna Hood | 31fdd67 | 2015-03-11 06:39:23 +1000 | [diff] [blame] | 373 | VERIFY_IS_APPROX(m1.floor(), floor(m1)); |
| 374 | VERIFY_IS_APPROX(m1.ceil(), ceil(m1)); |
Christoph Hertzberg | 61e0977 | 2015-08-14 17:32:34 +0200 | [diff] [blame] | 375 | VERIFY((m1.isNaN() == (Eigen::isnan)(m1)).all()); |
| 376 | VERIFY((m1.isInf() == (Eigen::isinf)(m1)).all()); |
| 377 | VERIFY((m1.isFinite() == (Eigen::isfinite)(m1)).all()); |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 378 | VERIFY_IS_APPROX(m4.inverse(), inverse(m4)); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 379 | VERIFY_IS_APPROX(m1.abs(), abs(m1)); |
| 380 | VERIFY_IS_APPROX(m1.abs2(), abs2(m1)); |
| 381 | VERIFY_IS_APPROX(m1.square(), square(m1)); |
| 382 | VERIFY_IS_APPROX(m1.cube(), cube(m1)); |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 383 | VERIFY_IS_APPROX(cos(m1+RealScalar(3)*m2), cos((m1+RealScalar(3)*m2).eval())); |
Gael Guennebaud | 3f32f5e | 2015-11-27 16:27:53 +0100 | [diff] [blame] | 384 | VERIFY_IS_APPROX(m1.sign(), sign(m1)); |
Rasmus Munk Larsen | 6964ae8 | 2020-07-07 01:54:04 +0000 | [diff] [blame] | 385 | VERIFY((m1.sqrt().sign().isNaN() == (Eigen::isnan)(sign(sqrt(m1)))).all()); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 386 | |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 387 | // avoid inf and NaNs so verification doesn't fail |
| 388 | m3 = m4.abs(); |
| 389 | VERIFY_IS_APPROX(m3.sqrt(), sqrt(abs(m3))); |
| 390 | VERIFY_IS_APPROX(m3.rsqrt(), Scalar(1)/sqrt(abs(m3))); |
| 391 | VERIFY_IS_APPROX(rsqrt(m3), Scalar(1)/sqrt(abs(m3))); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 392 | VERIFY_IS_APPROX(m3.log(), log(m3)); |
Gael Guennebaud | 89099b0 | 2016-06-01 17:00:08 +0200 | [diff] [blame] | 393 | VERIFY_IS_APPROX(m3.log1p(), log1p(m3)); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 394 | VERIFY_IS_APPROX(m3.log10(), log10(m3)); |
Rasmus Munk Larsen | f9fac1d | 2020-12-04 21:45:09 +0000 | [diff] [blame] | 395 | VERIFY_IS_APPROX(m3.log2(), log2(m3)); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 396 | |
| 397 | |
| 398 | VERIFY((!(m1>m2) == (m1<=m2)).all()); |
| 399 | |
| 400 | VERIFY_IS_APPROX(sin(m1.asin()), m1); |
| 401 | VERIFY_IS_APPROX(cos(m1.acos()), m1); |
| 402 | VERIFY_IS_APPROX(tan(m1.atan()), m1); |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 403 | VERIFY_IS_APPROX(sinh(m1), Scalar(0.5)*(exp(m1)-exp(-m1))); |
| 404 | VERIFY_IS_APPROX(cosh(m1), Scalar(0.5)*(exp(m1)+exp(-m1))); |
| 405 | VERIFY_IS_APPROX(tanh(m1), (Scalar(0.5)*(exp(m1)-exp(-m1)))/(Scalar(0.5)*(exp(m1)+exp(-m1)))); |
| 406 | VERIFY_IS_APPROX(logistic(m1), (Scalar(1)/(Scalar(1)+exp(-m1)))); |
| 407 | VERIFY_IS_APPROX(arg(m1), ((m1<Scalar(0)).template cast<Scalar>())*Scalar(std::acos(Scalar(-1)))); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 408 | VERIFY((round(m1) <= ceil(m1) && round(m1) >= floor(m1)).all()); |
Ilya Tokar | 19876ce | 2019-12-16 16:00:35 -0500 | [diff] [blame] | 409 | VERIFY((rint(m1) <= ceil(m1) && rint(m1) >= floor(m1)).all()); |
| 410 | VERIFY(((ceil(m1) - round(m1)) <= Scalar(0.5) || (round(m1) - floor(m1)) <= Scalar(0.5)).all()); |
| 411 | VERIFY(((ceil(m1) - round(m1)) <= Scalar(1.0) && (round(m1) - floor(m1)) <= Scalar(1.0)).all()); |
| 412 | VERIFY(((ceil(m1) - rint(m1)) <= Scalar(0.5) || (rint(m1) - floor(m1)) <= Scalar(0.5)).all()); |
| 413 | VERIFY(((ceil(m1) - rint(m1)) <= Scalar(1.0) && (rint(m1) - floor(m1)) <= Scalar(1.0)).all()); |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 414 | VERIFY((Eigen::isnan)((m1*Scalar(0))/Scalar(0)).all()); |
| 415 | VERIFY((Eigen::isinf)(m4/Scalar(0)).all()); |
| 416 | VERIFY(((Eigen::isfinite)(m1) && (!(Eigen::isfinite)(m1*Scalar(0)/Scalar(0))) && (!(Eigen::isfinite)(m4/Scalar(0)))).all()); |
| 417 | VERIFY_IS_APPROX(inverse(inverse(m4)),m4); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 418 | VERIFY((abs(m1) == m1 || abs(m1) == -m1).all()); |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 419 | VERIFY_IS_APPROX(m3, sqrt(abs2(m3))); |
Joel Holdsworth | d5c6657 | 2020-03-19 17:45:20 +0000 | [diff] [blame] | 420 | VERIFY_IS_APPROX(m1.absolute_difference(m2), (m1 > m2).select(m1 - m2, m2 - m1)); |
Gael Guennebaud | 3f32f5e | 2015-11-27 16:27:53 +0100 | [diff] [blame] | 421 | VERIFY_IS_APPROX( m1.sign(), -(-m1).sign() ); |
| 422 | VERIFY_IS_APPROX( m1*m1.sign(),m1.abs()); |
| 423 | VERIFY_IS_APPROX(m1.sign() * m1.abs(), m1); |
Benoit Jacob | 5d63d2c | 2010-04-28 22:42:34 -0400 | [diff] [blame] | 424 | |
Gael Guennebaud | 62670c8 | 2013-06-10 23:40:56 +0200 | [diff] [blame] | 425 | VERIFY_IS_APPROX(numext::abs2(numext::real(m1)) + numext::abs2(numext::imag(m1)), numext::abs2(m1)); |
Gael Guennebaud | 87427d2 | 2019-10-08 09:15:17 +0200 | [diff] [blame] | 426 | VERIFY_IS_APPROX(numext::abs2(Eigen::real(m1)) + numext::abs2(Eigen::imag(m1)), numext::abs2(m1)); |
Benoit Jacob | 5d63d2c | 2010-04-28 22:42:34 -0400 | [diff] [blame] | 427 | if(!NumTraits<Scalar>::IsComplex) |
Gael Guennebaud | 62670c8 | 2013-06-10 23:40:56 +0200 | [diff] [blame] | 428 | VERIFY_IS_APPROX(numext::real(m1), m1); |
Gael Guennebaud | 4ebb804 | 2010-06-02 09:45:57 +0200 | [diff] [blame] | 429 | |
Jitse Niesen | 6fecb6f | 2014-02-24 14:10:17 +0000 | [diff] [blame] | 430 | // shift argument of logarithm so that it is not zero |
| 431 | Scalar smallNumber = NumTraits<Scalar>::dummy_precision(); |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 432 | VERIFY_IS_APPROX((m3 + smallNumber).log() , log(abs(m3) + smallNumber)); |
| 433 | VERIFY_IS_APPROX((m3 + smallNumber + Scalar(1)).log() , log1p(abs(m3) + smallNumber)); |
Gael Guennebaud | 4ebb804 | 2010-06-02 09:45:57 +0200 | [diff] [blame] | 434 | |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 435 | VERIFY_IS_APPROX(m1.exp() * m2.exp(), exp(m1+m2)); |
| 436 | VERIFY_IS_APPROX(m1.exp(), exp(m1)); |
| 437 | VERIFY_IS_APPROX(m1.exp() / m2.exp(),(m1-m2).exp()); |
Gael Guennebaud | 575ac54 | 2010-06-19 23:17:07 +0200 | [diff] [blame] | 438 | |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 439 | VERIFY_IS_APPROX(m1.expm1(), expm1(m1)); |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 440 | VERIFY_IS_APPROX((m3 + smallNumber).exp() - Scalar(1), expm1(abs(m3) + smallNumber)); |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 441 | |
Gael Guennebaud | 575ac54 | 2010-06-19 23:17:07 +0200 | [diff] [blame] | 442 | VERIFY_IS_APPROX(m3.pow(RealScalar(0.5)), m3.sqrt()); |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 443 | VERIFY_IS_APPROX(pow(m3,RealScalar(0.5)), m3.sqrt()); |
Benoit Steiner | e25e3a0 | 2015-12-03 18:16:35 -0800 | [diff] [blame] | 444 | |
| 445 | VERIFY_IS_APPROX(m3.pow(RealScalar(-0.5)), m3.rsqrt()); |
| 446 | VERIFY_IS_APPROX(pow(m3,RealScalar(-0.5)), m3.rsqrt()); |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 447 | |
| 448 | // Avoid inf and NaN. |
| 449 | m3 = (m1.square()<NumTraits<Scalar>::epsilon()).select(Scalar(1),m3); |
| 450 | VERIFY_IS_APPROX(m3.pow(RealScalar(-2)), m3.square().inverse()); |
Rasmus Munk Larsen | cdd8fdc | 2021-01-18 13:25:16 +0000 | [diff] [blame] | 451 | pow_test<Scalar>(); |
Benoit Steiner | e25e3a0 | 2015-12-03 18:16:35 -0800 | [diff] [blame] | 452 | |
Antonio Sanchez | 4c42d5e | 2021-01-23 11:54:00 -0800 | [diff] [blame] | 453 | VERIFY_IS_APPROX(log10(m3), log(m3)/numext::log(Scalar(10))); |
| 454 | VERIFY_IS_APPROX(log2(m3), log(m3)/numext::log(Scalar(2))); |
Hauke Heibel | 81c1336 | 2012-03-07 08:58:42 +0100 | [diff] [blame] | 455 | |
| 456 | // scalar by array division |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 457 | const RealScalar tiny = sqrt(std::numeric_limits<RealScalar>::epsilon()); |
Hauke Heibel | dd9365e | 2012-03-09 14:04:13 +0100 | [diff] [blame] | 458 | s1 += Scalar(tiny); |
| 459 | m1 += ArrayType::Constant(rows,cols,Scalar(tiny)); |
Hauke Heibel | 81c1336 | 2012-03-07 08:58:42 +0100 | [diff] [blame] | 460 | VERIFY_IS_APPROX(s1/m1, s1 * m1.inverse()); |
Eugene Brevdo | f736277 | 2015-12-24 21:15:38 -0800 | [diff] [blame] | 461 | |
Gael Guennebaud | c695cbf | 2013-06-24 13:33:44 +0200 | [diff] [blame] | 462 | // check inplace transpose |
| 463 | m3 = m1; |
| 464 | m3.transposeInPlace(); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 465 | VERIFY_IS_APPROX(m3, m1.transpose()); |
Gael Guennebaud | c695cbf | 2013-06-24 13:33:44 +0200 | [diff] [blame] | 466 | m3.transposeInPlace(); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 467 | VERIFY_IS_APPROX(m3, m1); |
Gael Guennebaud | 0ce5bc0 | 2010-01-27 23:23:59 +0100 | [diff] [blame] | 468 | } |
| 469 | |
Jitse Niesen | 837db08 | 2011-05-09 10:17:41 +0100 | [diff] [blame] | 470 | template<typename ArrayType> void array_complex(const ArrayType& m) |
| 471 | { |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 472 | typedef typename ArrayType::Scalar Scalar; |
| 473 | typedef typename NumTraits<Scalar>::Real RealScalar; |
Jitse Niesen | 837db08 | 2011-05-09 10:17:41 +0100 | [diff] [blame] | 474 | |
| 475 | Index rows = m.rows(); |
| 476 | Index cols = m.cols(); |
| 477 | |
| 478 | ArrayType m1 = ArrayType::Random(rows, cols), |
Gael Guennebaud | 9fc1c92 | 2015-06-22 16:48:27 +0200 | [diff] [blame] | 479 | m2(rows, cols), |
| 480 | m4 = m1; |
Srinivas Vasudevan | 218764e | 2016-12-02 14:13:01 -0800 | [diff] [blame] | 481 | |
Gael Guennebaud | 9fc1c92 | 2015-06-22 16:48:27 +0200 | [diff] [blame] | 482 | m4.real() = (m4.real().abs()==RealScalar(0)).select(RealScalar(1),m4.real()); |
| 483 | m4.imag() = (m4.imag().abs()==RealScalar(0)).select(RealScalar(1),m4.imag()); |
Jitse Niesen | 837db08 | 2011-05-09 10:17:41 +0100 | [diff] [blame] | 484 | |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 485 | Array<RealScalar, -1, -1> m3(rows, cols); |
| 486 | |
Jitse Niesen | 837db08 | 2011-05-09 10:17:41 +0100 | [diff] [blame] | 487 | for (Index i = 0; i < m.rows(); ++i) |
| 488 | for (Index j = 0; j < m.cols(); ++j) |
Gael Guennebaud | a76fbbf | 2012-11-06 15:25:50 +0100 | [diff] [blame] | 489 | m2(i,j) = sqrt(m1(i,j)); |
Jitse Niesen | 837db08 | 2011-05-09 10:17:41 +0100 | [diff] [blame] | 490 | |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 491 | // these tests are mostly to check possible compilation issues with free-functions. |
Deanna Hood | f89fcef | 2015-03-11 13:13:30 +1000 | [diff] [blame] | 492 | VERIFY_IS_APPROX(m1.sin(), sin(m1)); |
| 493 | VERIFY_IS_APPROX(m1.cos(), cos(m1)); |
| 494 | VERIFY_IS_APPROX(m1.tan(), tan(m1)); |
| 495 | VERIFY_IS_APPROX(m1.sinh(), sinh(m1)); |
| 496 | VERIFY_IS_APPROX(m1.cosh(), cosh(m1)); |
| 497 | VERIFY_IS_APPROX(m1.tanh(), tanh(m1)); |
Rasmus Munk Larsen | d6e283b | 2018-08-13 11:14:50 -0700 | [diff] [blame] | 498 | VERIFY_IS_APPROX(m1.logistic(), logistic(m1)); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 499 | VERIFY_IS_APPROX(m1.arg(), arg(m1)); |
Christoph Hertzberg | 61e0977 | 2015-08-14 17:32:34 +0200 | [diff] [blame] | 500 | VERIFY((m1.isNaN() == (Eigen::isnan)(m1)).all()); |
| 501 | VERIFY((m1.isInf() == (Eigen::isinf)(m1)).all()); |
| 502 | VERIFY((m1.isFinite() == (Eigen::isfinite)(m1)).all()); |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 503 | VERIFY_IS_APPROX(m4.inverse(), inverse(m4)); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 504 | VERIFY_IS_APPROX(m1.log(), log(m1)); |
| 505 | VERIFY_IS_APPROX(m1.log10(), log10(m1)); |
Rasmus Munk Larsen | f9fac1d | 2020-12-04 21:45:09 +0000 | [diff] [blame] | 506 | VERIFY_IS_APPROX(m1.log2(), log2(m1)); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 507 | VERIFY_IS_APPROX(m1.abs(), abs(m1)); |
| 508 | VERIFY_IS_APPROX(m1.abs2(), abs2(m1)); |
| 509 | VERIFY_IS_APPROX(m1.sqrt(), sqrt(m1)); |
| 510 | VERIFY_IS_APPROX(m1.square(), square(m1)); |
| 511 | VERIFY_IS_APPROX(m1.cube(), cube(m1)); |
| 512 | VERIFY_IS_APPROX(cos(m1+RealScalar(3)*m2), cos((m1+RealScalar(3)*m2).eval())); |
Gael Guennebaud | 3f32f5e | 2015-11-27 16:27:53 +0100 | [diff] [blame] | 513 | VERIFY_IS_APPROX(m1.sign(), sign(m1)); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 514 | |
| 515 | |
| 516 | VERIFY_IS_APPROX(m1.exp() * m2.exp(), exp(m1+m2)); |
| 517 | VERIFY_IS_APPROX(m1.exp(), exp(m1)); |
| 518 | VERIFY_IS_APPROX(m1.exp() / m2.exp(),(m1-m2).exp()); |
| 519 | |
Srinivas Vasudevan | 88062b7 | 2019-12-12 01:56:54 +0000 | [diff] [blame] | 520 | VERIFY_IS_APPROX(m1.expm1(), expm1(m1)); |
| 521 | VERIFY_IS_APPROX(expm1(m1), exp(m1) - 1.); |
| 522 | // Check for larger magnitude complex numbers that expm1 matches exp - 1. |
| 523 | VERIFY_IS_APPROX(expm1(10. * m1), exp(10. * m1) - 1.); |
| 524 | |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 525 | VERIFY_IS_APPROX(sinh(m1), 0.5*(exp(m1)-exp(-m1))); |
| 526 | VERIFY_IS_APPROX(cosh(m1), 0.5*(exp(m1)+exp(-m1))); |
| 527 | VERIFY_IS_APPROX(tanh(m1), (0.5*(exp(m1)-exp(-m1)))/(0.5*(exp(m1)+exp(-m1)))); |
Rasmus Munk Larsen | d6e283b | 2018-08-13 11:14:50 -0700 | [diff] [blame] | 528 | VERIFY_IS_APPROX(logistic(m1), (1.0/(1.0 + exp(-m1)))); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 529 | |
| 530 | for (Index i = 0; i < m.rows(); ++i) |
| 531 | for (Index j = 0; j < m.cols(); ++j) |
Gael Guennebaud | 87427d2 | 2019-10-08 09:15:17 +0200 | [diff] [blame] | 532 | m3(i,j) = std::atan2(m1(i,j).imag(), m1(i,j).real()); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 533 | VERIFY_IS_APPROX(arg(m1), m3); |
| 534 | |
| 535 | std::complex<RealScalar> zero(0.0,0.0); |
Christoph Hertzberg | 61e0977 | 2015-08-14 17:32:34 +0200 | [diff] [blame] | 536 | VERIFY((Eigen::isnan)(m1*zero/zero).all()); |
Gael Guennebaud | 4a985e7 | 2015-11-20 14:52:08 +0100 | [diff] [blame] | 537 | #if EIGEN_COMP_MSVC |
| 538 | // msvc complex division is not robust |
| 539 | VERIFY((Eigen::isinf)(m4/RealScalar(0)).all()); |
| 540 | #else |
Gael Guennebaud | 40f326e | 2015-06-17 15:33:09 +0200 | [diff] [blame] | 541 | #if EIGEN_COMP_CLANG |
Gael Guennebaud | 4a985e7 | 2015-11-20 14:52:08 +0100 | [diff] [blame] | 542 | // clang's complex division is notoriously broken too |
Christoph Hertzberg | 61e0977 | 2015-08-14 17:32:34 +0200 | [diff] [blame] | 543 | if((numext::isinf)(m4(0,0)/RealScalar(0))) { |
Gael Guennebaud | 40f326e | 2015-06-17 15:33:09 +0200 | [diff] [blame] | 544 | #endif |
Gael Guennebaud | 4a985e7 | 2015-11-20 14:52:08 +0100 | [diff] [blame] | 545 | VERIFY((Eigen::isinf)(m4/zero).all()); |
Gael Guennebaud | 40f326e | 2015-06-17 15:33:09 +0200 | [diff] [blame] | 546 | #if EIGEN_COMP_CLANG |
| 547 | } |
| 548 | else |
| 549 | { |
Christoph Hertzberg | 61e0977 | 2015-08-14 17:32:34 +0200 | [diff] [blame] | 550 | VERIFY((Eigen::isinf)(m4.real()/zero.real()).all()); |
Gael Guennebaud | 40f326e | 2015-06-17 15:33:09 +0200 | [diff] [blame] | 551 | } |
| 552 | #endif |
Gael Guennebaud | 4a985e7 | 2015-11-20 14:52:08 +0100 | [diff] [blame] | 553 | #endif // MSVC |
| 554 | |
Christoph Hertzberg | 61e0977 | 2015-08-14 17:32:34 +0200 | [diff] [blame] | 555 | VERIFY(((Eigen::isfinite)(m1) && (!(Eigen::isfinite)(m1*zero/zero)) && (!(Eigen::isfinite)(m1/zero))).all()); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 556 | |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 557 | VERIFY_IS_APPROX(inverse(inverse(m4)),m4); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 558 | VERIFY_IS_APPROX(conj(m1.conjugate()), m1); |
Gael Guennebaud | 87427d2 | 2019-10-08 09:15:17 +0200 | [diff] [blame] | 559 | VERIFY_IS_APPROX(abs(m1), sqrt(square(m1.real())+square(m1.imag()))); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 560 | VERIFY_IS_APPROX(abs(m1), sqrt(abs2(m1))); |
| 561 | VERIFY_IS_APPROX(log10(m1), log(m1)/log(10)); |
Rasmus Munk Larsen | f9fac1d | 2020-12-04 21:45:09 +0000 | [diff] [blame] | 562 | VERIFY_IS_APPROX(log2(m1), log(m1)/log(2)); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 563 | |
Gael Guennebaud | 3f32f5e | 2015-11-27 16:27:53 +0100 | [diff] [blame] | 564 | VERIFY_IS_APPROX( m1.sign(), -(-m1).sign() ); |
| 565 | VERIFY_IS_APPROX( m1.sign() * m1.abs(), m1); |
| 566 | |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 567 | // scalar by array division |
Eugene Brevdo | f736277 | 2015-12-24 21:15:38 -0800 | [diff] [blame] | 568 | Scalar s1 = internal::random<Scalar>(); |
Benoit Steiner | 2d74ef9 | 2016-05-17 07:20:11 -0700 | [diff] [blame] | 569 | const RealScalar tiny = std::sqrt(std::numeric_limits<RealScalar>::epsilon()); |
Deanna Hood | 41b717d | 2015-03-18 03:11:03 +1000 | [diff] [blame] | 570 | s1 += Scalar(tiny); |
| 571 | m1 += ArrayType::Constant(rows,cols,Scalar(tiny)); |
| 572 | VERIFY_IS_APPROX(s1/m1, s1 * m1.inverse()); |
| 573 | |
| 574 | // check inplace transpose |
| 575 | m2 = m1; |
| 576 | m2.transposeInPlace(); |
| 577 | VERIFY_IS_APPROX(m2, m1.transpose()); |
| 578 | m2.transposeInPlace(); |
| 579 | VERIFY_IS_APPROX(m2, m1); |
Rasmus Munk Larsen | b47c777 | 2020-04-27 18:55:15 -0700 | [diff] [blame] | 580 | // Check vectorized inplace transpose. |
Rasmus Munk Larsen | 74ec8e6 | 2020-05-07 17:29:56 +0000 | [diff] [blame] | 581 | ArrayType m5 = ArrayType::Random(131, 131); |
Rasmus Munk Larsen | b47c777 | 2020-04-27 18:55:15 -0700 | [diff] [blame] | 582 | ArrayType m6 = m5; |
| 583 | m6.transposeInPlace(); |
| 584 | VERIFY_IS_APPROX(m6, m5.transpose()); |
Jitse Niesen | 837db08 | 2011-05-09 10:17:41 +0100 | [diff] [blame] | 585 | } |
| 586 | |
Abraham Bachrach | 039408c | 2012-01-11 11:00:30 -0500 | [diff] [blame] | 587 | template<typename ArrayType> void min_max(const ArrayType& m) |
| 588 | { |
Abraham Bachrach | 039408c | 2012-01-11 11:00:30 -0500 | [diff] [blame] | 589 | typedef typename ArrayType::Scalar Scalar; |
| 590 | |
| 591 | Index rows = m.rows(); |
| 592 | Index cols = m.cols(); |
| 593 | |
| 594 | ArrayType m1 = ArrayType::Random(rows, cols); |
| 595 | |
| 596 | // min/max with array |
| 597 | Scalar maxM1 = m1.maxCoeff(); |
| 598 | Scalar minM1 = m1.minCoeff(); |
| 599 | |
| 600 | VERIFY_IS_APPROX(ArrayType::Constant(rows,cols, minM1), (m1.min)(ArrayType::Constant(rows,cols, minM1))); |
| 601 | VERIFY_IS_APPROX(m1, (m1.min)(ArrayType::Constant(rows,cols, maxM1))); |
| 602 | |
| 603 | VERIFY_IS_APPROX(ArrayType::Constant(rows,cols, maxM1), (m1.max)(ArrayType::Constant(rows,cols, maxM1))); |
| 604 | VERIFY_IS_APPROX(m1, (m1.max)(ArrayType::Constant(rows,cols, minM1))); |
| 605 | |
| 606 | // min/max with scalar input |
| 607 | VERIFY_IS_APPROX(ArrayType::Constant(rows,cols, minM1), (m1.min)( minM1)); |
| 608 | VERIFY_IS_APPROX(m1, (m1.min)( maxM1)); |
| 609 | |
| 610 | VERIFY_IS_APPROX(ArrayType::Constant(rows,cols, maxM1), (m1.max)( maxM1)); |
| 611 | VERIFY_IS_APPROX(m1, (m1.max)( minM1)); |
| 612 | |
| 613 | } |
| 614 | |
Gael Guennebaud | e0f6d35 | 2018-09-20 18:07:32 +0200 | [diff] [blame] | 615 | EIGEN_DECLARE_TEST(array_cwise) |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 616 | { |
| 617 | for(int i = 0; i < g_repeat; i++) { |
Hauke Heibel | 2d0dfe5 | 2010-12-16 17:36:10 +0100 | [diff] [blame] | 618 | CALL_SUBTEST_1( array(Array<float, 1, 1>()) ); |
Hauke Heibel | b31e124 | 2010-12-16 19:07:23 +0100 | [diff] [blame] | 619 | CALL_SUBTEST_2( array(Array22f()) ); |
| 620 | CALL_SUBTEST_3( array(Array44d()) ); |
Gael Guennebaud | a8f66fe | 2011-07-12 14:41:00 +0200 | [diff] [blame] | 621 | CALL_SUBTEST_4( array(ArrayXXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); |
| 622 | CALL_SUBTEST_5( array(ArrayXXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); |
| 623 | CALL_SUBTEST_6( array(ArrayXXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); |
Gael Guennebaud | 543529d | 2019-01-22 15:30:50 +0100 | [diff] [blame] | 624 | CALL_SUBTEST_6( array(Array<Index,Dynamic,Dynamic>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 625 | } |
Hauke Heibel | 2d0dfe5 | 2010-12-16 17:36:10 +0100 | [diff] [blame] | 626 | for(int i = 0; i < g_repeat; i++) { |
| 627 | CALL_SUBTEST_1( comparisons(Array<float, 1, 1>()) ); |
Hauke Heibel | b31e124 | 2010-12-16 19:07:23 +0100 | [diff] [blame] | 628 | CALL_SUBTEST_2( comparisons(Array22f()) ); |
| 629 | CALL_SUBTEST_3( comparisons(Array44d()) ); |
Gael Guennebaud | a8f66fe | 2011-07-12 14:41:00 +0200 | [diff] [blame] | 630 | CALL_SUBTEST_5( comparisons(ArrayXXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); |
| 631 | CALL_SUBTEST_6( comparisons(ArrayXXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); |
Hauke Heibel | 2d0dfe5 | 2010-12-16 17:36:10 +0100 | [diff] [blame] | 632 | } |
| 633 | for(int i = 0; i < g_repeat; i++) { |
Abraham Bachrach | 039408c | 2012-01-11 11:00:30 -0500 | [diff] [blame] | 634 | CALL_SUBTEST_1( min_max(Array<float, 1, 1>()) ); |
| 635 | CALL_SUBTEST_2( min_max(Array22f()) ); |
| 636 | CALL_SUBTEST_3( min_max(Array44d()) ); |
| 637 | CALL_SUBTEST_5( min_max(ArrayXXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); |
| 638 | CALL_SUBTEST_6( min_max(ArrayXXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); |
| 639 | } |
| 640 | for(int i = 0; i < g_repeat; i++) { |
Hauke Heibel | 2d0dfe5 | 2010-12-16 17:36:10 +0100 | [diff] [blame] | 641 | CALL_SUBTEST_1( array_real(Array<float, 1, 1>()) ); |
Hauke Heibel | b31e124 | 2010-12-16 19:07:23 +0100 | [diff] [blame] | 642 | CALL_SUBTEST_2( array_real(Array22f()) ); |
| 643 | CALL_SUBTEST_3( array_real(Array44d()) ); |
Gael Guennebaud | a8f66fe | 2011-07-12 14:41:00 +0200 | [diff] [blame] | 644 | CALL_SUBTEST_5( array_real(ArrayXXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); |
Antonio Sanchez | f0e46ed | 2021-01-22 11:10:54 -0800 | [diff] [blame] | 645 | CALL_SUBTEST_7( array_real(Array<Eigen::half, 32, 32>()) ); |
| 646 | CALL_SUBTEST_8( array_real(Array<Eigen::bfloat16, 32, 32>()) ); |
Hauke Heibel | 2d0dfe5 | 2010-12-16 17:36:10 +0100 | [diff] [blame] | 647 | } |
Jitse Niesen | 837db08 | 2011-05-09 10:17:41 +0100 | [diff] [blame] | 648 | for(int i = 0; i < g_repeat; i++) { |
Gael Guennebaud | a8f66fe | 2011-07-12 14:41:00 +0200 | [diff] [blame] | 649 | CALL_SUBTEST_4( array_complex(ArrayXXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) ); |
Jitse Niesen | 837db08 | 2011-05-09 10:17:41 +0100 | [diff] [blame] | 650 | } |
Benoit Jacob | 5d63d2c | 2010-04-28 22:42:34 -0400 | [diff] [blame] | 651 | |
Hauke Heibel | 2d0dfe5 | 2010-12-16 17:36:10 +0100 | [diff] [blame] | 652 | VERIFY((internal::is_same< internal::global_math_functions_filtering_base<int>::type, int >::value)); |
| 653 | VERIFY((internal::is_same< internal::global_math_functions_filtering_base<float>::type, float >::value)); |
| 654 | VERIFY((internal::is_same< internal::global_math_functions_filtering_base<Array2i>::type, ArrayBase<Array2i> >::value)); |
Gael Guennebaud | 64fcfd3 | 2016-06-14 11:26:57 +0200 | [diff] [blame] | 655 | typedef CwiseUnaryOp<internal::scalar_abs_op<double>, ArrayXd > Xpr; |
Hauke Heibel | 2d0dfe5 | 2010-12-16 17:36:10 +0100 | [diff] [blame] | 656 | VERIFY((internal::is_same< internal::global_math_functions_filtering_base<Xpr>::type, |
| 657 | ArrayBase<Xpr> |
| 658 | >::value)); |
Gael Guennebaud | 8cef541 | 2008-06-21 17:28:07 +0000 | [diff] [blame] | 659 | } |