TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Extensions to the standard library

Detailed Description

Some convenient extensions to the standard library.

The following extensions are provided:

Classes

class  nda::runtime_error
 Runtime error class used throughout the nda library. More...
 

Functions

template<typename T , auto R, typename U >
constexpr std::array< T, R+1 > nda::stdutil::append (std::array< T, R > const &a, U const &x)
 Make a new std::array by appending one element at the end to an existing std::array.
 
template<typename T , typename U , size_t R>
constexpr auto nda::stdutil::dot_product (std::array< T, R > const &a1, std::array< U, R > const &a2)
 Calculate the dot product of two std::array objects.
 
template<typename T , typename U , size_t R>
constexpr std::array< T, R+1 > nda::stdutil::front_append (std::array< T, R > const &a, U const &x)
 Make a new std::array by prepending one element at the front to an existing std::array.
 
template<int N, typename T , size_t R>
constexpr std::array< T, R - N > nda::stdutil::front_mpop (std::array< T, R > const &a)
 Make a new std::array by popping the first N elements of an existing std::array.
 
template<typename T , size_t R>
constexpr std::array< T, R - 1 > nda::stdutil::front_pop (std::array< T, R > const &a)
 Make a new std::array by popping the first element of an existing std::array.
 
template<typename T , size_t R1, size_t R2>
constexpr std::array< T, R1+R2 > nda::stdutil::join (std::array< T, R1 > const &a1, std::array< T, R2 > const &a2)
 Make a new std::array by joining two existing std::array objects.
 
template<size_t R, typename T >
constexpr std::array< T, R > nda::stdutil::make_initialized_array (T v)
 Create a new std::array object initialized with a specific value.
 
template<typename T , typename U , size_t R>
constexpr std::array< T, R > nda::stdutil::make_std_array (std::array< U, R > const &a)
 Convert a std::array with value type U to a std::array with value type T.
 
template<int N, typename T , size_t R>
constexpr std::array< T, R - N > nda::stdutil::mpop (std::array< T, R > const &a)
 Make a new std::array by popping the last N elements of an existing std::array.
 
template<typename T , typename U , size_t R>
constexpr auto std::operator* (std::array< T, R > const &lhs, std::array< U, R > const &rhs)
 Multiply two std::array objects element-wise.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U> and !std::is_same_v<T, U>)
auto std::operator* (std::complex< T > const &x, std::complex< U > const &y)
 Implementation of operator * for two std::complex types with different value types.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U>)
auto std::operator* (std::complex< T > const &x, U y)
 Implementation of operator * for std::complex and some other arithmetic type.
 
template<typename T , size_t R>
constexpr std::array< T, R > std::operator* (T s, std::array< T, R > const &a)
 Multiply a scalar and a std::array element-wise.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U>)
auto std::operator* (T x, std::complex< U > const &y)
 Implementation of operator * for some other arithmetic type and std::complex.
 
template<typename T , size_t R>
constexpr std::array< T, R > std::operator+ (std::array< T, R > const &lhs, std::array< T, R > const &rhs)
 Add two std::array objects element-wise.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U> and !std::is_same_v<T, U>)
auto std::operator+ (std::complex< T > const &x, std::complex< U > const &y)
 Implementation of operator + for two std::complex types with different value types.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U>)
auto std::operator+ (std::complex< T > const &x, U y)
 Implementation of operator + for std::complex and some other arithmetic type.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U>)
auto std::operator+ (T x, std::complex< U > const &y)
 Implementation of operator + for some other arithmetic type and std::complex.
 
template<typename T , size_t R>
constexpr std::array< T, R > std::operator- (std::array< T, R > const &a)
 Negate a std::array element-wise (unary minus).
 
template<typename T , size_t R>
constexpr std::array< T, R > std::operator- (std::array< T, R > const &lhs, std::array< T, R > const &rhs)
 Subtract two std::array objects element-wise.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U> and !std::is_same_v<T, U>)
auto std::operator- (std::complex< T > const &x, std::complex< U > const &y)
 Implementation of operator - for two std::complex types with different value types.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U>)
auto std::operator- (std::complex< T > const &x, U y)
 Implementation of operator - for std::complex and some other arithmetic type.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U>)
auto std::operator- (T x, std::complex< U > const &y)
 Implementation of operator - for some other arithmetic type and std::complex.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U> and !std::is_same_v<T, U>)
auto std::operator/ (std::complex< T > const &x, std::complex< U > const &y)
 Implementation of operator / for two std::complex types with different value types.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U>)
auto std::operator/ (std::complex< T > const &x, U y)
 Implementation of operator / for std::complex and some other arithmetic type.
 
template<typename T , typename U >
requires (std::is_arithmetic_v<T> and std::is_arithmetic_v<U> and std::common_with<T, U>)
auto std::operator/ (T x, std::complex< U > const &y)
 Implementation of operator / for some other arithmetic type and std::complex.
 
template<typename T , size_t R>
std::ostream & std::operator<< (std::ostream &out, std::array< T, R > const &a)
 Write a std::array to an output stream.
 
template<typename T , size_t R>
constexpr std::array< T, R - 1 > nda::stdutil::pop (std::array< T, R > const &a)
 Make a new std::array by popping the last element of an existing std::array.
 
template<typename T , size_t R>
constexpr auto nda::stdutil::product (std::array< T, R > const &a)
 Calculate the product of all elements in a std::array.
 
template<typename T , size_t R>
constexpr auto nda::stdutil::sum (std::array< T, R > const &a)
 Calculate the sum of all elements in a std::array.
 
template<typename T , size_t R>
std::string std::to_string (std::array< T, R > const &a)
 Get a string representation of a std::array.
 
template<typename T , size_t R>
constexpr std::vector< T > nda::stdutil::to_vector (std::array< T, R > const &a)
 Convert a std::array to a std::vector.
 

Function Documentation

◆ append()

template<typename T , auto R, typename U >
std::array< T, R+1 > nda::stdutil::append ( std::array< T, R > const & a,
U const & x )
constexpr

#include <nda/stdutil/array.hpp>

Make a new std::array by appending one element at the end to an existing std::array.

Template Parameters
TValue type of the input array.
RSize of the input array.
UType of the element to append (must be convertible to T).
Parameters
aInput std::array.
xElement to append.
Returns
A copy of the input array with the additional element appended at the end.

Definition at line 217 of file array.hpp.

◆ dot_product()

template<typename T , typename U , size_t R>
auto nda::stdutil::dot_product ( std::array< T, R > const & a1,
std::array< U, R > const & a2 )
constexpr

#include <nda/stdutil/array.hpp>

Calculate the dot product of two std::array objects.

Warning
This function simply calculates the sum of the element-wise products of the two arrays. For arrays with complex numbers, this might not be what you expect from a dot product.
Template Parameters
TValue type of input array #1.
UValue type of input array #2.
RSize of the input arrays.
Parameters
a1Input array #1.
a2Input array #2.
Returns
Sum of the element-wise products of the two arrays.

Definition at line 369 of file array.hpp.

◆ front_append()

template<typename T , typename U , size_t R>
std::array< T, R+1 > nda::stdutil::front_append ( std::array< T, R > const & a,
U const & x )
constexpr

#include <nda/stdutil/array.hpp>

Make a new std::array by prepending one element at the front to an existing std::array.

Template Parameters
TValue type of the input array.
UType of the element to prepend (must be convertible to T).
RSize of the input array.
Parameters
aInput std::array.
xElement to prepend.
Returns
A copy of the input array with the additional element prepended at the front.

Definition at line 235 of file array.hpp.

◆ front_mpop()

template<int N, typename T , size_t R>
std::array< T, R - N > nda::stdutil::front_mpop ( std::array< T, R > const & a)
constexpr

#include <nda/stdutil/array.hpp>

Make a new std::array by popping the first N elements of an existing std::array.

Template Parameters
NNumber of elements to pop.
TValue type of the input array.
RSize of the input array.
Parameters
aInput array.
Returns
A copy of the input array with the first N elements removed.

Definition at line 281 of file array.hpp.

◆ front_pop()

template<typename T , size_t R>
std::array< T, R - 1 > nda::stdutil::front_pop ( std::array< T, R > const & a)
constexpr

#include <nda/stdutil/array.hpp>

Make a new std::array by popping the first element of an existing std::array.

Template Parameters
TValue type of the input array.
RSize of the input array.
Parameters
aInput std::array.
Returns
A copy of the input array with the first element removed.

Definition at line 296 of file array.hpp.

◆ join()

template<typename T , size_t R1, size_t R2>
std::array< T, R1+R2 > nda::stdutil::join ( std::array< T, R1 > const & a1,
std::array< T, R2 > const & a2 )
constexpr

#include <nda/stdutil/array.hpp>

Make a new std::array by joining two existing std::array objects.

Template Parameters
TValue type of the arrays.
R1Size of the input array #1.
R2Size of the input array #2.
Parameters
a1Input std::array #1.
a2Input std::array #2.
Returns
Array of size R1 + R2 containing the elements of the first array followed by the elements of the second array.

Definition at line 312 of file array.hpp.

◆ make_initialized_array()

template<size_t R, typename T >
std::array< T, R > nda::stdutil::make_initialized_array ( T v)
constexpr

#include <nda/stdutil/array.hpp>

Create a new std::array object initialized with a specific value.

Template Parameters
RSize of the array.
TValue type of the array.
Parameters
vValue to initialize the std::array with.
Returns
std::array initialized with the constant value.

Definition at line 168 of file array.hpp.

◆ make_std_array()

template<typename T , typename U , size_t R>
std::array< T, R > nda::stdutil::make_std_array ( std::array< U, R > const & a)
constexpr

#include <nda/stdutil/array.hpp>

Convert a std::array with value type U to a std::array with value type T.

Template Parameters
TValue type of the target array.
UValue type of the input array.
RSize of the input array.
Parameters
aInput std::array.
Returns
std::array with the same values as the input array and value type T.

Definition at line 184 of file array.hpp.

◆ mpop()

template<int N, typename T , size_t R>
std::array< T, R - N > nda::stdutil::mpop ( std::array< T, R > const & a)
constexpr

#include <nda/stdutil/array.hpp>

Make a new std::array by popping the last N elements of an existing std::array.

Template Parameters
NNumber of elements to pop.
TValue type of the input array.
RSize of the input array.
Parameters
aInput std::array.
Returns
A copy of the input array with the last N elements removed.

Definition at line 252 of file array.hpp.

◆ operator*() [1/2]

template<typename T , typename U , size_t R>
auto std::operator* ( std::array< T, R > const & lhs,
std::array< U, R > const & rhs )
constexpr

#include <nda/stdutil/array.hpp>

Multiply two std::array objects element-wise.

Template Parameters
TValue type of the first array.
UValue type of the second array.
RSize of the arrays.
Parameters
lhsLeft hand side std::array operand.
rhsRight hand side std::array operand.
Returns
std::array containing the element-wise product.

Definition at line 116 of file array.hpp.

◆ operator*() [2/2]

template<typename T , size_t R>
std::array< T, R > std::operator* ( T s,
std::array< T, R > const & a )
constexpr

#include <nda/stdutil/array.hpp>

Multiply a scalar and a std::array element-wise.

Template Parameters
TValue type of the array/scalar.
RSize of the array.
Parameters
sScalar value.
astd::array operand.
Returns
std::array containing the product of each element with the scalar.

Definition at line 149 of file array.hpp.

◆ operator+()

template<typename T , size_t R>
std::array< T, R > std::operator+ ( std::array< T, R > const & lhs,
std::array< T, R > const & rhs )
constexpr

#include <nda/stdutil/array.hpp>

Add two std::array objects element-wise.

Template Parameters
TValue type of the arrays.
RSize of the arrays.
Parameters
lhsLeft hand side std::array operand.
rhsRight hand side std::array operand.
Returns
std::array containing the element-wise sum.

Definition at line 83 of file array.hpp.

◆ operator-() [1/2]

template<typename T , size_t R>
std::array< T, R > std::operator- ( std::array< T, R > const & a)
constexpr

#include <nda/stdutil/array.hpp>

Negate a std::array element-wise (unary minus).

Template Parameters
TValue type of the array.
RSize of the array.
Parameters
astd::array operand.
Returns
std::array containing the element-wise negation.

Definition at line 133 of file array.hpp.

◆ operator-() [2/2]

template<typename T , size_t R>
std::array< T, R > std::operator- ( std::array< T, R > const & lhs,
std::array< T, R > const & rhs )
constexpr

#include <nda/stdutil/array.hpp>

Subtract two std::array objects element-wise.

Template Parameters
TValue type of the arrays.
RSize of the arrays.
Parameters
lhsLeft hand side std::array operand.
rhsRight hand side std::array operand.
Returns
std::array containing the element-wise difference.

Definition at line 99 of file array.hpp.

◆ operator<<()

template<typename T , size_t R>
std::ostream & std::operator<< ( std::ostream & out,
std::array< T, R > const & a )

#include <nda/stdutil/array.hpp>

Write a std::array to an output stream.

Template Parameters
TValue type of the array.
RSize of the array.
Parameters
outstd::ostream to stream into.
astd::array to be written.
Returns
Reference to the std::ostream.

Definition at line 52 of file array.hpp.

◆ pop()

template<typename T , size_t R>
std::array< T, R - 1 > nda::stdutil::pop ( std::array< T, R > const & a)
constexpr

#include <nda/stdutil/array.hpp>

Make a new std::array by popping the last element of an existing std::array.

Template Parameters
TValue type of the input array.
RSize of the input array.
Parameters
aInput std::array.
Returns
A copy of the input array with the last element removed.

Definition at line 267 of file array.hpp.

◆ product()

template<typename T , size_t R>
auto nda::stdutil::product ( std::array< T, R > const & a)
constexpr

#include <nda/stdutil/array.hpp>

Calculate the product of all elements in a std::array.

Template Parameters
TValue type of the array.
RSize of the array.
Parameters
aInput std::array.
Returns
Product of all elements in the input array.

Definition at line 348 of file array.hpp.

◆ sum()

template<typename T , size_t R>
auto nda::stdutil::sum ( std::array< T, R > const & a)
constexpr

#include <nda/stdutil/array.hpp>

Calculate the sum of all elements in a std::array.

Template Parameters
TValue type of the array.
RSize of the array.
Parameters
aInput std::array.
Returns
Sum of all the elements of the input array. If its size is zero, return a default constructed object of type T.

Definition at line 329 of file array.hpp.

◆ to_string()

template<typename T , size_t R>
std::string std::to_string ( std::array< T, R > const & a)

#include <nda/stdutil/array.hpp>

Get a string representation of a std::array.

Template Parameters
TValue type of the array.
RSize of the array.
Parameters
aInput std::array.
Returns
std::string representation of the array.

Definition at line 65 of file array.hpp.

◆ to_vector()

template<typename T , size_t R>
std::vector< T > nda::stdutil::to_vector ( std::array< T, R > const & a)
constexpr

#include <nda/stdutil/array.hpp>

Convert a std::array to a std::vector.

Template Parameters
TValue type of the input array.
RSize of the input array.
Parameters
aInput std::array.
Returns
std::vector of the same size and with the same values as the input array.

Definition at line 200 of file array.hpp.