use reasonable distribution names
parent
e993afe2bf
commit
d5d58fd707
|
@ -34,7 +34,7 @@ using boost::format;
|
|||
using namespace boost::lambda;
|
||||
|
||||
static std::mt19937 rng;
|
||||
static std::uniform_real_distribution<> rg(-1.0, 0.0);
|
||||
static std::uniform_real_distribution<> uniform(-1.0, 0.0);
|
||||
//typedef ublas::matrix<double> matrix;
|
||||
//typedef ublas::matrix_range<matrix> matrix_range;
|
||||
//typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> matrix;
|
||||
|
@ -54,8 +54,8 @@ int main(int argc, char* argv[]) {
|
|||
volatile size_t n=300;
|
||||
volatile size_t nReps = 1000;
|
||||
assert(m > n);
|
||||
std::uniform_int_distribution<size_t> ri(0,m-1);
|
||||
std::uniform_int_distribution<size_t> rj(0,n-1);
|
||||
std::uniform_int_distribution<size_t> uniform_i(0,m-1);
|
||||
std::uniform_int_distribution<size_t> uniform_j(0,n-1);
|
||||
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);
|
||||
|
@ -76,13 +76,13 @@ int main(int argc, char* argv[]) {
|
|||
for(size_t rep=0; rep<1000; ++rep)
|
||||
for(size_t i=0; i<(size_t)mat.rows(); ++i)
|
||||
for(size_t j=0; j<(size_t)mat.cols(); ++j)
|
||||
mat(i,j) = rg(rng);
|
||||
mat(i,j) = uniform(rng);
|
||||
|
||||
gttic_(basicTime);
|
||||
for(size_t rep=0; rep<nReps; ++rep)
|
||||
for(size_t i=0; i<(size_t)mat.rows(); ++i)
|
||||
for(size_t j=0; j<(size_t)mat.cols(); ++j)
|
||||
mat(i,j) = rg(rng);
|
||||
mat(i,j) = uniform(rng);
|
||||
gttoc_(basicTime);
|
||||
tictoc_getNode(basicTimeNode, basicTime);
|
||||
basicTime = basicTimeNode->secs();
|
||||
|
@ -93,7 +93,7 @@ int main(int argc, char* argv[]) {
|
|||
for(size_t rep=0; rep<nReps; ++rep)
|
||||
for(size_t i=0; i<(size_t)full.rows(); ++i)
|
||||
for(size_t j=0; j<(size_t)full.cols(); ++j)
|
||||
full(i,j) = rg(rng);
|
||||
full(i,j) = uniform(rng);
|
||||
gttoc_(fullTime);
|
||||
tictoc_getNode(fullTimeNode, fullTime);
|
||||
fullTime = fullTimeNode->secs();
|
||||
|
@ -104,7 +104,7 @@ int main(int argc, char* argv[]) {
|
|||
for(size_t rep=0; rep<nReps; ++rep)
|
||||
for(size_t i=0; i<(size_t)top.rows(); ++i)
|
||||
for(size_t j=0; j<(size_t)top.cols(); ++j)
|
||||
top(i,j) = rg(rng);
|
||||
top(i,j) = uniform(rng);
|
||||
gttoc_(topTime);
|
||||
tictoc_getNode(topTimeNode, topTime);
|
||||
topTime = topTimeNode->secs();
|
||||
|
@ -115,7 +115,7 @@ int main(int argc, char* argv[]) {
|
|||
for(size_t rep=0; rep<nReps; ++rep)
|
||||
for(size_t i=0; i<(size_t)block.rows(); ++i)
|
||||
for(size_t j=0; j<(size_t)block.cols(); ++j)
|
||||
block(i,j) = rg(rng);
|
||||
block(i,j) = uniform(rng);
|
||||
gttoc_(blockTime);
|
||||
tictoc_getNode(blockTimeNode, blockTime);
|
||||
blockTime = blockTimeNode->secs();
|
||||
|
@ -134,13 +134,13 @@ int main(int argc, char* argv[]) {
|
|||
for(size_t rep=0; rep<1000; ++rep)
|
||||
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) = rg(rng);
|
||||
mat(i,j) = uniform(rng);
|
||||
|
||||
gttic_(basicTime);
|
||||
for(size_t rep=0; rep<nReps; ++rep)
|
||||
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) = rg(rng);
|
||||
mat(i,j) = uniform(rng);
|
||||
gttoc_(basicTime);
|
||||
tictoc_getNode(basicTimeNode, basicTime);
|
||||
basicTime = basicTimeNode->secs();
|
||||
|
@ -151,7 +151,7 @@ int main(int argc, char* argv[]) {
|
|||
for(size_t rep=0; rep<nReps; ++rep)
|
||||
for(size_t j=0; j<(size_t)full.cols(); ++j)
|
||||
for(size_t i=0; i<(size_t)full.rows(); ++i)
|
||||
full(i,j) = rg(rng);
|
||||
full(i,j) = uniform(rng);
|
||||
gttoc_(fullTime);
|
||||
tictoc_getNode(fullTimeNode, fullTime);
|
||||
fullTime = fullTimeNode->secs();
|
||||
|
@ -162,7 +162,7 @@ int main(int argc, char* argv[]) {
|
|||
for(size_t rep=0; rep<nReps; ++rep)
|
||||
for(size_t j=0; j<(size_t)top.cols(); ++j)
|
||||
for(size_t i=0; i<(size_t)top.rows(); ++i)
|
||||
top(i,j) = rg(rng);
|
||||
top(i,j) = uniform(rng);
|
||||
gttoc_(topTime);
|
||||
tictoc_getNode(topTimeNode, topTime);
|
||||
topTime = topTimeNode->secs();
|
||||
|
@ -173,7 +173,7 @@ int main(int argc, char* argv[]) {
|
|||
for(size_t rep=0; rep<nReps; ++rep)
|
||||
for(size_t j=0; j<(size_t)block.cols(); ++j)
|
||||
for(size_t i=0; i<(size_t)block.rows(); ++i)
|
||||
block(i,j) = rg(rng);
|
||||
block(i,j) = uniform(rng);
|
||||
gttoc_(blockTime);
|
||||
tictoc_getNode(blockTimeNode, blockTime);
|
||||
blockTime = blockTimeNode->secs();
|
||||
|
@ -191,14 +191,14 @@ int main(int argc, char* argv[]) {
|
|||
cout << "Row-major matrix, random assignment:" << endl;
|
||||
|
||||
// Do a few initial assignments to let any cache effects stabilize
|
||||
for_each(ijs.begin(), ijs.end(), _1 = make_pair(ri(rng),rj(rng)));
|
||||
for_each(ijs.begin(), ijs.end(), _1 = make_pair(uniform_i(rng),uniform_j(rng)));
|
||||
for(size_t rep=0; rep<1000; ++rep)
|
||||
for(const ij_t& ij: ijs) { mat(ij.first, ij.second) = rg(rng); }
|
||||
for(const ij_t& ij: ijs) { mat(ij.first, ij.second) = uniform(rng); }
|
||||
|
||||
gttic_(basicTime);
|
||||
for_each(ijs.begin(), ijs.end(), _1 = make_pair(ri(rng),rj(rng)));
|
||||
for_each(ijs.begin(), ijs.end(), _1 = make_pair(uniform_i(rng),uniform_j(rng)));
|
||||
for(size_t rep=0; rep<1000; ++rep)
|
||||
for(const ij_t& ij: ijs) { mat(ij.first, ij.second) = rg(rng); }
|
||||
for(const ij_t& ij: ijs) { mat(ij.first, ij.second) = uniform(rng); }
|
||||
gttoc_(basicTime);
|
||||
tictoc_getNode(basicTimeNode, basicTime);
|
||||
basicTime = basicTimeNode->secs();
|
||||
|
@ -206,9 +206,9 @@ int main(int argc, char* argv[]) {
|
|||
cout << format(" Basic: %1% mus/element") % double(1000000 * basicTime / double(ijs.size()*nReps)) << endl;
|
||||
|
||||
gttic_(fullTime);
|
||||
for_each(ijs.begin(), ijs.end(), _1 = make_pair(ri(rng),rj(rng)));
|
||||
for_each(ijs.begin(), ijs.end(), _1 = make_pair(uniform_i(rng),uniform_j(rng)));
|
||||
for(size_t rep=0; rep<1000; ++rep)
|
||||
for(const ij_t& ij: ijs) { full(ij.first, ij.second) = rg(rng); }
|
||||
for(const ij_t& ij: ijs) { full(ij.first, ij.second) = uniform(rng); }
|
||||
gttoc_(fullTime);
|
||||
tictoc_getNode(fullTimeNode, fullTime);
|
||||
fullTime = fullTimeNode->secs();
|
||||
|
@ -216,9 +216,9 @@ int main(int argc, char* argv[]) {
|
|||
cout << format(" Full: %1% mus/element") % double(1000000 * fullTime / double(ijs.size()*nReps)) << endl;
|
||||
|
||||
gttic_(topTime);
|
||||
for_each(ijs.begin(), ijs.end(), _1 = make_pair(ri(rng)%top.rows(),rj(rng)));
|
||||
for_each(ijs.begin(), ijs.end(), _1 = make_pair(uniform_i(rng)%top.rows(),uniform_j(rng)));
|
||||
for(size_t rep=0; rep<1000; ++rep)
|
||||
for(const ij_t& ij: ijs) { top(ij.first, ij.second) = rg(rng); }
|
||||
for(const ij_t& ij: ijs) { top(ij.first, ij.second) = uniform(rng); }
|
||||
gttoc_(topTime);
|
||||
tictoc_getNode(topTimeNode, topTime);
|
||||
topTime = topTimeNode->secs();
|
||||
|
@ -226,9 +226,9 @@ int main(int argc, char* argv[]) {
|
|||
cout << format(" Top: %1% mus/element") % double(1000000 * topTime / double(ijs.size()*nReps)) << endl;
|
||||
|
||||
gttic_(blockTime);
|
||||
for_each(ijs.begin(), ijs.end(), _1 = make_pair(ri(rng)%block.rows(),rj(rng)%block.cols()));
|
||||
for_each(ijs.begin(), ijs.end(), _1 = make_pair(uniform_i(rng)%block.rows(),uniform_j(rng)%block.cols()));
|
||||
for(size_t rep=0; rep<1000; ++rep)
|
||||
for(const ij_t& ij: ijs) { block(ij.first, ij.second) = rg(rng); }
|
||||
for(const ij_t& ij: ijs) { block(ij.first, ij.second) = uniform(rng); }
|
||||
gttoc_(blockTime);
|
||||
tictoc_getNode(blockTimeNode, blockTime);
|
||||
blockTime = blockTimeNode->secs();
|
||||
|
@ -251,7 +251,7 @@ int main(int argc, char* argv[]) {
|
|||
// 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)
|
||||
// mat(i,j) = rg(rng);
|
||||
// mat(i,j) = uniform(rng);
|
||||
//
|
||||
// tri = ublas::triangular_adaptor<matrix, ublas::upper>(mat);
|
||||
// cout << " Assigned from triangular adapter: " << tri << endl;
|
||||
|
@ -260,13 +260,13 @@ int main(int argc, char* argv[]) {
|
|||
//
|
||||
// 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) = rg(rng);
|
||||
// mat(i,j) = uniform(rng);
|
||||
// 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)
|
||||
// mat(i,j) = rg(rng);
|
||||
// mat(i,j) = uniform(rng);
|
||||
// (ublas::triangular_adaptor<matrix, ublas::upper>(mat)) = tri;
|
||||
// cout << " Assign triangular adaptor from triangular: " << mat << endl;
|
||||
// }
|
||||
|
@ -282,7 +282,7 @@ int main(int argc, char* argv[]) {
|
|||
// 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)
|
||||
// mat(i,j) = rg(rng);
|
||||
// mat(i,j) = uniform(rng);
|
||||
//
|
||||
// tri = ublas::triangular_adaptor<matrix, ublas::upper>(mat);
|
||||
// cout << " Assigned from triangular adapter: " << tri << endl;
|
||||
|
@ -291,13 +291,13 @@ int main(int argc, char* argv[]) {
|
|||
//
|
||||
// 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) = rg(rng);
|
||||
// mat(i,j) = uniform(rng);
|
||||
// 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)
|
||||
// mat(i,j) = rg(rng);
|
||||
// mat(i,j) = uniform(rng);
|
||||
// mat = ublas::triangular_adaptor<matrix, ublas::upper>(mat);
|
||||
// cout << " Assign matrix from triangular adaptor of self: " << mat << endl;
|
||||
// }
|
||||
|
|
Loading…
Reference in New Issue