Molecular Dynamics Simulation  1.0
Classes | Namespaces | Functions
ArrayUtils.h File Reference
#include <omp.h>
#include <algorithm>
#include <array>
#include <cmath>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
Include dependency graph for ArrayUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ArrayUtils::is_container_impl::is_container< T >
 
struct  ArrayUtils::is_container_impl::is_container< std::array< T, N > >
 
struct  ArrayUtils::is_container_impl::is_container< std::vector< Args... > >
 
struct  ArrayUtils::is_container_impl::is_container< std::list< Args... > >
 
struct  ArrayUtils::is_container_impl::is_container< std::set< Args... > >
 
struct  ArrayUtils::is_container_impl::is_container< std::unordered_set< Args... > >
 
struct  ArrayUtils::is_container< T >
 

Namespaces

 ArrayUtils
 Collection of utility functions and operators for iterable data containers.
 
 ArrayUtils::is_container_impl
 Type trait to check if a given type is a container.
 

Functions

template<class Container >
std::string ArrayUtils::to_string (const Container &container, const std::string &delimiter=", ", const std::array< std::string, 2 > &surround={"[", "]"})
 
template<class Container , class F >
Container ArrayUtils::elementWisePairOp (const Container &lhs, const Container &rhs, F binaryFunction)
 
template<class Scalar , class Container , class F >
Container ArrayUtils::elementWiseScalarOp (const Scalar &lhs, const Container &rhs, F binaryFunction)
 
template<class Container >
auto ArrayUtils::L2Norm (const Container &c)
 
template<>
auto ArrayUtils::L2Norm< std::array< double, 3 > > (const std::array< double, 3 > &c)
 
template<class Container >
auto ArrayUtils::L2NormSquared (const Container &c)
 
template<>
auto ArrayUtils::L2NormSquared< std::array< double, 3 > > (const std::array< double, 3 > &c)
 
template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, std::ostream & > operator<< (std::ostream &os, const Container &container)
 
template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator+ (const Container &lhs, const Container &rhs)
 
template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator- (const Container &lhs, const Container &rhs)
 
template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator* (const Container &lhs, const Container &rhs)
 
template<class Scalar , class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator* (const Scalar &lhs, const Container &rhs)
 
template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, bool > operator== (const Container &lhs, const Container &rhs)
 

Detailed Description

Author
F. Gratl
Date
12/13/19

Definition in file ArrayUtils.h.

Function Documentation

◆ operator*() [1/2]

template<class Container >
std::enable_if_t<ArrayUtils::is_container<Container>::value, Container> operator* ( const Container &  lhs,
const Container &  rhs 
)

Element wise multiplication of two containers.

Template Parameters
Container
Parameters
lhs
rhs
Returns
For all i lhs[i] * rhs[i].

Definition at line 257 of file ArrayUtils.h.

257  {
258  return ArrayUtils::elementWisePairOp(lhs, rhs, std::multiplies<>());
259 }
Container elementWisePairOp(const Container &lhs, const Container &rhs, F binaryFunction)
Definition: ArrayUtils.h:127

◆ operator*() [2/2]

template<class Scalar , class Container >
std::enable_if_t<ArrayUtils::is_container<Container>::value, Container> operator* ( const Scalar &  lhs,
const Container &  rhs 
)

Element wise scaling of a container.

Template Parameters
Container
Parameters
lhs
rhs
Returns
For all i lhs * rhs[i].

Definition at line 269 of file ArrayUtils.h.

269  {
270  return ArrayUtils::elementWiseScalarOp(lhs, rhs, std::multiplies<>());
271 }
Container elementWiseScalarOp(const Scalar &lhs, const Container &rhs, F binaryFunction)
Definition: ArrayUtils.h:154

◆ operator+()

template<class Container >
std::enable_if_t<ArrayUtils::is_container<Container>::value, Container> operator+ ( const Container &  lhs,
const Container &  rhs 
)

Element wise addition of two containers.

Template Parameters
Container
Parameters
lhs
rhs
Returns
For all i lhs[i] + rhs[i].

Definition at line 233 of file ArrayUtils.h.

233  {
234  return ArrayUtils::elementWisePairOp(lhs, rhs, std::plus<>());
235 }

◆ operator-()

template<class Container >
std::enable_if_t<ArrayUtils::is_container<Container>::value, Container> operator- ( const Container &  lhs,
const Container &  rhs 
)

Element wise subtraction of two containers.

Template Parameters
Container
Parameters
lhs
rhs
Returns
For all i lhs[i] - rhs[i].

Definition at line 245 of file ArrayUtils.h.

245  {
246  return ArrayUtils::elementWisePairOp(lhs, rhs, std::minus<>());
247 }

◆ operator<<()

template<class Container >
std::enable_if_t<ArrayUtils::is_container<Container>::value, std::ostream&> operator<< ( std::ostream &  os,
const Container &  container 
)

Stream operator for containers.

This function actually checks if the given Template parameter satisfies is_container.

Template Parameters
Container
Parameters
os
container
Returns

Definition at line 1 of file ArrayUtils.h.

220  {
221  os << ArrayUtils::to_string(container);
222  return os;
223 }
std::string to_string(const Container &container, const std::string &delimiter=", ", const std::array< std::string, 2 > &surround={"[", "]"})
Definition: ArrayUtils.h:97

◆ operator==()

template<class Container >
std::enable_if_t<ArrayUtils::is_container<Container>::value, bool> operator== ( const Container &  lhs,
const Container &  rhs 
)

Element wise comparison of two containers.

Template Parameters
Container
Parameters
lhs
rhs
Returns
True iff the containers are of the same size, all elements are equal, and in the same order.

Definition at line 282 of file ArrayUtils.h.

282  {
283  if (lhs.size() != rhs.size()) {
284  return false;
285  }
286 
287  auto lhsIter = std::cbegin(lhs);
288  const auto lhsEnd = std::cend(lhs);
289  auto rhsIter = std::cbegin(rhs);
290 
291  for (; lhsIter != lhsEnd; ++lhsIter, ++rhsIter) {
292  if (*lhsIter != *rhs) {
293  return false;
294  }
295  }
296  return true;
297 }