MolSim
Loading...
Searching...
No Matches
Namespaces | Classes | Functions
ArrayUtils Namespace Reference

Collection of utility functions and operators for iterable data containers like std::array, std::vector, etc. More...

Namespaces

namespace  is_container_impl
 Collection of structs that define what we consider a container. Remove / add whatever you need.
 

Classes

struct  is_container
 Type trait to check if a given type is a container. More...
 

Functions

template<class Container >
std::string to_string (const Container &container, const std::string &delimiter=", ", const std::array< std::string, 2 > &surround={"[", "]"})
 Generates a string representation of a container which fulfills the Container requirement (provide cbegin and cend).
 
template<class Container , class F >
Container elementWisePairOp (const Container &lhs, const Container &rhs, F binaryFunction)
 Applies an element wise binary function F to two containers.
 
template<class Scalar , class Container , class F >
Container elementWiseScalarOp (const Scalar &lhs, const Container &rhs, F binaryFunction)
 Applies a binary function F to with a scalar to every element in a container.
 
template<class Container >
auto L2NormSquared (const Container &c)
 Calculates the square of the L2 norm for a given container.
 
template<class Container >
auto L2Norm (const Container &c)
 Calculates the L2 norm for a given container.
 

Detailed Description

Collection of utility functions and operators for iterable data containers like std::array, std::vector, etc.

Function Documentation

◆ elementWisePairOp()

template<class Container , class F >
Container ArrayUtils::elementWisePairOp ( const Container &  lhs,
const Container &  rhs,
binaryFunction 
)
inline

Applies an element wise binary function F to two containers.

If the containers differ in size the F is only applied to as many elements as are in the smaller container.

Template Parameters
ContainerType for both containers.
FType of binary function.
Parameters
lhs
rhs
binaryFunction
Returns
Element wise F(lhs, rhs).

◆ elementWiseScalarOp()

template<class Scalar , class Container , class F >
Container ArrayUtils::elementWiseScalarOp ( const Scalar &  lhs,
const Container &  rhs,
binaryFunction 
)
inline

Applies a binary function F to with a scalar to every element in a container.

Template Parameters
ScalarType of scalar value.
ContainerType of the container.
F
Parameters
lhs
rhs
binaryFunction
Returns
Element wise F(lhs, rhs).

◆ L2Norm()

template<class Container >
auto ArrayUtils::L2Norm ( const Container &  c)

Calculates the L2 norm for a given container.

Template Parameters
Container
Parameters
c
Returns
sqrt(sum_i(c[i]*c[i])).

◆ L2NormSquared()

template<class Container >
auto ArrayUtils::L2NormSquared ( const Container &  c)

Calculates the square of the L2 norm for a given container.

Template Parameters
Container
Parameters
c
Returns
sum_i(c[i]*c[i]).

◆ to_string()

template<class Container >
std::string ArrayUtils::to_string ( const Container &  container,
const std::string &  delimiter = ", ",
const std::array< std::string, 2 > &  surround = {"[", "]"} 
)

Generates a string representation of a container which fulfills the Container requirement (provide cbegin and cend).

Template Parameters
ContainerType of Container.
Parameters
containerThe container to create the string representation from.
delimiterString that is put between items.
surroundStrings to be put before and after the listing (e.g. brackets).
Returns
String representation of container.