22using namespace std::chrono;
41 std::vector<size_t>
idx(
data.size());
42 std::iota(
idx.begin(),
idx.end(), 0);
44 std::stable_sort(
idx.begin(),
idx.end(),
45 [&
data](
size_t i1,
size_t i2) {return data[i1] > data[i2];});
59 std::vector<size_t>
idx(
data.size());
60 std::iota(
idx.begin(),
idx.end(), 0);
62 std::stable_sort(
idx.begin(),
idx.end(),
63 [&
data](
size_t i1,
size_t i2) {return data[i1] < data[i2];});
120 if (
data.size() == 0) {
121 std::cerr <<
"Error: maxIndex() is called with data of size " <<
data.size()
127 std::cerr <<
"Error: maxIndex() data_end = " <<
data_end
128 <<
" is not valid for the data of size " <<
data.size()
134 std::cerr <<
"Error: maxIndex() data_start = " <<
data_start
135 <<
" is not valid for the data of size " <<
data.size()
142 std::iota(
idx.begin(),
idx.end() , 0);
144 std::stable_sort(
idx.begin(),
idx.end(),
146 {return data[i1 + data_start] > data[i2 + data_start];});
158 for (
size_t i = 0; i <
data.size(); i++)
171 for (
size_t i = 0; i <
data.size(); i++)
184 for (
size_t i = 0; i <
data.size(); i++)
197 for (
size_t i = 0; i <
data.size(); i++)
210 for (
size_t i = 0; i <
data.size(); i++)
224 for (
size_t i = 0; i <
data.size(); i++)
239 return std::reduce(
data.begin(),
data.end());
249inline bool isFree(
const int &i,
const unsigned int &
dof) {
250 return !(i >>
dof & 1UL);
255 return !(i >>
dof & 1UL);
266 for (
const auto &j :
list)
290 for (
const auto &j :
list)
294 list.emplace_back(i);
305 std::chrono::steady_clock::time_point
end, std::string
unit =
"microseconds") {
306 if (
unit ==
"microseconds")
307 return std::chrono::duration_cast<std::chrono::microseconds>(
end -
begin).count();
308 else if (
unit ==
"milliseconds")
309 return std::chrono::duration_cast<std::chrono::milliseconds>(
end -
begin).count();
310 else if (
unit ==
"seconds")
311 return std::chrono::duration_cast<std::chrono::seconds>(
end -
begin).count();
313 std::cerr <<
"Unit = " <<
unit <<
" not valid.\n";
324template <
typename T_out>
329 std::cerr <<
"Error: key = " << key <<
" does not exist in data map.\n";
343template <
typename T_out>
348 std::cerr <<
"Error: key = " << key <<
" does not exist in data map.\n";
365template <
typename T_out>
370 std::cerr <<
"Error: key = " << key <<
" does not exist in data map.\n";
386inline T l2Dist(
const std::vector<T> &
x1,
const std::vector<T> &
x2) {
388 if (
x1.size() !=
x2.size())
389 throw std::invalid_argument(
"size of two vectors not matching");
392 for (
size_t i=0; i<
x1.size(); i++)
395 return std::sqrt(
sum);
std::pair< double, size_t > maxLengthAndMaxLengthIndex(const std::vector< util::Point > &data)
Returns the maximum length of point and index from list of points.
void appendKeyData(std::string key, T_out data, std::map< std::string, T_out > &data_map, bool issue_err=false)
Append value to data associated with key.
T_out getKeyData(std::string key, std::map< std::string, T_out > &data_map, bool issue_err=false)
Get data for a key.
size_t maxLengthIndex(const std::vector< util::Point > &data)
Returns the index that has maximum length of point from list of points.
std::pair< size_t, T > minAndMinIndex(const std::vector< T > &data)
Returns the minimum and index of minimum from list of data.
T l2Dist(const std::vector< T > &x1, const std::vector< T > &x2)
Computes l2 distance between two vectors.
double minLength(const std::vector< util::Point > &data)
Returns the minimum length of point from list of points.
T max(const std::vector< T > &data)
Returns the maximum from list of data.
size_t minIndex(const std::vector< T > &data)
Returns the index corresponding to minimum from list of data.
T min(const std::vector< T > &data)
Returns the minimim from list of data.
bool isInList(const T &i, const std::vector< T > &list)
Find if data is in the list.
size_t minLengthIndex(const std::vector< util::Point > &data)
Returns the index that has minimum length of point from list of points.
T add(const std::vector< T > &data)
Returns the sum of data.
float timeDiff(std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, std::string unit="microseconds")
Returns difference between two times.
bool isTagInList(const std::string &tag, const std::vector< std::string > &tags)
Returns true if tag is found in the list of tags.
std::pair< size_t, T > maxAndMaxIndex(const std::vector< T > &data)
Returns the maximum and index of maximum from list of data.
bool isFree(const int &i, const unsigned int &dof)
Returns true if degree of freedom is free.
void addToList(const T &i, std::vector< T > &list)
Add element to the list.
std::pair< double, size_t > minLengthAndMinLengthIndex(const std::vector< util::Point > &data)
Returns the minimum length of point and index from list of points.
void setKeyData(std::string key, T_out data, std::map< std::string, T_out > &data_map, bool issue_err=false)
Set value to data associated with key.
size_t maxIndex(const std::vector< T > &data)
Returns the index corresponding to maximum from list of data.
double maxLength(const std::vector< util::Point > &data)
Returns the maximum length of point from list of points.
Collection of methods useful in simulation.