| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  | // This file is part of Eigen, a lightweight C++ template library
 | 
					
						
							| 
									
										
										
										
											2009-05-23 02:25:33 +08:00
										 |  |  | // for linear algebra.
 | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2010-06-25 05:21:58 +08:00
										 |  |  | // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
 | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2012-07-14 02:42:47 +08:00
										 |  |  | // 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/.
 | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "main.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-08 23:26:48 +08:00
										 |  |  | template <int M1, int M2, int N1, int N2> | 
					
						
							|  |  |  | void test_blocks() { | 
					
						
							|  |  |  |   Matrix<int, M1 + M2, N1 + N2> m_fixed; | 
					
						
							|  |  |  |   MatrixXi m_dynamic(M1 + M2, N1 + N2); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-08 23:26:48 +08:00
										 |  |  |   Matrix<int, M1, N1> mat11; | 
					
						
							|  |  |  |   mat11.setRandom(); | 
					
						
							|  |  |  |   Matrix<int, M1, N2> mat12; | 
					
						
							|  |  |  |   mat12.setRandom(); | 
					
						
							|  |  |  |   Matrix<int, M2, N1> mat21; | 
					
						
							|  |  |  |   mat21.setRandom(); | 
					
						
							|  |  |  |   Matrix<int, M2, N2> mat22; | 
					
						
							|  |  |  |   mat22.setRandom(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   MatrixXi matx11 = mat11, matx12 = mat12, matx21 = mat21, matx22 = mat22; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     VERIFY_IS_EQUAL((m_fixed << mat11, mat12, mat21, matx22).finished(), | 
					
						
							|  |  |  |                     (m_dynamic << mat11, matx12, mat21, matx22).finished()); | 
					
						
							| 
									
										
										
										
											2016-08-12 21:15:34 +08:00
										 |  |  |     VERIFY_IS_EQUAL((m_fixed.template topLeftCorner<M1, N1>()), mat11); | 
					
						
							|  |  |  |     VERIFY_IS_EQUAL((m_fixed.template topRightCorner<M1, N2>()), mat12); | 
					
						
							|  |  |  |     VERIFY_IS_EQUAL((m_fixed.template bottomLeftCorner<M2, N1>()), mat21); | 
					
						
							|  |  |  |     VERIFY_IS_EQUAL((m_fixed.template bottomRightCorner<M2, N2>()), mat22); | 
					
						
							| 
									
										
										
										
											2016-08-08 23:26:48 +08:00
										 |  |  |     VERIFY_IS_EQUAL((m_fixed << mat12, mat11, matx21, mat22).finished(), | 
					
						
							|  |  |  |                     (m_dynamic << mat12, matx11, matx21, mat22).finished()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (N1 > 0) { | 
					
						
							| 
									
										
										
										
											2020-04-13 22:41:20 +08:00
										 |  |  |     if (M1 > 0) { | 
					
						
							|  |  |  |       VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat11, mat21, mat22)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (M2 > 0) { | 
					
						
							|  |  |  |       VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat21, mat21, mat22)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-08-12 21:15:34 +08:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2016-08-08 23:26:48 +08:00
										 |  |  |     // allow insertion of zero-column blocks:
 | 
					
						
							|  |  |  |     VERIFY_IS_EQUAL((m_fixed << mat11, mat12, mat11, mat11, mat21, mat21, mat22).finished(), | 
					
						
							|  |  |  |                     (m_dynamic << mat12, mat22).finished()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (M1 != M2) { | 
					
						
							|  |  |  |     VERIFY_RAISES_ASSERT((m_fixed << mat11, mat21, mat12, mat22)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 22:41:20 +08:00
										 |  |  | template <int depth, int N = 0> | 
					
						
							| 
									
										
										
										
											2016-08-08 23:26:48 +08:00
										 |  |  | struct test_block_recursion { | 
					
						
							|  |  |  |   static void run() { | 
					
						
							| 
									
										
										
										
											2020-04-13 22:41:20 +08:00
										 |  |  |     test_block_recursion<depth - 1, N>::run(); | 
					
						
							|  |  |  |     test_block_recursion<depth - 1, N + (1 << (depth - 1))>::run(); | 
					
						
							| 
									
										
										
										
											2016-08-08 23:26:48 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 22:41:20 +08:00
										 |  |  | template <int N> | 
					
						
							|  |  |  | struct test_block_recursion<0, N> { | 
					
						
							|  |  |  |   static void run() { test_blocks<(N >> 6) & 3, (N >> 4) & 3, (N >> 2) & 3, N & 3>(); } | 
					
						
							| 
									
										
										
										
											2016-08-08 23:26:48 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-18 20:28:51 +08:00
										 |  |  | void test_basics() { | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  |   Matrix3d m3; | 
					
						
							|  |  |  |   Matrix4d m4; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   VERIFY_RAISES_ASSERT((m3 << 1, 2, 3, 4, 5, 6, 7, 8)); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-23 20:26:32 +08:00
										 |  |  | #ifndef _MSC_VER
 | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  |   VERIFY_RAISES_ASSERT((m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); | 
					
						
							| 
									
										
										
										
											2009-01-23 20:26:32 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   double data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; | 
					
						
							| 
									
										
										
										
											2008-08-24 01:11:44 +08:00
										 |  |  |   Matrix3d ref = Map<Matrix<double, 3, 3, RowMajor> >(data); | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-21 08:34:46 +08:00
										 |  |  |   m3 = Matrix3d::Random(); | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  |   m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9; | 
					
						
							| 
									
										
										
										
											2008-08-21 04:08:38 +08:00
										 |  |  |   VERIFY_IS_APPROX(m3, ref); | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Vector3d vec[3]; | 
					
						
							|  |  |  |   vec[0] << 1, 4, 7; | 
					
						
							|  |  |  |   vec[1] << 2, 5, 8; | 
					
						
							|  |  |  |   vec[2] << 3, 6, 9; | 
					
						
							| 
									
										
										
										
											2008-07-21 08:34:46 +08:00
										 |  |  |   m3 = Matrix3d::Random(); | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  |   m3 << vec[0], vec[1], vec[2]; | 
					
						
							| 
									
										
										
										
											2008-08-21 04:08:38 +08:00
										 |  |  |   VERIFY_IS_APPROX(m3, ref); | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   vec[0] << 1, 2, 3; | 
					
						
							|  |  |  |   vec[1] << 4, 5, 6; | 
					
						
							|  |  |  |   vec[2] << 7, 8, 9; | 
					
						
							| 
									
										
										
										
											2008-07-21 08:34:46 +08:00
										 |  |  |   m3 = Matrix3d::Random(); | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  |   m3 << vec[0].transpose(), 4, 5, 6, vec[2].transpose(); | 
					
						
							| 
									
										
										
										
											2008-08-21 04:08:38 +08:00
										 |  |  |   VERIFY_IS_APPROX(m3, ref); | 
					
						
							| 
									
										
										
										
											2021-03-18 20:28:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EIGEN_DECLARE_TEST(commainitializer) { | 
					
						
							|  |  |  |   CALL_SUBTEST_1(test_basics()); | 
					
						
							| 
									
										
										
										
											2016-06-23 16:25:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-08 23:26:48 +08:00
										 |  |  |   // recursively test all block-sizes from 0 to 3:
 | 
					
						
							| 
									
										
										
										
											2021-03-18 20:28:51 +08:00
										 |  |  |   CALL_SUBTEST_2(test_block_recursion<8>::run()); | 
					
						
							| 
									
										
										
										
											2008-05-22 20:18:55 +08:00
										 |  |  | } |