| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  | // This file is part of Eigen, a lightweight C++ template library
 | 
					
						
							|  |  |  | // for linear algebra.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This Source Code Form is subject to the terms of the Mozilla
 | 
					
						
							|  |  |  | // Public License v. 2.0. If a copy of the MPL was not distributed
 | 
					
						
							|  |  |  | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <valarray>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include "main.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Move Eigen::all,last,lastp1,lastN to Eigen::placeholders::.
These names are so common, IMO they should not exist directly in the
`Eigen::` namespace.  This prevents us from using the `last` or `all`
names for any parameters or local variables, otherwise spitting out
warnings about shadowing or hiding the global values.  Many external
projects (and our own examples) also heavily use
```
using namespace Eigen;
```
which means these conflict with external libraries as well, e.g.
`std::fill(first,last,value)`.
It seems originally these were placed in a separate namespace
`Eigen::placeholders`, which has since been deprecated.  I propose
to un-deprecate this, and restore the original locations.
These symbols are also imported into `Eigen::indexing`, which
additionally imports `fix` and `seq`. An alternative is to remove the
`placeholders` namespace and stick with `indexing`.
NOTE: this is an API-breaking change.
Fixes #2321.
											
										 
											2021-09-16 05:10:29 +08:00
										 |  |  | using Eigen::placeholders::all; | 
					
						
							|  |  |  | using Eigen::placeholders::last; | 
					
						
							|  |  |  | using Eigen::placeholders::lastN; | 
					
						
							|  |  |  | using Eigen::placeholders::lastp1; | 
					
						
							| 
									
										
										
										
											2017-01-06 20:29:33 +08:00
										 |  |  | #include <array>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  | typedef std::pair<Index, Index> IndexPair; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 20:10:10 +08:00
										 |  |  | int encode(Index i, Index j) { return int(i * 100 + j); } | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | IndexPair decode(Index ij) { return IndexPair(ij / 100, ij % 100); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <typename T> | 
					
						
							|  |  |  | bool match(const T& xpr, std::string ref, std::string str_xpr = "") { | 
					
						
							| 
									
										
										
										
											2017-01-06 22:54:55 +08:00
										 |  |  |   EIGEN_UNUSED_VARIABLE(str_xpr); | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |   std::stringstream str; | 
					
						
							|  |  |  |   str << xpr; | 
					
						
							| 
									
										
										
										
											2017-01-11 20:17:09 +08:00
										 |  |  |   if (!(str.str() == ref)) std::cout << str_xpr << "\n" << xpr << "\n\n"; | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |   return str.str() == ref; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MATCH(X, R) match(X, R, #X)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 21:25:30 +08:00
										 |  |  | template <typename T1, typename T2> | 
					
						
							| 
									
										
										
										
											2022-03-17 00:43:40 +08:00
										 |  |  | std::enable_if_t<internal::is_same<T1, T2>::value, bool> is_same_eq(const T1& a, const T2& b) { | 
					
						
							| 
									
										
										
										
											2017-01-10 21:25:30 +08:00
										 |  |  |   return (a == b).all(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-16 23:17:01 +08:00
										 |  |  | template <typename T1, typename T2> | 
					
						
							| 
									
										
										
										
											2017-01-20 03:34:18 +08:00
										 |  |  | bool is_same_seq(const T1& a, const T2& b) { | 
					
						
							| 
									
										
										
										
											2017-01-18 18:35:27 +08:00
										 |  |  |   bool ok = a.first() == b.first() && a.size() == b.size() && Index(a.incrObject()) == Index(b.incrObject()); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  |   ; | 
					
						
							| 
									
										
										
										
											2017-01-18 18:35:27 +08:00
										 |  |  |   if (!ok) { | 
					
						
							|  |  |  |     std::cerr << "seqN(" << a.first() << ", " << a.size() << ", " << Index(a.incrObject()) << ") != "; | 
					
						
							|  |  |  |     std::cerr << "seqN(" << b.first() << ", " << b.size() << ", " << Index(b.incrObject()) << ")\n"; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return ok; | 
					
						
							| 
									
										
										
										
											2017-01-16 23:17:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-20 03:34:18 +08:00
										 |  |  | template <typename T1, typename T2> | 
					
						
							| 
									
										
										
										
											2022-03-17 00:43:40 +08:00
										 |  |  | std::enable_if_t<internal::is_same<T1, T2>::value, bool> is_same_seq_type(const T1& a, const T2& b) { | 
					
						
							| 
									
										
										
										
											2017-01-20 03:34:18 +08:00
										 |  |  |   return is_same_seq(a, b); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 23:05:58 +08:00
										 |  |  | #define VERIFY_EQ_INT(A, B) VERIFY_IS_APPROX(int(A), int(B))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 00:57:28 +08:00
										 |  |  | // C++03 does not allow local or unnamed enums as index
 | 
					
						
							|  |  |  | enum DummyEnum { XX = 0, YY = 1 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  | void check_indexed_view() { | 
					
						
							|  |  |  |   Index n = 10; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 20:17:09 +08:00
										 |  |  |   ArrayXd a = ArrayXd::LinSpaced(n, 0, n - 1); | 
					
						
							|  |  |  |   Array<double, 1, Dynamic> b = a.transpose(); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-19 21:05:22 +08:00
										 |  |  |   ArrayXXi A = ArrayXXi::NullaryExpr(n, n, std::ref(encode)); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |   for (Index i = 0; i < n; ++i) | 
					
						
							|  |  |  |     for (Index j = 0; j < n; ++j) VERIFY(decode(A(i, j)) == IndexPair(i, j)); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |   Array4i eii(4); | 
					
						
							|  |  |  |   eii << 3, 1, 6, 5; | 
					
						
							|  |  |  |   std::valarray<int> vali(4); | 
					
						
							|  |  |  |   Map<ArrayXi>(&vali[0], 4) = eii; | 
					
						
							|  |  |  |   std::vector<int> veci(4); | 
					
						
							|  |  |  |   Map<ArrayXi>(veci.data(), 4) = eii; | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |   VERIFY(MATCH(A(3, seq(9, 3, -1)), "309  308  307  306  305  304  303")); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:35:21 +08:00
										 |  |  |   VERIFY(MATCH(A(seqN(2, 5), seq(9, 3, -1)), | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |                "209  208  207  206  205  204  203\n" | 
					
						
							|  |  |  |                "309  308  307  306  305  304  303\n" | 
					
						
							|  |  |  |                "409  408  407  406  405  404  403\n" | 
					
						
							|  |  |  |                "509  508  507  506  505  504  503\n" | 
					
						
							|  |  |  |                "609  608  607  606  605  604  603")); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:35:21 +08:00
										 |  |  |   VERIFY(MATCH(A(seqN(2, 5), 5), | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |                "205\n" | 
					
						
							|  |  |  |                "305\n" | 
					
						
							|  |  |  |                "405\n" | 
					
						
							|  |  |  |                "505\n" | 
					
						
							|  |  |  |                "605")); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:35:21 +08:00
										 |  |  |   VERIFY(MATCH(A(seqN(last, 5, -1), seq(2, last)), | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |                "902  903  904  905  906  907  908  909\n" | 
					
						
							|  |  |  |                "802  803  804  805  806  807  808  809\n" | 
					
						
							|  |  |  |                "702  703  704  705  706  707  708  709\n" | 
					
						
							|  |  |  |                "602  603  604  605  606  607  608  609\n" | 
					
						
							|  |  |  |                "502  503  504  505  506  507  508  509")); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |   VERIFY(MATCH(A(eii, veci), | 
					
						
							|  |  |  |                "303  301  306  305\n" | 
					
						
							|  |  |  |                "103  101  106  105\n" | 
					
						
							|  |  |  |                "603  601  606  605\n" | 
					
						
							|  |  |  |                "503  501  506  505")); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |   VERIFY(MATCH(A(eii, all), | 
					
						
							|  |  |  |                "300  301  302  303  304  305  306  307  308  309\n" | 
					
						
							|  |  |  |                "100  101  102  103  104  105  106  107  108  109\n" | 
					
						
							|  |  |  |                "600  601  602  603  604  605  606  607  608  609\n" | 
					
						
							|  |  |  |                "500  501  502  503  504  505  506  507  508  509")); | 
					
						
							| 
									
										
										
										
											2017-01-07 04:53:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 20:43:02 +08:00
										 |  |  |   // take row number 3, and repeat it 5 times
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:35:21 +08:00
										 |  |  |   VERIFY(MATCH(A(seqN(3, 5, 0), all), | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |                "300  301  302  303  304  305  306  307  308  309\n" | 
					
						
							|  |  |  |                "300  301  302  303  304  305  306  307  308  309\n" | 
					
						
							|  |  |  |                "300  301  302  303  304  305  306  307  308  309\n" | 
					
						
							|  |  |  |                "300  301  302  303  304  305  306  307  308  309\n" | 
					
						
							|  |  |  |                "300  301  302  303  304  305  306  307  308  309")); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 20:17:09 +08:00
										 |  |  |   VERIFY(MATCH(a(seqN(3, 3), 0), "3\n4\n5")); | 
					
						
							|  |  |  |   VERIFY(MATCH(a(seq(3, 5)), "3\n4\n5")); | 
					
						
							|  |  |  |   VERIFY(MATCH(a(seqN(3, 3, 1)), "3\n4\n5")); | 
					
						
							|  |  |  |   VERIFY(MATCH(a(seqN(5, 3, -1)), "5\n4\n3")); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 20:17:09 +08:00
										 |  |  |   VERIFY(MATCH(b(0, seqN(3, 3)), "3  4  5")); | 
					
						
							|  |  |  |   VERIFY(MATCH(b(seq(3, 5)), "3  4  5")); | 
					
						
							|  |  |  |   VERIFY(MATCH(b(seqN(3, 3, 1)), "3  4  5")); | 
					
						
							|  |  |  |   VERIFY(MATCH(b(seqN(5, 3, -1)), "5  4  3")); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 20:17:09 +08:00
										 |  |  |   VERIFY(MATCH(b(all), "0  1  2  3  4  5  6  7  8  9")); | 
					
						
							|  |  |  |   VERIFY(MATCH(b(eii), "3  1  6  5")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 20:10:10 +08:00
										 |  |  |   Array44i B; | 
					
						
							| 
									
										
										
										
											2017-01-06 22:54:55 +08:00
										 |  |  |   B.setRandom(); | 
					
						
							| 
									
										
										
										
											2017-01-10 00:35:21 +08:00
										 |  |  |   VERIFY((A(seqN(2, 5), 5)).ColsAtCompileTime == 1); | 
					
						
							|  |  |  |   VERIFY((A(seqN(2, 5), 5)).RowsAtCompileTime == Dynamic); | 
					
						
							| 
									
										
										
										
											2017-01-17 23:05:58 +08:00
										 |  |  |   VERIFY_EQ_INT((A(seqN(2, 5), 5)).InnerStrideAtCompileTime, A.InnerStrideAtCompileTime); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, 5), 5)).OuterStrideAtCompileTime, A.col(5).OuterStrideAtCompileTime); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 23:05:58 +08:00
										 |  |  |   VERIFY_EQ_INT((A(5, seqN(2, 5))).InnerStrideAtCompileTime, A.row(5).InnerStrideAtCompileTime); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(5, seqN(2, 5))).OuterStrideAtCompileTime, A.row(5).OuterStrideAtCompileTime); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((B(1, seqN(1, 2))).InnerStrideAtCompileTime, B.row(1).InnerStrideAtCompileTime); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((B(1, seqN(1, 2))).OuterStrideAtCompileTime, B.row(1).OuterStrideAtCompileTime); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 23:05:58 +08:00
										 |  |  |   VERIFY_EQ_INT((A(seqN(2, 5), seq(1, 3))).InnerStrideAtCompileTime, A.InnerStrideAtCompileTime); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, 5), seq(1, 3))).OuterStrideAtCompileTime, A.OuterStrideAtCompileTime); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((B(seqN(1, 2), seq(1, 3))).InnerStrideAtCompileTime, B.InnerStrideAtCompileTime); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((B(seqN(1, 2), seq(1, 3))).OuterStrideAtCompileTime, B.OuterStrideAtCompileTime); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, 5, 2), seq(1, 3, 2))).InnerStrideAtCompileTime, Dynamic); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, 5, 2), seq(1, 3, 2))).OuterStrideAtCompileTime, Dynamic); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, 5, fix<2>), seq(1, 3, fix<3>))).InnerStrideAtCompileTime, 2); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, 5, fix<2>), seq(1, 3, fix<3>))).OuterStrideAtCompileTime, Dynamic); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((B(seqN(1, 2, fix<2>), seq(1, 3, fix<3>))).InnerStrideAtCompileTime, 2); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((B(seqN(1, 2, fix<2>), seq(1, 3, fix<3>))).OuterStrideAtCompileTime, 3 * 4); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 23:05:58 +08:00
										 |  |  |   VERIFY_EQ_INT((A(seqN(2, fix<5>), seqN(1, fix<3>))).RowsAtCompileTime, 5); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, fix<5>), seqN(1, fix<3>))).ColsAtCompileTime, 3); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, fix<5>(5)), seqN(1, fix<3>(3)))).RowsAtCompileTime, 5); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, fix<5>(5)), seqN(1, fix<3>(3)))).ColsAtCompileTime, 3); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, fix<Dynamic>(5)), seqN(1, fix<Dynamic>(3)))).RowsAtCompileTime, Dynamic); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, fix<Dynamic>(5)), seqN(1, fix<Dynamic>(3)))).ColsAtCompileTime, Dynamic); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, fix<Dynamic>(5)), seqN(1, fix<Dynamic>(3)))).rows(), 5); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(seqN(2, fix<Dynamic>(5)), seqN(1, fix<Dynamic>(3)))).cols(), 3); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-16 23:17:01 +08:00
										 |  |  |   VERIFY(is_same_seq_type(seqN(2, 5, fix<-1>), seqN(2, 5, fix<-1>(-1)))); | 
					
						
							|  |  |  |   VERIFY(is_same_seq_type(seqN(2, 5), seqN(2, 5, fix<1>(1)))); | 
					
						
							|  |  |  |   VERIFY(is_same_seq_type(seqN(2, 5, 3), seqN(2, 5, fix<DynamicIndex>(3)))); | 
					
						
							|  |  |  |   VERIFY(is_same_seq_type(seq(2, 7, fix<3>), seqN(2, 2, fix<3>))); | 
					
						
							|  |  |  |   VERIFY(is_same_seq_type(seqN(2, fix<Dynamic>(5), 3), seqN(2, 5, fix<DynamicIndex>(3)))); | 
					
						
							|  |  |  |   VERIFY(is_same_seq_type(seqN(2, fix<5>(5), fix<-2>), seqN(2, fix<5>, fix<-2>()))); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-20 03:34:18 +08:00
										 |  |  |   VERIFY(is_same_seq_type(seq(2, fix<5>), seqN(2, 4))); | 
					
						
							|  |  |  |   VERIFY(is_same_seq_type(seq(fix<2>, fix<5>), seqN(fix<2>, fix<4>))); | 
					
						
							| 
									
										
										
										
											2017-01-24 23:28:12 +08:00
										 |  |  |   VERIFY(is_same_seq(seqN(2, std::integral_constant<int, 5>(), std::integral_constant<int, -2>()), | 
					
						
							|  |  |  |                      seqN(2, fix<5>, fix<-2>()))); | 
					
						
							|  |  |  |   VERIFY(is_same_seq( | 
					
						
							|  |  |  |       seq(std::integral_constant<int, 1>(), std::integral_constant<int, 5>(), std::integral_constant<int, 2>()), | 
					
						
							|  |  |  |       seq(fix<1>, fix<5>, fix<2>()))); | 
					
						
							|  |  |  |   VERIFY(is_same_seq_type(seqN(2, std::integral_constant<int, 5>(), std::integral_constant<int, -2>()), | 
					
						
							|  |  |  |                           seqN(2, fix<5>, fix<-2>()))); | 
					
						
							|  |  |  |   VERIFY(is_same_seq_type( | 
					
						
							|  |  |  |       seq(std::integral_constant<int, 1>(), std::integral_constant<int, 5>(), std::integral_constant<int, 2>()), | 
					
						
							|  |  |  |       seq(fix<1>, fix<5>, fix<2>()))); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 23:28:12 +08:00
										 |  |  |   VERIFY(is_same_seq_type(seqN(2, std::integral_constant<int, 5>()), seqN(2, fix<5>))); | 
					
						
							|  |  |  |   VERIFY( | 
					
						
							|  |  |  |       is_same_seq_type(seq(std::integral_constant<int, 1>(), std::integral_constant<int, 5>()), seq(fix<1>, fix<5>))); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:35:21 +08:00
										 |  |  |   VERIFY((A(seqN(2, fix<5>), 5)).RowsAtCompileTime == 5); | 
					
						
							| 
									
										
										
										
											2017-01-06 20:10:10 +08:00
										 |  |  |   VERIFY((A(4, all)).ColsAtCompileTime == Dynamic); | 
					
						
							|  |  |  |   VERIFY((A(4, all)).RowsAtCompileTime == 1); | 
					
						
							|  |  |  |   VERIFY((B(1, all)).ColsAtCompileTime == 4); | 
					
						
							|  |  |  |   VERIFY((B(1, all)).RowsAtCompileTime == 1); | 
					
						
							|  |  |  |   VERIFY((B(all, 1)).ColsAtCompileTime == 1); | 
					
						
							|  |  |  |   VERIFY((B(all, 1)).RowsAtCompileTime == 4); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-26 05:54:51 +08:00
										 |  |  |   VERIFY(int((A(all, eii)).ColsAtCompileTime) == int(eii.SizeAtCompileTime)); | 
					
						
							| 
									
										
										
										
											2017-01-17 23:05:58 +08:00
										 |  |  |   VERIFY_EQ_INT((A(eii, eii)).Flags & DirectAccessBit, (unsigned int)(0)); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(eii, eii)).InnerStrideAtCompileTime, 0); | 
					
						
							|  |  |  |   VERIFY_EQ_INT((A(eii, eii)).OuterStrideAtCompileTime, 0); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 18:35:27 +08:00
										 |  |  |   VERIFY_IS_APPROX(A(seq(n - 1, 2, -2), seqN(n - 1 - 6, 3, -1)), A(seq(last, 2, fix<-2>), seqN(last - 6, 3, fix<-1>))); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 06:42:16 +08:00
										 |  |  |   VERIFY_IS_APPROX(A(seq(n - 1, 2, -2), seqN(n - 1 - 6, 4)), A(seq(last, 2, -2), seqN(last - 6, 4))); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(A(seq(n - 1 - 6, n - 1 - 2), seqN(n - 1 - 6, 4)), | 
					
						
							|  |  |  |                    A(seq(last - 6, last - 2), seqN(6 + last - 6 - 6, 4))); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(A(seq((n - 1) / 2, (n) / 2 + 3), seqN(2, 4)), | 
					
						
							|  |  |  |                    A(seq(last / 2, (last + 1) / 2 + 3), seqN(last + 2 - last, 4))); | 
					
						
							| 
									
										
										
										
											2018-09-15 20:35:10 +08:00
										 |  |  |   VERIFY_IS_APPROX(A(seq(n - 2, 2, -2), seqN(n - 8, 4)), A(seq(lastp1 - 2, 2, -2), seqN(lastp1 - 8, 4))); | 
					
						
							| 
									
										
										
										
											2017-01-10 06:42:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 17:28:45 +08:00
										 |  |  |   // Check all combinations of seq:
 | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(A(seq(1, n - 1 - 2, 2), seq(1, n - 1 - 2, 2)), A(seq(1, last - 2, 2), seq(1, last - 2, fix<2>))); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(A(seq(n - 1 - 5, n - 1 - 2, 2), seq(n - 1 - 5, n - 1 - 2, 2)), | 
					
						
							|  |  |  |                    A(seq(last - 5, last - 2, 2), seq(last - 5, last - 2, fix<2>))); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(A(seq(n - 1 - 5, 7, 2), seq(n - 1 - 5, 7, 2)), A(seq(last - 5, 7, 2), seq(last - 5, 7, fix<2>))); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(A(seq(1, n - 1 - 2), seq(n - 1 - 5, 7)), A(seq(1, last - 2), seq(last - 5, 7))); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(A(seq(n - 1 - 5, n - 1 - 2), seq(n - 1 - 5, n - 1 - 2)), | 
					
						
							|  |  |  |                    A(seq(last - 5, last - 2), seq(last - 5, last - 2))); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 05:21:23 +08:00
										 |  |  |   VERIFY_IS_APPROX(A.col(A.cols() - 1), A(all, last)); | 
					
						
							| 
									
										
										
										
											2018-09-15 20:35:10 +08:00
										 |  |  |   VERIFY_IS_APPROX(A(A.rows() - 2, A.cols() / 2), A(last - 1, lastp1 / 2)); | 
					
						
							| 
									
										
										
										
											2017-01-17 05:21:23 +08:00
										 |  |  |   VERIFY_IS_APPROX(a(a.size() - 2), a(last - 1)); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(a(a.size() / 2), a((last + 1) / 2)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 21:25:30 +08:00
										 |  |  |   // Check fall-back to Block
 | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2017-01-17 18:34:28 +08:00
										 |  |  |     VERIFY(is_same_eq(A.col(0), A(all, 0))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.row(0), A(0, all))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.block(0, 0, 2, 2), A(seqN(0, 2), seq(0, 1)))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.middleRows(2, 4), A(seqN(2, 4), all))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.middleCols(2, 4), A(all, seqN(2, 4)))); | 
					
						
							| 
									
										
										
										
											2017-01-11 00:10:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 18:34:28 +08:00
										 |  |  |     VERIFY(is_same_eq(A.col(A.cols() - 1), A(all, last))); | 
					
						
							| 
									
										
										
										
											2017-01-17 05:21:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 21:25:30 +08:00
										 |  |  |     const ArrayXXi& cA(A); | 
					
						
							| 
									
										
										
										
											2017-01-17 18:34:28 +08:00
										 |  |  |     VERIFY(is_same_eq(cA.col(0), cA(all, 0))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.row(0), cA(0, all))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.block(0, 0, 2, 2), cA(seqN(0, 2), seq(0, 1)))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.middleRows(2, 4), cA(seqN(2, 4), all))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.middleCols(2, 4), cA(all, seqN(2, 4)))); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 18:34:28 +08:00
										 |  |  |     VERIFY(is_same_eq(a.head(4), a(seq(0, 3)))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(a.tail(4), a(seqN(last - 3, 4)))); | 
					
						
							| 
									
										
										
										
											2018-09-15 20:35:10 +08:00
										 |  |  |     VERIFY(is_same_eq(a.tail(4), a(seq(lastp1 - 4, last)))); | 
					
						
							| 
									
										
										
										
											2017-01-17 18:34:28 +08:00
										 |  |  |     VERIFY(is_same_eq(a.segment<4>(3), a(seqN(3, fix<4>)))); | 
					
						
							| 
									
										
										
										
											2017-01-10 21:25:30 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 00:10:35 +08:00
										 |  |  |   ArrayXXi A1 = A, A2 = ArrayXXi::Random(4, 4); | 
					
						
							|  |  |  |   ArrayXi range25(4); | 
					
						
							|  |  |  |   range25 << 3, 2, 4, 5; | 
					
						
							|  |  |  |   A1(seqN(3, 4), seq(2, 5)) = A2; | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(A1.block(3, 2, 4, 4), A2); | 
					
						
							|  |  |  |   A1 = A; | 
					
						
							|  |  |  |   A2.setOnes(); | 
					
						
							|  |  |  |   A1(seq(6, 3, -1), range25) = A2; | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(A1.block(3, 2, 4, 4), A2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 18:35:27 +08:00
										 |  |  |   // check reverse
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     VERIFY(is_same_seq_type(seq(3, 7).reverse(), seqN(7, 5, fix<-1>))); | 
					
						
							|  |  |  |     VERIFY(is_same_seq_type(seq(7, 3, fix<-2>).reverse(), seqN(3, 3, fix<2>))); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(a(seqN(2, last / 2).reverse()), a(seqN(2 + (last / 2 - 1) * 1, last / 2, fix<-1>))); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(a(seqN(last / 2, fix<4>).reverse()), a(seqN(last / 2, fix<4>)).reverse()); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(A(seq(last - 5, last - 1, 2).reverse(), seqN(last - 3, 3, fix<-2>).reverse()), | 
					
						
							|  |  |  |                      A(seq(last - 5, last - 1, 2), seqN(last - 3, 3, fix<-2>)).reverse()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-23 22:20:25 +08:00
										 |  |  |   // check lastN
 | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(a(lastN(3)), a.tail(3)); | 
					
						
							|  |  |  |   VERIFY(MATCH(a(lastN(3)), "7\n8\n9")); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(a(lastN(fix<3>())), a.tail<3>()); | 
					
						
							|  |  |  |   VERIFY(MATCH(a(lastN(3, 2)), "5\n7\n9")); | 
					
						
							|  |  |  |   VERIFY(MATCH(a(lastN(3, fix<2>())), "5\n7\n9")); | 
					
						
							|  |  |  |   VERIFY(a(lastN(fix<3>())).SizeAtCompileTime == 3); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 20:29:33 +08:00
										 |  |  |   VERIFY((A(all, std::array<int, 4>{{1, 3, 2, 4}})).ColsAtCompileTime == 4); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:35:21 +08:00
										 |  |  |   VERIFY_IS_APPROX((A(std::array<int, 3>{{1, 3, 5}}, std::array<int, 4>{{9, 6, 3, 0}})), | 
					
						
							|  |  |  |                    A(seqN(1, 3, 2), seqN(9, 4, -3))); | 
					
						
							| 
									
										
										
										
											2023-03-29 09:35:26 +08:00
										 |  |  |   VERIFY_IS_EQUAL(A(std::array<int, 3>{1, 3, 5}, std::array<int, 4>{3, 1, 6, 5}).RowsAtCompileTime, 3); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(A(std::array<int, 3>{1, 3, 5}, std::array<int, 4>{3, 1, 6, 5}).ColsAtCompileTime, 4); | 
					
						
							| 
									
										
										
										
											2017-01-11 20:17:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-29 10:39:45 +08:00
										 |  |  |   VERIFY_IS_EQUAL(a(std::array<int, 3>{1, 3, 5}).SizeAtCompileTime, 3); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(b(std::array<int, 3>{1, 3, 5}).SizeAtCompileTime, 3); | 
					
						
							| 
									
										
										
										
											2017-01-06 20:29:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 20:32:50 +08:00
										 |  |  |   // check different index types (C-style array, STL container, Eigen type)
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     Index size = 10; | 
					
						
							|  |  |  |     ArrayXd r = ArrayXd::Random(size); | 
					
						
							|  |  |  |     ArrayXi idx = ArrayXi::EqualSpaced(size, 0, 1); | 
					
						
							|  |  |  |     std::shuffle(idx.begin(), idx.end(), std::random_device()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int c_array[3] = {idx[0], idx[1], idx[2]}; | 
					
						
							|  |  |  |     std::vector<int> std_vector{idx[0], idx[1], idx[2]}; | 
					
						
							|  |  |  |     Matrix<int, 3, 1> eigen_matrix{idx[0], idx[1], idx[2]}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // non-const access
 | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r({idx[0], idx[1], idx[2]}), r(c_array)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r({idx[0], idx[1], idx[2]}), r(std_vector)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r({idx[0], idx[1], idx[2]}), r(eigen_matrix)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r(std_vector), r(c_array)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r(std_vector), r(eigen_matrix)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r(eigen_matrix), r(c_array)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ArrayXd& r_ref = r; | 
					
						
							|  |  |  |     // const access
 | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r_ref({idx[0], idx[1], idx[2]}), r_ref(c_array)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r_ref({idx[0], idx[1], idx[2]}), r_ref(std_vector)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r_ref({idx[0], idx[1], idx[2]}), r_ref(eigen_matrix)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r_ref(std_vector), r_ref(c_array)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r_ref(std_vector), r_ref(eigen_matrix)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(r_ref(eigen_matrix), r_ref(c_array)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     Index rows = 8; | 
					
						
							|  |  |  |     Index cols = 11; | 
					
						
							|  |  |  |     ArrayXXd R = ArrayXXd::Random(rows, cols); | 
					
						
							|  |  |  |     ArrayXi r_idx = ArrayXi::EqualSpaced(rows, 0, 1); | 
					
						
							|  |  |  |     ArrayXi c_idx = ArrayXi::EqualSpaced(cols, 0, 1); | 
					
						
							|  |  |  |     std::shuffle(r_idx.begin(), r_idx.end(), std::random_device()); | 
					
						
							|  |  |  |     std::shuffle(c_idx.begin(), c_idx.end(), std::random_device()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int c_array_rows[3] = {r_idx[0], r_idx[1], r_idx[2]}; | 
					
						
							|  |  |  |     int c_array_cols[4] = {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}; | 
					
						
							|  |  |  |     std::vector<int> std_vector_rows{r_idx[0], r_idx[1], r_idx[2]}; | 
					
						
							|  |  |  |     std::vector<int> std_vector_cols{c_idx[0], c_idx[1], c_idx[2], c_idx[3]}; | 
					
						
							|  |  |  |     Matrix<int, 3, 1> eigen_matrix_rows{r_idx[0], r_idx[1], r_idx[2]}; | 
					
						
							|  |  |  |     Matrix<int, 4, 1> eigen_matrix_cols{c_idx[0], c_idx[1], c_idx[2], c_idx[3]}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // non-const access
 | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}), | 
					
						
							|  |  |  |                           R(c_array_rows, c_array_cols)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}), | 
					
						
							|  |  |  |                           R(std_vector_rows, std_vector_cols)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}), | 
					
						
							|  |  |  |                           R(eigen_matrix_rows, eigen_matrix_cols)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R(std_vector_rows, std_vector_cols), R(c_array_rows, c_array_cols)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R(std_vector_rows, std_vector_cols), R(eigen_matrix_rows, eigen_matrix_cols)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R(eigen_matrix_rows, eigen_matrix_cols), R(c_array_rows, c_array_cols)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ArrayXXd& R_ref = R; | 
					
						
							|  |  |  |     // const access
 | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R_ref({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}), | 
					
						
							|  |  |  |                           R_ref(c_array_rows, c_array_cols)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R_ref({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}), | 
					
						
							|  |  |  |                           R_ref(std_vector_rows, std_vector_cols)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R_ref({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}), | 
					
						
							|  |  |  |                           R_ref(eigen_matrix_rows, eigen_matrix_cols)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R_ref(std_vector_rows, std_vector_cols), R_ref(c_array_rows, c_array_cols)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R_ref(std_vector_rows, std_vector_cols), R_ref(eigen_matrix_rows, eigen_matrix_cols)); | 
					
						
							|  |  |  |     VERIFY_IS_CWISE_EQUAL(R_ref(eigen_matrix_rows, eigen_matrix_cols), R_ref(c_array_rows, c_array_cols)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 00:10:16 +08:00
										 |  |  |   // check mat(i,j) with weird types for i and j
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(A(B.RowsAtCompileTime - 1, 1), A(3, 1)); | 
					
						
							| 
									
										
										
										
											2017-01-18 16:43:58 +08:00
										 |  |  |     VERIFY_IS_APPROX(A(B.RowsAtCompileTime, 1), A(4, 1)); | 
					
						
							| 
									
										
										
										
											2017-01-18 00:10:16 +08:00
										 |  |  |     VERIFY_IS_APPROX(A(B.RowsAtCompileTime - 1, B.ColsAtCompileTime - 1), A(3, 3)); | 
					
						
							| 
									
										
										
										
											2017-01-18 16:43:58 +08:00
										 |  |  |     VERIFY_IS_APPROX(A(B.RowsAtCompileTime, B.ColsAtCompileTime), A(4, 4)); | 
					
						
							| 
									
										
										
										
											2019-01-25 21:54:39 +08:00
										 |  |  |     const Index I_ = 3, J_ = 4; | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(A(I_, J_), A(3, 4)); | 
					
						
							| 
									
										
										
										
											2017-01-18 00:10:16 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 18:34:28 +08:00
										 |  |  |   // check extended block API
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.block<3, 4>(1, 1), A.block(1, 1, fix<3>, fix<4>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.block<3, 4>(1, 1, 3, 4), A.block(1, 1, fix<3>(), fix<4>(4)))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.block<3, Dynamic>(1, 1, 3, 4), A.block(1, 1, fix<3>, 4))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.block<Dynamic, 4>(1, 1, 3, 4), A.block(1, 1, fix<Dynamic>(3), fix<4>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.block(1, 1, 3, 4), A.block(1, 1, fix<Dynamic>(3), fix<Dynamic>(4)))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 16:43:58 +08:00
										 |  |  |     VERIFY(is_same_eq(A.topLeftCorner<3, 4>(), A.topLeftCorner(fix<3>, fix<4>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.bottomLeftCorner<3, 4>(), A.bottomLeftCorner(fix<3>, fix<4>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.bottomRightCorner<3, 4>(), A.bottomRightCorner(fix<3>, fix<4>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.topRightCorner<3, 4>(), A.topRightCorner(fix<3>, fix<4>))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.leftCols<3>(), A.leftCols(fix<3>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.rightCols<3>(), A.rightCols(fix<3>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.middleCols<3>(1), A.middleCols(1, fix<3>))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.topRows<3>(), A.topRows(fix<3>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.bottomRows<3>(), A.bottomRows(fix<3>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(A.middleRows<3>(1), A.middleRows(1, fix<3>))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     VERIFY(is_same_eq(a.segment<3>(1), a.segment(1, fix<3>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(a.head<3>(), a.head(fix<3>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(a.tail<3>(), a.tail(fix<3>))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 18:34:28 +08:00
										 |  |  |     const ArrayXXi& cA(A); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.block<Dynamic, 4>(1, 1, 3, 4), cA.block(1, 1, fix<Dynamic>(3), fix<4>))); | 
					
						
							| 
									
										
										
										
											2017-01-18 16:43:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.topLeftCorner<3, 4>(), cA.topLeftCorner(fix<3>, fix<4>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.bottomLeftCorner<3, 4>(), cA.bottomLeftCorner(fix<3>, fix<4>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.bottomRightCorner<3, 4>(), cA.bottomRightCorner(fix<3>, fix<4>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.topRightCorner<3, 4>(), cA.topRightCorner(fix<3>, fix<4>))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.leftCols<3>(), cA.leftCols(fix<3>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.rightCols<3>(), cA.rightCols(fix<3>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.middleCols<3>(1), cA.middleCols(1, fix<3>))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.topRows<3>(), cA.topRows(fix<3>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.bottomRows<3>(), cA.bottomRows(fix<3>))); | 
					
						
							|  |  |  |     VERIFY(is_same_eq(cA.middleRows<3>(1), cA.middleRows(1, fix<3>))); | 
					
						
							| 
									
										
										
										
											2017-01-17 18:34:28 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-07 20:34:30 +08:00
										 |  |  |   // Check compilation of enums as index type:
 | 
					
						
							| 
									
										
										
										
											2018-09-11 00:57:28 +08:00
										 |  |  |   a(XX) = 1; | 
					
						
							|  |  |  |   A(XX, YY) = 1; | 
					
						
							|  |  |  |   // Anonymous enums only work with C++11
 | 
					
						
							| 
									
										
										
										
											2017-09-07 20:34:30 +08:00
										 |  |  |   enum { X = 0, Y = 1 }; | 
					
						
							|  |  |  |   a(X) = 1; | 
					
						
							|  |  |  |   A(X, Y) = 1; | 
					
						
							| 
									
										
										
										
											2018-09-11 00:57:28 +08:00
										 |  |  |   A(XX, Y) = 1; | 
					
						
							|  |  |  |   A(X, YY) = 1; | 
					
						
							| 
									
										
										
										
											2023-03-29 09:35:26 +08:00
										 |  |  |   // check symbolic indices
 | 
					
						
							| 
									
										
										
										
											2023-04-17 20:32:50 +08:00
										 |  |  |   a(last) = 1.0; | 
					
						
							| 
									
										
										
										
											2023-03-29 09:35:26 +08:00
										 |  |  |   A(last, last) = 1; | 
					
						
							| 
									
										
										
										
											2023-04-17 20:32:50 +08:00
										 |  |  |   // check weird non-const, non-lvalue scenarios
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     // in these scenarios, the objects are not declared 'const', and the compiler will atttempt to use the non-const
 | 
					
						
							|  |  |  |     // overloads without intervention
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // non-const map to a const object
 | 
					
						
							|  |  |  |     Map<const ArrayXd> a_map(a.data(), a.size()); | 
					
						
							|  |  |  |     Map<const ArrayXXi> A_map(A.data(), A.rows(), A.cols()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     VERIFY_IS_EQUAL(a_map(last), a.coeff(a.size() - 1)); | 
					
						
							|  |  |  |     VERIFY_IS_EQUAL(A_map(last, last), A.coeff(A.rows() - 1, A.cols() - 1)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // non-const expressions that have no modifiable data
 | 
					
						
							|  |  |  |     using Op = internal::scalar_constant_op<double>; | 
					
						
							|  |  |  |     using VectorXpr = CwiseNullaryOp<Op, VectorXd>; | 
					
						
							|  |  |  |     using MatrixXpr = CwiseNullaryOp<Op, MatrixXd>; | 
					
						
							|  |  |  |     double constant_val = internal::random<double>(); | 
					
						
							|  |  |  |     Op op(constant_val); | 
					
						
							|  |  |  |     VectorXpr vectorXpr(10, 1, op); | 
					
						
							|  |  |  |     MatrixXpr matrixXpr(8, 11, op); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     VERIFY_IS_EQUAL(vectorXpr.coeff(vectorXpr.size() - 1), vectorXpr(last)); | 
					
						
							|  |  |  |     VERIFY_IS_EQUAL(matrixXpr.coeff(matrixXpr.rows() - 1, matrixXpr.cols() - 1), matrixXpr(last, last)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-18 19:46:46 +08:00
										 |  |  |   // Check compilation of varying integer types as index types:
 | 
					
						
							|  |  |  |   Index i = n / 2; | 
					
						
							|  |  |  |   short i_short(i); | 
					
						
							|  |  |  |   std::size_t i_sizet(i); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(a(i), a.coeff(i_short)); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(a(i), a.coeff(i_sizet)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(A(i, i), A.coeff(i_short, i_short)); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(A(i, i), A.coeff(i_short, i)); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(A(i, i), A.coeff(i, i_short)); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(A(i, i), A.coeff(i, i_sizet)); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(A(i, i), A.coeff(i_sizet, i)); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(A(i, i), A.coeff(i_sizet, i_short)); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(A(i, i), A.coeff(5, i_sizet)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-09 01:40:22 +08:00
										 |  |  |   // Regression test for Max{Rows,Cols}AtCompileTime
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     Matrix3i A3 = Matrix3i::Random(); | 
					
						
							|  |  |  |     ArrayXi ind(5); | 
					
						
							|  |  |  |     ind << 1, 1, 1, 1, 1; | 
					
						
							|  |  |  |     VERIFY_IS_EQUAL(A3(ind, ind).eval(), MatrixXi::Constant(5, 5, A3(1, 1))); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 21:40:07 +08:00
										 |  |  |   // Regression for bug 1736
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(A(all, eii).col(0).eval(), A.col(eii(0))); | 
					
						
							|  |  |  |     A(all, eii).col(0) = A.col(eii(0)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 03:24:42 +08:00
										 |  |  |   // bug 1815: IndexedView should allow linear access
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     VERIFY(MATCH(b(eii)(0), "3")); | 
					
						
							|  |  |  |     VERIFY(MATCH(a(eii)(0), "3")); | 
					
						
							|  |  |  |     VERIFY(MATCH(A(1, eii)(0), "103")); | 
					
						
							|  |  |  |     VERIFY(MATCH(A(eii, 1)(0), "301")); | 
					
						
							|  |  |  |     VERIFY(MATCH(A(1, all)(1), "101")); | 
					
						
							|  |  |  |     VERIFY(MATCH(A(all, 1)(1), "101")); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-30 06:26:15 +08:00
										 |  |  |   // bug #2375: indexing over matrices of dim >128 should compile on gcc
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     Matrix<double, 513, 3> large_mat = Matrix<double, 513, 3>::Random(); | 
					
						
							|  |  |  |     std::array<int, 2> test_indices = {0, 1}; | 
					
						
							|  |  |  |     Matrix<double, 513, 2> thin_slice = large_mat(all, test_indices); | 
					
						
							|  |  |  |     for (int col = 0; col < int(test_indices.size()); ++col) | 
					
						
							|  |  |  |       for (int row = 0; row < large_mat.rows(); ++row) VERIFY_IS_EQUAL(thin_slice(row, col), large_mat(row, col)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-15 06:11:19 +08:00
										 |  |  |   // Bug IndexView with a single static row should be RowMajor:
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     // A(1, seq(0,2,1)).cwiseAbs().colwise().replicate(2).eval();
 | 
					
						
							|  |  |  |     STATIC_CHECK(((internal::evaluator<decltype(A(1, seq(0, 2, 1)))>::Flags & RowMajorBit) == RowMajorBit)); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 20:46:15 +08:00
										 |  |  | EIGEN_DECLARE_TEST(indexed_view) { | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  |   //   for(int i = 0; i < g_repeat; i++) {
 | 
					
						
							|  |  |  |   CALL_SUBTEST_1(check_indexed_view()); | 
					
						
							|  |  |  |   //   }
 | 
					
						
							| 
									
										
										
										
											2018-05-18 19:59:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // static checks of some internals:
 | 
					
						
							|  |  |  |   STATIC_CHECK((internal::is_valid_index_type<int>::value)); | 
					
						
							|  |  |  |   STATIC_CHECK((internal::is_valid_index_type<unsigned int>::value)); | 
					
						
							|  |  |  |   STATIC_CHECK((internal::is_valid_index_type<short>::value)); | 
					
						
							|  |  |  |   STATIC_CHECK((internal::is_valid_index_type<std::ptrdiff_t>::value)); | 
					
						
							|  |  |  |   STATIC_CHECK((internal::is_valid_index_type<std::size_t>::value)); | 
					
						
							|  |  |  |   STATIC_CHECK((!internal::valid_indexed_view_overload<int, int>::value)); | 
					
						
							|  |  |  |   STATIC_CHECK((!internal::valid_indexed_view_overload<int, std::ptrdiff_t>::value)); | 
					
						
							|  |  |  |   STATIC_CHECK((!internal::valid_indexed_view_overload<std::ptrdiff_t, int>::value)); | 
					
						
							|  |  |  |   STATIC_CHECK((!internal::valid_indexed_view_overload<std::size_t, int>::value)); | 
					
						
							| 
									
										
										
										
											2017-01-06 18:59:08 +08:00
										 |  |  | } |