| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-11 22:39:48 +08:00
										 |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation, | 
					
						
							| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    timeublas.cpp | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |  * @brief   Tests to help determine which way of accomplishing something with Eigen is faster | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |  * @author  Richard Roberts | 
					
						
							| 
									
										
										
										
											2011-10-23 03:48:52 +08:00
										 |  |  |  * @date    Sep 18, 2010 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  | #include <gtsam/base/timing.h>
 | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | #include <gtsam/base/Matrix.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <iostream>
 | 
					
						
							| 
									
										
										
										
											2020-07-24 02:05:23 +08:00
										 |  |  | #include <random>
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <utility>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | //namespace ublas = boost::numeric::ublas;
 | 
					
						
							|  |  |  | //using namespace Eigen;
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-24 02:05:23 +08:00
										 |  |  | static std::mt19937 rng; | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  | static std::uniform_real_distribution<> uniform(-1.0, 0.0); | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | //typedef ublas::matrix<double> matrix;
 | 
					
						
							|  |  |  | //typedef ublas::matrix_range<matrix> matrix_range;
 | 
					
						
							| 
									
										
										
										
											2012-12-29 10:23:32 +08:00
										 |  |  | //typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> matrix;
 | 
					
						
							|  |  |  | //typedef Eigen::Block<matrix> matrix_block;
 | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | //using ublas::range;
 | 
					
						
							|  |  |  | //using ublas::triangular_matrix;
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | int main(int argc, char* argv[]) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |   if(true) { | 
					
						
							|  |  |  |     cout << "\nTiming matrix_block:" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // We use volatile here to make these appear to the optimizing compiler as
 | 
					
						
							|  |  |  |     // if their values are only known at run-time.
 | 
					
						
							|  |  |  |     volatile size_t m=500; | 
					
						
							|  |  |  |     volatile size_t n=300; | 
					
						
							|  |  |  |     volatile size_t nReps = 1000; | 
					
						
							|  |  |  |     assert(m > n); | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |     std::uniform_int_distribution<size_t> uniform_i(0,m-1); | 
					
						
							|  |  |  |     std::uniform_int_distribution<size_t> uniform_j(0,n-1); | 
					
						
							| 
									
										
										
										
											2012-12-29 10:23:32 +08:00
										 |  |  |     gtsam::Matrix mat((int)m,(int)n); | 
					
						
							|  |  |  |     gtsam::SubMatrix full = mat.block(0, 0, m, n); | 
					
						
							|  |  |  |     gtsam::SubMatrix top = mat.block(0, 0, n, n); | 
					
						
							|  |  |  |     gtsam::SubMatrix block = mat.block(m/4, n/4, m-m/2, n-n/2); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-21 05:04:12 +08:00
										 |  |  |     cout << "  Basic: " << (int)m << "x" << (int)n << endl; | 
					
						
							|  |  |  |     cout << "  Full:  mat(" << 0 << ":" << (int)m << ", " << 0 << ":" << (int)n << ")" << endl; | 
					
						
							|  |  |  |     cout << "  Top:   mat(" << 0 << ":" << (int)n << ", " << 0 << ":" << (int)n << ")" << endl; | 
					
						
							|  |  |  |     cout << "  Block: mat(" << size_t(m/4) << ":" << size_t(m-m/4) << ", " << size_t(n/4) << ":" << size_t(n-n/4) << ")" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     cout << endl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       double basicTime, fullTime, topTime, blockTime; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       cout << "Row-major matrix, row-major assignment:" << endl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Do a few initial assignments to let any cache effects stabilize
 | 
					
						
							|  |  |  |       for(size_t rep=0; rep<1000; ++rep) | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |         for(size_t i=0; i<(size_t)mat.rows(); ++i) | 
					
						
							|  |  |  |           for(size_t j=0; j<(size_t)mat.cols(); ++j) | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |             mat(i,j) = uniform(rng); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(basicTime); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<nReps; ++rep) | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |         for(size_t i=0; i<(size_t)mat.rows(); ++i) | 
					
						
							|  |  |  |           for(size_t j=0; j<(size_t)mat.cols(); ++j) | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |             mat(i,j) = uniform(rng); | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(basicTime); | 
					
						
							|  |  |  |       tictoc_getNode(basicTimeNode, basicTime); | 
					
						
							|  |  |  |       basicTime = basicTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Basic: " << double(1000000 * basicTime / double(mat.rows()*mat.cols()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(fullTime); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<nReps; ++rep) | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |         for(size_t i=0; i<(size_t)full.rows(); ++i) | 
					
						
							|  |  |  |           for(size_t j=0; j<(size_t)full.cols(); ++j) | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |             full(i,j) = uniform(rng); | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(fullTime); | 
					
						
							|  |  |  |       tictoc_getNode(fullTimeNode, fullTime); | 
					
						
							|  |  |  |       fullTime = fullTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Full:  " << double(1000000 * fullTime / double(full.rows()*full.cols()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(topTime); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<nReps; ++rep) | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |         for(size_t i=0; i<(size_t)top.rows(); ++i) | 
					
						
							|  |  |  |           for(size_t j=0; j<(size_t)top.cols(); ++j) | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |             top(i,j) = uniform(rng); | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(topTime); | 
					
						
							|  |  |  |       tictoc_getNode(topTimeNode, topTime); | 
					
						
							|  |  |  |       topTime = topTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Top:   " << double(1000000 * topTime / double(top.rows()*top.cols()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(blockTime); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<nReps; ++rep) | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |         for(size_t i=0; i<(size_t)block.rows(); ++i) | 
					
						
							|  |  |  |           for(size_t j=0; j<(size_t)block.cols(); ++j) | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |             block(i,j) = uniform(rng); | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(blockTime); | 
					
						
							|  |  |  |       tictoc_getNode(blockTimeNode, blockTime); | 
					
						
							|  |  |  |       blockTime = blockTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Block: " << double(1000000 * blockTime / double(block.rows()*block.cols()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cout << endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       double basicTime, fullTime, topTime, blockTime; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       cout << "Row-major matrix, column-major assignment:" << endl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Do a few initial assignments to let any cache effects stabilize
 | 
					
						
							|  |  |  |       for(size_t rep=0; rep<1000; ++rep) | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |         for(size_t j=0; j<(size_t)mat.cols(); ++j) | 
					
						
							|  |  |  |           for(size_t i=0; i<(size_t)mat.rows(); ++i) | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |             mat(i,j) = uniform(rng); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(basicTime); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<nReps; ++rep) | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |         for(size_t j=0; j<(size_t)mat.cols(); ++j) | 
					
						
							|  |  |  |           for(size_t i=0; i<(size_t)mat.rows(); ++i) | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |             mat(i,j) = uniform(rng); | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(basicTime); | 
					
						
							|  |  |  |       tictoc_getNode(basicTimeNode, basicTime); | 
					
						
							|  |  |  |       basicTime = basicTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Basic: " << double(1000000 * basicTime / double(mat.rows()*mat.cols()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(fullTime); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<nReps; ++rep) | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |         for(size_t j=0; j<(size_t)full.cols(); ++j) | 
					
						
							|  |  |  |           for(size_t i=0; i<(size_t)full.rows(); ++i) | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |             full(i,j) = uniform(rng); | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(fullTime); | 
					
						
							|  |  |  |       tictoc_getNode(fullTimeNode, fullTime); | 
					
						
							|  |  |  |       fullTime = fullTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Full:  " << double(1000000 * fullTime / double(full.rows()*full.cols()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(topTime); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<nReps; ++rep) | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |         for(size_t j=0; j<(size_t)top.cols(); ++j) | 
					
						
							|  |  |  |           for(size_t i=0; i<(size_t)top.rows(); ++i) | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |             top(i,j) = uniform(rng); | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(topTime); | 
					
						
							|  |  |  |       tictoc_getNode(topTimeNode, topTime); | 
					
						
							|  |  |  |       topTime = topTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Top:   " << double(1000000 * topTime / double(top.rows()*top.cols()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(blockTime); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<nReps; ++rep) | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  |         for(size_t j=0; j<(size_t)block.cols(); ++j) | 
					
						
							|  |  |  |           for(size_t i=0; i<(size_t)block.rows(); ++i) | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  |             block(i,j) = uniform(rng); | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(blockTime); | 
					
						
							|  |  |  |       tictoc_getNode(blockTimeNode, blockTime); | 
					
						
							|  |  |  |       blockTime = blockTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Block: " << double(1000000 * blockTime / double(block.rows()*block.cols()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cout << endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       double basicTime, fullTime, topTime, blockTime; | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       typedef std::pair<size_t,size_t> ij_t; | 
					
						
							|  |  |  |       std::vector<ij_t> ijs(100000); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cout << "Row-major matrix, random assignment:" << endl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Do a few initial assignments to let any cache effects stabilize
 | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       for (auto& ij : ijs) ij = {uniform_i(rng), uniform_j(rng)}; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<1000; ++rep) | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |         for(const auto& [i, j]: ijs) { mat(i, j) = uniform(rng); } | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(basicTime); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       for (auto& ij : ijs) ij = {uniform_i(rng), uniform_j(rng)}; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<1000; ++rep) | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |         for(const auto& [i, j]: ijs) { mat(i, j) = uniform(rng); } | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(basicTime); | 
					
						
							|  |  |  |       tictoc_getNode(basicTimeNode, basicTime); | 
					
						
							|  |  |  |       basicTime = basicTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Basic: " << double(1000000 * basicTime / double(ijs.size()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(fullTime); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       for (auto& ij : ijs) ij = {uniform_i(rng), uniform_j(rng)}; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<1000; ++rep) | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |         for(const auto& [i, j]: ijs) { full(i, j) = uniform(rng); } | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(fullTime); | 
					
						
							|  |  |  |       tictoc_getNode(fullTimeNode, fullTime); | 
					
						
							|  |  |  |       fullTime = fullTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Full:  " << double(1000000 * fullTime / double(ijs.size()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(topTime); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       for (auto& ij : ijs) ij = {uniform_i(rng) % top.rows(), uniform_j(rng)}; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<1000; ++rep) | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |         for(const auto& [i, j]: ijs) { top(i, j) = uniform(rng); } | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(topTime); | 
					
						
							|  |  |  |       tictoc_getNode(topTimeNode, topTime); | 
					
						
							|  |  |  |       topTime = topTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Top:   " << double(1000000 * topTime / double(ijs.size()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttic_(blockTime); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       for (auto& ij : ijs) | 
					
						
							|  |  |  |         ij = {uniform_i(rng) % block.rows(), uniform_j(rng) % block.cols()}; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |       for(size_t rep=0; rep<1000; ++rep) | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |         for(const auto& [i, j]: ijs) { block(i, j) = uniform(rng); } | 
					
						
							| 
									
										
										
										
											2020-05-10 09:29:08 +08:00
										 |  |  |       gttoc_(blockTime); | 
					
						
							|  |  |  |       tictoc_getNode(blockTimeNode, blockTime); | 
					
						
							|  |  |  |       blockTime = blockTimeNode->secs(); | 
					
						
							|  |  |  |       gtsam::tictoc_reset_(); | 
					
						
							| 
									
										
										
										
											2023-02-05 04:50:25 +08:00
										 |  |  |       cout << "  Block: " << double(1000000 * blockTime / double(ijs.size()*nReps)) << " μs/element" << endl; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cout << endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | //  if(true) {
 | 
					
						
							|  |  |  | //    cout << "\nTesting square triangular matrices:" << endl;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | ////    typedef triangular_matrix<double, ublas::upper, ublas::column_major> triangular;
 | 
					
						
							|  |  |  | ////    typedef ublas::matrix<double, ublas::column_major> matrix;
 | 
					
						
							|  |  |  | //    typedef MatrixXd matrix; // default col major
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | ////    triangular tri(5,5);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    matrix mat(5,5);
 | 
					
						
							|  |  |  | //    for(size_t j=0; j<(size_t)mat.cols(); ++j)
 | 
					
						
							|  |  |  | //      for(size_t i=0; i<(size_t)mat.rows(); ++i)
 | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  | //        mat(i,j) = uniform(rng);
 | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //    tri = ublas::triangular_adaptor<matrix, ublas::upper>(mat);
 | 
					
						
							|  |  |  | //    cout << "  Assigned from triangular adapter: " << tri << endl;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    cout << "  Triangular adapter of mat: " << ublas::triangular_adaptor<matrix, ublas::upper>(mat) << endl;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    for(size_t j=0; j<(size_t)mat.cols(); ++j)
 | 
					
						
							|  |  |  | //      for(size_t i=0; i<(size_t)mat.rows(); ++i)
 | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  | //        mat(i,j) = uniform(rng);
 | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | //    mat = tri;
 | 
					
						
							|  |  |  | //    cout << "  Assign matrix from triangular: " << mat << endl;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    for(size_t j=0; j<(size_t)mat.cols(); ++j)
 | 
					
						
							|  |  |  | //      for(size_t i=0; i<(size_t)mat.rows(); ++i)
 | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  | //        mat(i,j) = uniform(rng);
 | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | //    (ublas::triangular_adaptor<matrix, ublas::upper>(mat)) = tri;
 | 
					
						
							|  |  |  | //    cout << "  Assign triangular adaptor from triangular: " << mat << endl;
 | 
					
						
							|  |  |  | //  }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  {
 | 
					
						
							|  |  |  | //    cout << "\nTesting wide triangular matrices:" << endl;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    typedef triangular_matrix<double, ublas::upper, ublas::column_major> triangular;
 | 
					
						
							|  |  |  | //    typedef ublas::matrix<double, ublas::column_major> matrix;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    triangular tri(5,7);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    matrix mat(5,7);
 | 
					
						
							|  |  |  | //    for(size_t j=0; j<(size_t)mat.cols(); ++j)
 | 
					
						
							|  |  |  | //      for(size_t i=0; i<(size_t)mat.rows(); ++i)
 | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  | //        mat(i,j) = uniform(rng);
 | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //    tri = ublas::triangular_adaptor<matrix, ublas::upper>(mat);
 | 
					
						
							|  |  |  | //    cout << "  Assigned from triangular adapter: " << tri << endl;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    cout << "  Triangular adapter of mat: " << ublas::triangular_adaptor<matrix, ublas::upper>(mat) << endl;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    for(size_t j=0; j<(size_t)mat.cols(); ++j)
 | 
					
						
							|  |  |  | //      for(size_t i=0; i<(size_t)mat.rows(); ++i)
 | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  | //        mat(i,j) = uniform(rng);
 | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | //    mat = tri;
 | 
					
						
							|  |  |  | //    cout << "  Assign matrix from triangular: " << mat << endl;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    for(size_t j=0; j<(size_t)mat.cols(); ++j)
 | 
					
						
							|  |  |  | //      for(size_t i=0; i<(size_t)mat.rows(); ++i)
 | 
					
						
							| 
									
										
										
										
											2020-07-24 02:49:13 +08:00
										 |  |  | //        mat(i,j) = uniform(rng);
 | 
					
						
							| 
									
										
										
										
											2011-05-21 02:43:37 +08:00
										 |  |  | //    mat = ublas::triangular_adaptor<matrix, ublas::upper>(mat);
 | 
					
						
							|  |  |  | //    cout << "  Assign matrix from triangular adaptor of self: " << mat << endl;
 | 
					
						
							|  |  |  | //  }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  {
 | 
					
						
							|  |  |  | //    cout << "\nTesting subvectors:" << endl;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    typedef MatrixXd matrix;
 | 
					
						
							|  |  |  | //    matrix mat(4,4);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    for(size_t j=0; j<(size_t)mat.cols(); ++j)
 | 
					
						
							|  |  |  | //      for(size_t i=0; i<(size_t)mat.rows(); ++i)
 | 
					
						
							|  |  |  | //        mat(i,j) = i*mat.rows() + j;
 | 
					
						
							|  |  |  | //    cout << "  mat = " << mat;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //    cout << "  vec(1:4, 2:2) = " << mat.block(1,2, ), ublas::range(1,4), ublas::range(2,2));
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  }
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |