Unify some functions in utils.

This commit is contained in:
2018-01-18 14:43:13 +01:00
parent 51315f1c59
commit 8bef347d05
5 changed files with 46 additions and 6 deletions

View File

@@ -5,6 +5,7 @@
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <string>
#include <utility>
#include <vector>
@@ -127,4 +128,31 @@ namespace fmri
return val / 180 * M_PI;
}
/**
* Compute the ideal number of columns for dividing up a range into a rectangle.
*
* @tparam T
* @param elems number of elements to space out
* @return the ideal number of columns
*/
template<class T>
inline T numCols(const T elems) {
auto cols = static_cast<T>(ceil(sqrt(elems)));
while (elems % cols) {
++cols;// TODO: this should probably be done analytically
}
return cols;
}
/**
* Get a globally initialized random number generator.
*
* This RNG should always be used as a reference, to make sure the state actually updates.
*
* @return A reference to the global RNG.
*/
std::default_random_engine& rng();
}