24using namespace std::chrono;
43 std::vector<size_t>
idx(
data.size());
44 std::iota(
idx.begin(),
idx.end(), 0);
46 std::stable_sort(
idx.begin(),
idx.end(),
47 [&
data](
size_t i1,
size_t i2) {return data[i1] > data[i2];});
61 std::vector<size_t>
idx(
data.size());
62 std::iota(
idx.begin(),
idx.end(), 0);
64 std::stable_sort(
idx.begin(),
idx.end(),
65 [&
data](
size_t i1,
size_t i2) {return data[i1] < data[i2];});
122 if (
data.size() == 0) {
123 throw std::runtime_error(
125 <<
"Error: maxIndex() is called with data of size " <<
data.size()
130 throw std::runtime_error(
132 <<
"Error: maxIndex() data_end = " <<
data_end
133 <<
" is not valid for the data of size " <<
data.size()
138 throw std::runtime_error(
140 <<
"Error: maxIndex() data_start = " <<
data_start
141 <<
" is not valid for the data of size " <<
data.size()
147 std::iota(
idx.begin(),
idx.end() , 0);
149 std::stable_sort(
idx.begin(),
idx.end(),
151 {return data[i1 + data_start] > data[i2 + data_start];});
163 for (
size_t i = 0; i <
data.size(); i++)
176 for (
size_t i = 0; i <
data.size(); i++)
189 for (
size_t i = 0; i <
data.size(); i++)
202 for (
size_t i = 0; i <
data.size(); i++)
215 for (
size_t i = 0; i <
data.size(); i++)
229 for (
size_t i = 0; i <
data.size(); i++)
244 return std::reduce(
data.begin(),
data.end());
254inline bool isFree(
const int &i,
const unsigned int &
dof) {
255 return !(i >>
dof & 1UL);
260 return !(i >>
dof & 1UL);
271 for (
const auto &j :
list)
295 for (
const auto &j :
list)
299 list.emplace_back(i);
310 std::chrono::steady_clock::time_point
end, std::string
unit =
"microseconds") {
311 if (
unit ==
"microseconds")
312 return std::chrono::duration_cast<std::chrono::microseconds>(
end -
begin).count();
313 else if (
unit ==
"milliseconds")
314 return std::chrono::duration_cast<std::chrono::milliseconds>(
end -
begin).count();
315 else if (
unit ==
"seconds")
316 return std::chrono::duration_cast<std::chrono::seconds>(
end -
begin).count();
318 throw std::runtime_error(
320 <<
"Unit = " <<
unit <<
" not valid.\n");
330template <
typename T_out>
335 throw std::runtime_error(
337 <<
"Error: key = " << key <<
" does not exist in data map.\n");
350template <
typename T_out>
355 throw std::runtime_error(
357 <<
"Error: key = " << key <<
" does not exist in data map.\n");
373template <
typename T_out>
378 throw std::runtime_error(
380 <<
"Error: key = " << key <<
" does not exist in data map.\n");
395inline T l2Dist(
const std::vector<T> &
x1,
const std::vector<T> &
x2) {
397 if (
x1.size() !=
x2.size())
398 throw std::invalid_argument(
"size of two vectors not matching");
401 for (
size_t i=0; i<
x1.size(); i++)
404 return std::sqrt(
sum);
Collects a message with stream syntax for use in an exception.
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.