ampsci
High-precision calculations for one- and two-valence atomic systems
qip Namespace Reference

Detailed Description

General-purpose utility library.

Provides lightweight, header-only utilities used throughout ampsci, including:

Namespaces

namespace  overloads
 Operator overloads for std::vector.
 

Classes

class  Arithmetic
 Helper template that provides +, -, *, / given +=, -=, *=, /=. More...
 
class  Arithmetic2
 Like Arithmetic, but for two different types (T op U). More...
 
class  Array
 N-dimensional array with arithmetic operators. More...
 
class  ArrayView
 Non-owning view onto a 1D contiguous or strided array segment. More...
 
class  Comparison
 Helper template that provides !=, >, <=, >= given == and <. More...
 
class  ConstStrideIterator
 Const version of StrideIterator. More...
 
struct  less_abs
 Function object for comparisons by absolute value. More...
 
class  ProgressBar
 Thread-safe progress bar for OpenMP parallel loops. More...
 
class  StrideIterator
 Iterator with a configurable stride. More...
 
struct  StrongType
 A light-weight easy-to-use single-file header-only template class for strong typing. More...
 

Functions

template<typename T , typename... Args>
product (T first, Args... rest)
 Variadic product - helper function.
 
template<std::size_t N>
void NDrange_impl (std::vector< std::array< std::size_t, N > > &result, std::array< std::size_t, N > &current, const std::array< std::size_t, N > &maxValues, std::size_t index)
 
template<typename... Args>
auto NDrange (std::size_t first, Args... rest)
 Returns all index tuples for an N-dimensional range.
 
template<typename T , typename... Args>
max (T first, Args... rest)
 Returns the maximum of any number of parameters (variadic).
 
template<typename T , typename... Args>
min (T first, Args... rest)
 Returns the minimum of any number of parameters (variadic).
 
template<typename T , typename... Args>
max_abs (T first, Args... rest)
 Returns the value with maximum absolute value of any number of parameters (variadic).
 
template<typename T , typename... Args>
min_abs (T first, Args... rest)
 Returns the value with minimum absolute value of any number of parameters (variadic).
 
template<typename T , typename... Args>
max_difference (T first, Args... rest)
 Returns max - min over any number of arguments (variadic).
 
template<int n, typename T >
constexpr auto pow (T x)
 x^n for compile-time integer n, x any arithmetic type.
 
template<typename T >
constexpr T pow (T x, int n)
 x^n for runtime integer n; T must be floating point.
 
template<typename T >
constexpr double factorial (T x)
 Factorial x! - takes integer, returns double.
 
template<typename T >
constexpr double double_factorial (T x)
 Double factorial x!! - takes integer, returns double.
 
template<typename T >
constexpr int sign (T value)
 Returns the sign of value. Note: sign(0) == 0.
 
template<typename T >
constexpr T clamp_abs (T value, T max_abs)
 Clamps value to [-max_abs, max_abs] - i.e., using abs.
 
template<typename T >
constexpr T chop (T value, T min_abs)
 Sets value to zero if |value| < min_abs, otherwise returns value unchanged.
 
template<typename Function , typename Real >
std::pair< Real, Real > derivative (Function y, Real x, Real delta_target=Real{1.0e-6}, Real dx=Real{0.01}, unsigned it_limit=250)
 Numerical derivative of y(x) at point x; returns {dy/dx, error}.
 
template<typename Function , typename Real >
std::pair< Real, Real > Newtons (Function f, Real x, Real delta_target=Real{1.0e-6}, Real dx=Real{0.01}, unsigned it_limit=250)
 Solves f(x) = 0 using Newton's method; returns {root, error}.
 
template<typename Function , typename Real >
std::pair< Real, Real > Newtons (Function f, Real x, std::pair< Real, Real > bounds, Real delta_target=Real{1.0e-6}, Real dx=Real{0.01}, unsigned it_limit=250)
 Solves f(x) = 0 using Newton's method with bounds; returns {root, error}.
 
std::string omp_details ()
 Returns a short string describing the threading status, e.g. "Using OpenMP with 8 threads." or "Single-threaded.".
 
std::string random_string (std::size_t length)
 Returns a random alphanumeric string of the given length.
 
std::string fstring (const std::string format,...)
 Returns a formatted string using printf-style format specifiers.
 
std::string fstring (const std::size_t size, const std::string format,...)
 Overload of fstring with explicit buffer size (maximum string length).
 
bool wildcard_compare (std::string_view s1, std::string_view s2)
 Compares s1 against pattern s2, where s2 may contain one wildcard '*' that matches any substring.
 
char tolower (char ch)
 Conversion of a single character to lowercase.
 
std::string tolower (std::string t_string)
 Returns a lowercase copy of the string.
 
bool contains (std::string_view the_string, std::string_view sub_string)
 Returns true if the_string contains sub_string.
 
bool ci_contains (const std::string &the_string, const std::string &sub_string)
 Returns true if the_string contains sub_string (case insensitive).
 
bool contains (const std::string &the_string, const std::vector< std::string > &sub_strings)
 Returns true if the_string contains any of the sub_strings.
 
bool ci_contains (const std::string &the_string, const std::vector< std::string > &sub_strings)
 Returns true if the_string contains any of the sub_strings (case insensitive).
 
bool ci_compare (std::string_view s1, std::string_view s2)
 Case-insensitive string comparison; equivalent to tolower(s1) == tolower(s2).
 
bool ci_wc_compare (std::string_view s1, std::string_view s2)
 Case-insensitive version of wildcard_compare.
 
auto Levenstein (std::string_view a, std::string_view b)
 Returns the Levenshtein edit distance between strings a and b.
 
auto ci_Levenstein (std::string_view a, std::string_view b)
 Case-insensitive version of Levenstein.
 
auto closest_match (std::string_view test_string, const std::vector< std::string > &list)
 Returns an iterator to the closest match to test_string in list, using Levenstein distance.
 
std::string ci_closest_match (const std::string_view test_string, const std::vector< std::string > &list)
 Returns the closest match (case insensitive) to test_string in list, using ci_Levenstein distance.
 
bool string_is_integer (std::string_view s)
 Returns true if the string represents an integer.
 
std::vector< std::string > split (const std::string &s, char delim=' ')
 Splits a string by delimiter into a vector of substrings.
 
std::string concat (const std::vector< std::string > &v, const std::string &delim="")
 Concatenates a vector of strings into one, with an optional delimiter.
 
std::string wrap (const std::string &input, std::size_t at=80, const std::string &prefix="")
 Word-wraps input at column at, optionally prefixing each line.
 
std::string int_to_roman (int a)
 Converts an integer to a Roman numeral string. Assumes |a| <= 3999.
 
template<typename T , typename... Args>
std::vector< T > merge (std::vector< T > first, const std::vector< T > &second, const Args &...rest)
 Merges any number of vectors: {a,b,c},{d,e},{f} -> {a,b,c,d,e,f}.
 
template<typename T >
auto compare (const std::vector< T > &first, const std::vector< T > &second)
 Compares two arithmetic vectors element-wise; returns {max_delta, iterator}.
 
template<typename T , typename U , typename Func >
auto compare (const std::vector< T > &first, const std::vector< U > &second, Func &func)
 Compares two vectors using a user-supplied function; returns {max, iterator}.
 
template<typename T >
auto compare_eps (const std::vector< T > &first, const std::vector< T > &second)
 Compares two floating-point vectors element-wise relative to the second; returns {max_eps, iterator}.
 
template<typename T , typename... Args>
void add (std::vector< T > *first, const std::vector< T > &second, const Args &...rest)
 Adds any number of vectors in place (modifies *first).
 
template<typename T , typename... Args>
std::vector< T > add (std::vector< T > first, const std::vector< T > &second, const Args &...rest)
 Adds any number of vectors; returns result sized to the largest input.
 
template<typename T , typename... Args>
void multiply (std::vector< T > *first, const std::vector< T > &second, const Args &...rest)
 Multiplies any number of arithmetic vectors in place (modifies *first).
 
template<typename T , typename... Args>
std::vector< T > multiply (std::vector< T > first, const std::vector< T > &second, const Args &...rest)
 Multiplies any number of vectors; returns result sized to the largest input.
 
template<typename F , typename T , typename... Args>
void compose (const F &func, std::vector< T > *first, const std::vector< T > &second, const Args &...rest)
 Applies func element-wise across any number of vectors in place (modifies *first).
 
template<typename F , typename T , typename... Args>
std::vector< T > compose (const F &func, std::vector< T > first, const std::vector< T > &second, const Args &...rest)
 Applies func element-wise across any number of vectors; returns result sized to the largest input.
 
template<typename T >
void scale (std::vector< T > *vec, T x)
 In-place scalar multiplication of a vector; types must match.
 
template<typename T >
std::vector< T > scale (std::vector< T > vec, T x)
 Scalar multiplication of a vector; types must match.
 
template<typename T = double, typename N = std::size_t>
std::vector< T > uniform_range (T first, T last, N number)
 Returns a uniformly distributed range [first, last] with number points.
 
template<typename T = double, typename N = std::size_t>
std::vector< T > logarithmic_range (T first, T last, N number)
 Returns a logarithmically distributed range [first, last] with number points.
 
template<typename T = double, typename N = std::size_t>
std::vector< T > loglinear_range (T first, T last, T b, N number)
 Returns a log-linear distributed range [first, last] with number points.
 
template<typename T , typename... Args>
constexpr auto multiply_at (std::size_t i, const T &first, const Args &...rest)
 Helper: returns first[i] * rest[i] * ... at index i.
 
template<typename T , typename... Args>
constexpr auto inner_product (const T &first, const Args &...rest)
 Variadic inner product: sum_i v1[i]*v2[i]*...*vn[i].
 
template<typename T , typename... Args>
auto inner_product_sub (std::size_t p0, std::size_t pinf, const T &first, const Args &...rest)
 Inner product over the subrange [p0, pinf).
 
template<typename F , typename T >
apply_to (const F &func, T list)
 Applies func to each element of list in place; returns the modified list.
 
template<typename T , typename Func >
std::vector< T > select_if (const std::vector< T > &in, Func condition)
 Returns a copy of in containing only elements satisfying condition.
 
template<typename T , typename Func >
void insert_into_if (const std::vector< T > &in, std::vector< T > *inout, Func condition)
 Inserts elements from in into *inout if condition is met.
 
template<typename T >
std::vector< T > reverse (std::vector< T > in)
 Returns a reversed copy of the vector.
 
template<typename T >
mean (std::vector< T > vec)
 Mean of a vector.
 
template<typename T >
variance (std::vector< T > vec, std::size_t dof=0)
 Variance using the two-pass method.
 
template<typename T >
sdev (std::vector< T > vec, std::size_t dof=0)
 Standard deviation: sqrt(variance).
 
template<typename T >
sem (std::vector< T > vec, std::size_t dof=0)
 Standard error of the mean: sdev / sqrt(N).
 
void progbar (int i, int max, int length=50)
 Basic progress bar. Prints new line if (and only if) i==(max-1)
 

Variables

constexpr bool use_omp = false
 True if compiled with OpenMP support, false otherwise.
 

Function Documentation

◆ product()

template<typename T , typename... Args>
T qip::product ( first,
Args...  rest 
)

Variadic product - helper function.

◆ NDrange()

template<typename... Args>
auto qip::NDrange ( std::size_t  first,
Args...  rest 
)

Returns all index tuples for an N-dimensional range.

Enables iteration over every index combination, e.g.:

for (auto [i,j,k] : qip::NDrange(3,4,2)) { array.at(i,j,k); }
General-purpose utility library.
Definition Array.hpp:23
auto NDrange(std::size_t first, Args... rest)
Returns all index tuples for an N-dimensional range.
Definition Array.hpp:278
Note
Not memory efficient; do not use for large arrays.

◆ max()

template<typename T , typename... Args>
T qip::max ( first,
Args...  rest 
)

Returns the maximum of any number of parameters (variadic).

◆ min()

template<typename T , typename... Args>
T qip::min ( first,
Args...  rest 
)

Returns the minimum of any number of parameters (variadic).

◆ max_abs()

template<typename T , typename... Args>
T qip::max_abs ( first,
Args...  rest 
)

Returns the value with maximum absolute value of any number of parameters (variadic).

◆ min_abs()

template<typename T , typename... Args>
T qip::min_abs ( first,
Args...  rest 
)

Returns the value with minimum absolute value of any number of parameters (variadic).

◆ max_difference()

template<typename T , typename... Args>
T qip::max_difference ( first,
Args...  rest 
)

Returns max - min over any number of arguments (variadic).

◆ pow() [1/2]

template<int n, typename T >
constexpr auto qip::pow ( x)
constexpr

x^n for compile-time integer n, x any arithmetic type.

Returns double for negative n, T otherwise.

◆ pow() [2/2]

template<typename T >
constexpr T qip::pow ( x,
int  n 
)
constexpr

x^n for runtime integer n; T must be floating point.

◆ factorial()

template<typename T >
constexpr double qip::factorial ( x)
constexpr

Factorial x! - takes integer, returns double.

◆ double_factorial()

template<typename T >
constexpr double qip::double_factorial ( x)
constexpr

Double factorial x!! - takes integer, returns double.

◆ sign()

template<typename T >
constexpr int qip::sign ( value)
constexpr

Returns the sign of value. Note: sign(0) == 0.

◆ clamp_abs()

template<typename T >
constexpr T qip::clamp_abs ( value,
max_abs 
)
constexpr

Clamps value to [-max_abs, max_abs] - i.e., using abs.

◆ chop()

template<typename T >
constexpr T qip::chop ( value,
min_abs 
)
constexpr

Sets value to zero if |value| < min_abs, otherwise returns value unchanged.

◆ derivative()

template<typename Function , typename Real >
std::pair< Real, Real > qip::derivative ( Function  y,
Real  x,
Real  delta_target = Real{1.0e-6},
Real  dx = Real{0.01},
unsigned  it_limit = 250 
)

Numerical derivative of y(x) at point x; returns {dy/dx, error}.

Iteratively halves the step size until |dy/dx_n - dy/dx_{n-1}| < delta_target.

Template Parameters
FunctionCallable as y(x), returning a value convertible to Real.
RealFloating-point type.
Parameters
yFunction to differentiate.
xPoint at which to evaluate the derivative.
delta_targetConvergence target (default 1e-6).
dxInitial step size (default 0.01).
it_limitMaximum number of iterations (default 250).

◆ Newtons() [1/2]

template<typename Function , typename Real >
std::pair< Real, Real > qip::Newtons ( Function  f,
Real  x,
Real  delta_target = Real{1.0e-6},
Real  dx = Real{0.01},
unsigned  it_limit = 250 
)

Solves f(x) = 0 using Newton's method; returns {root, error}.

Template Parameters
FunctionCallable as f(x), returning a value convertible to Real.
RealFloating-point type.
Parameters
fFunction to solve.
xInitial guess.
delta_targetConvergence target for |x_n - x_{n+1}| (default 1e-6).
dxInitial step size for derivative (default 0.01).
it_limitMaximum number of iterations (default 250).

◆ Newtons() [2/2]

template<typename Function , typename Real >
std::pair< Real, Real > qip::Newtons ( Function  f,
Real  x,
std::pair< Real, Real >  bounds,
Real  delta_target = Real{1.0e-6},
Real  dx = Real{0.01},
unsigned  it_limit = 250 
)

Solves f(x) = 0 using Newton's method with bounds; returns {root, error}.

Solution is clamped to [bounds.first, bounds.second].

Parameters
fFunction to solve.
xInitial guess.
boundsAllowed range [lower, upper].
delta_targetConvergence target for |x_n - x_{n+1}| (default 1e-6).
dxInitial step size for derivative (default 0.01).
it_limitMaximum number of iterations (default 250).

◆ omp_details()

std::string qip::omp_details ( )
inline

Returns a short string describing the threading status, e.g. "Using OpenMP with 8 threads." or "Single-threaded.".

◆ random_string()

std::string qip::random_string ( std::size_t  length)
inline

Returns a random alphanumeric string of the given length.

◆ fstring() [1/2]

std::string qip::fstring ( const std::string  format,
  ... 
)
inline

Returns a formatted string using printf-style format specifiers.

Maximum string length is 256 characters. Use the size overload for longer strings.

◆ fstring() [2/2]

std::string qip::fstring ( const std::size_t  size,
const std::string  format,
  ... 
)
inline

Overload of fstring with explicit buffer size (maximum string length).

◆ wildcard_compare()

bool qip::wildcard_compare ( std::string_view  s1,
std::string_view  s2 
)
inline

Compares s1 against pattern s2, where s2 may contain one wildcard '*' that matches any substring.

◆ tolower() [1/2]

char qip::tolower ( char  ch)
inline

Conversion of a single character to lowercase.

◆ tolower() [2/2]

std::string qip::tolower ( std::string  t_string)
inline

Returns a lowercase copy of the string.

◆ contains() [1/2]

bool qip::contains ( std::string_view  the_string,
std::string_view  sub_string 
)
inline

Returns true if the_string contains sub_string.

◆ ci_contains() [1/2]

bool qip::ci_contains ( const std::string &  the_string,
const std::string &  sub_string 
)
inline

Returns true if the_string contains sub_string (case insensitive).

◆ contains() [2/2]

bool qip::contains ( const std::string &  the_string,
const std::vector< std::string > &  sub_strings 
)
inline

Returns true if the_string contains any of the sub_strings.

◆ ci_contains() [2/2]

bool qip::ci_contains ( const std::string &  the_string,
const std::vector< std::string > &  sub_strings 
)
inline

Returns true if the_string contains any of the sub_strings (case insensitive).

◆ ci_compare()

bool qip::ci_compare ( std::string_view  s1,
std::string_view  s2 
)
inline

Case-insensitive string comparison; equivalent to tolower(s1) == tolower(s2).

◆ ci_wc_compare()

bool qip::ci_wc_compare ( std::string_view  s1,
std::string_view  s2 
)
inline

Case-insensitive version of wildcard_compare.

Compares s1 against pattern s2, where s2 may contain one wildcard '*' that matches any substring.

◆ Levenstein()

auto qip::Levenstein ( std::string_view  a,
std::string_view  b 
)
inline

Returns the Levenshtein edit distance between strings a and b.

◆ ci_Levenstein()

auto qip::ci_Levenstein ( std::string_view  a,
std::string_view  b 
)
inline

Case-insensitive version of Levenstein.

◆ closest_match()

auto qip::closest_match ( std::string_view  test_string,
const std::vector< std::string > &  list 
)
inline

Returns an iterator to the closest match to test_string in list, using Levenstein distance.

◆ ci_closest_match()

std::string qip::ci_closest_match ( const std::string_view  test_string,
const std::vector< std::string > &  list 
)
inline

Returns the closest match (case insensitive) to test_string in list, using ci_Levenstein distance.

◆ string_is_integer()

bool qip::string_is_integer ( std::string_view  s)
inline

Returns true if the string represents an integer.

Accepts an optional leading '+' or '-'. e.g., "16" and "-12" return true; "12x" and "12.5" return false.

◆ split()

std::vector< std::string > qip::split ( const std::string &  s,
char  delim = ' ' 
)
inline

Splits a string by delimiter into a vector of substrings.

◆ concat()

std::string qip::concat ( const std::vector< std::string > &  v,
const std::string &  delim = "" 
)
inline

Concatenates a vector of strings into one, with an optional delimiter.

◆ wrap()

std::string qip::wrap ( const std::string &  input,
std::size_t  at = 80,
const std::string &  prefix = "" 
)
inline

Word-wraps input at column at, optionally prefixing each line.

Does not split words unless unavoidable.

◆ int_to_roman()

std::string qip::int_to_roman ( int  a)
inline

Converts an integer to a Roman numeral string. Assumes |a| <= 3999.

◆ merge()

template<typename T , typename... Args>
std::vector< T > qip::merge ( std::vector< T >  first,
const std::vector< T > &  second,
const Args &...  rest 
)

Merges any number of vectors: {a,b,c},{d,e},{f} -> {a,b,c,d,e,f}.

◆ compare() [1/2]

template<typename T >
auto qip::compare ( const std::vector< T > &  first,
const std::vector< T > &  second 
)

Compares two arithmetic vectors element-wise; returns {max_delta, iterator}.

Returns {delta, itr} where delta = max|first - second| (signed as first-second), and itr points to the position in first where the maximum occurred.

If all compare exactly, max_delta should be zero, and iterator points to begining of list.

◆ compare() [2/2]

template<typename T , typename U , typename Func >
auto qip::compare ( const std::vector< T > &  first,
const std::vector< U > &  second,
Func &  func 
)

Compares two vectors using a user-supplied function; returns {max, iterator}.

Returns {delta, itr} where delta = max|func(first[i], second[i])|, and itr points to the position in first where the maximum occurred.

◆ compare_eps()

template<typename T >
auto qip::compare_eps ( const std::vector< T > &  first,
const std::vector< T > &  second 
)

Compares two floating-point vectors element-wise relative to the second; returns {max_eps, iterator}.

Returns {eps, itr} where eps = max|(first-second)/second| (signed), and itr points to the position in first where the maximum occurred.

◆ add() [1/2]

template<typename T , typename... Args>
void qip::add ( std::vector< T > *  first,
const std::vector< T > &  second,
const Args &...  rest 
)

Adds any number of vectors in place (modifies *first).

Resizes *first to the size of the largest vector if needed.

◆ add() [2/2]

template<typename T , typename... Args>
std::vector< T > qip::add ( std::vector< T >  first,
const std::vector< T > &  second,
const Args &...  rest 
)

Adds any number of vectors; returns result sized to the largest input.

◆ multiply() [1/2]

template<typename T , typename... Args>
void qip::multiply ( std::vector< T > *  first,
const std::vector< T > &  second,
const Args &...  rest 
)

Multiplies any number of arithmetic vectors in place (modifies *first).

Resizes *first if needed; elements beyond the shorter vector are set to zero.

◆ multiply() [2/2]

template<typename T , typename... Args>
std::vector< T > qip::multiply ( std::vector< T >  first,
const std::vector< T > &  second,
const Args &...  rest 
)

Multiplies any number of vectors; returns result sized to the largest input.

◆ compose() [1/2]

template<typename F , typename T , typename... Args>
void qip::compose ( const F &  func,
std::vector< T > *  first,
const std::vector< T > &  second,
const Args &...  rest 
)

Applies func element-wise across any number of vectors in place (modifies *first).

e.g., qip::compose(std::plus{}, &vo, v2, v3) is equivalent to qip::add(&vo, v2, v3). Resizes *first if needed.

◆ compose() [2/2]

template<typename F , typename T , typename... Args>
std::vector< T > qip::compose ( const F &  func,
std::vector< T >  first,
const std::vector< T > &  second,
const Args &...  rest 
)

Applies func element-wise across any number of vectors; returns result sized to the largest input.

◆ scale() [1/2]

template<typename T >
void qip::scale ( std::vector< T > *  vec,
x 
)

In-place scalar multiplication of a vector; types must match.

◆ scale() [2/2]

template<typename T >
std::vector< T > qip::scale ( std::vector< T >  vec,
x 
)

Scalar multiplication of a vector; types must match.

◆ uniform_range()

template<typename T = double, typename N = std::size_t>
std::vector< T > qip::uniform_range ( first,
last,
number 
)

Returns a uniformly distributed range [first, last] with number points.

first and last are guaranteed endpoints. number must be at least 2. For integral T the spacing may not be perfectly uniform due to rounding; duplicate values may appear if too many steps are requested.

◆ logarithmic_range()

template<typename T = double, typename N = std::size_t>
std::vector< T > qip::logarithmic_range ( first,
last,
number 
)

Returns a logarithmically distributed range [first, last] with number points.

first and last are guaranteed endpoints. number must be at least 2. For integral T the spacing may not be perfectly logarithmic due to rounding; duplicate values may appear if too many steps are requested.

◆ loglinear_range()

template<typename T = double, typename N = std::size_t>
std::vector< T > qip::loglinear_range ( first,
last,
b,
number 
)

Returns a log-linear distributed range [first, last] with number points.

Roughly logarithmic for values below b and linear above b. number must be at least 3. T must be floating point. Not tested for negative values.

◆ multiply_at()

template<typename T , typename... Args>
constexpr auto qip::multiply_at ( std::size_t  i,
const T &  first,
const Args &...  rest 
)
constexpr

Helper: returns first[i] * rest[i] * ... at index i.

◆ inner_product()

template<typename T , typename... Args>
constexpr auto qip::inner_product ( const T &  first,
const Args &...  rest 
)
constexpr

Variadic inner product: sum_i v1[i]*v2[i]*...*vn[i].

◆ inner_product_sub()

template<typename T , typename... Args>
auto qip::inner_product_sub ( std::size_t  p0,
std::size_t  pinf,
const T &  first,
const Args &...  rest 
)

Inner product over the subrange [p0, pinf).

◆ apply_to()

template<typename F , typename T >
T qip::apply_to ( const F &  func,
list 
)

Applies func to each element of list in place; returns the modified list.

◆ select_if()

template<typename T , typename Func >
std::vector< T > qip::select_if ( const std::vector< T > &  in,
Func  condition 
)

Returns a copy of in containing only elements satisfying condition.

condition must have signature bool condition(T).

◆ insert_into_if()

template<typename T , typename Func >
void qip::insert_into_if ( const std::vector< T > &  in,
std::vector< T > *  inout,
Func  condition 
)

Inserts elements from in into *inout if condition is met.

◆ reverse()

template<typename T >
std::vector< T > qip::reverse ( std::vector< T >  in)

Returns a reversed copy of the vector.

◆ mean()

template<typename T >
T qip::mean ( std::vector< T >  vec)

Mean of a vector.

\[ \bar x = \frac{1}{N}\sum_i x_i \]

◆ variance()

template<typename T >
T qip::variance ( std::vector< T >  vec,
std::size_t  dof = 0 
)

Variance using the two-pass method.

\[ \sigma^2 = \sum_i (x_i - \bar x)^2 / (N - \text{dof}) \]

dof is the degrees of freedom; use dof=1 for sample variance.

◆ sdev()

template<typename T >
T qip::sdev ( std::vector< T >  vec,
std::size_t  dof = 0 
)

Standard deviation: sqrt(variance).

◆ sem()

template<typename T >
T qip::sem ( std::vector< T >  vec,
std::size_t  dof = 0 
)

Standard error of the mean: sdev / sqrt(N).

◆ progbar()

void qip::progbar ( int  i,
int  max,
int  length = 50 
)
inline

Basic progress bar. Prints new line if (and only if) i==(max-1)

  • does not work well in Parellel regions. Use ProgressBar in that case
  • Prints directly to cout - creates a mess if piped to a text file. Use ProgressBar if that will be an issue

Variable Documentation

◆ use_omp

constexpr bool qip::use_omp = false
constexpr

True if compiled with OpenMP support, false otherwise.