Celeritas 0.7.0-dev.245+develop.a7be925e
Loading...
Searching...
No Matches
Macros | Functions
ArrayOperators.hh File Reference

Mathematical operators for the Array type. More...

#include <type_traits>
#include "corecel/cont/Array.hh"

Macros

#define CELER_DEFINE_ARRAY_ASSIGN(TOKEN)
 
#define CELER_DEFINE_ARRAY_ARITHM(TOKEN)
 

Functions

template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > celeritas::operator* (T2 const &y, Array< T, N > const &x)
 Left-multiply by scalar.
 
template<class T , size_type N>
Array< T, N > celeritas::operator- (Array< T, N > const &x)
 Unary negation.
 
template<class T , size_type N>
Array< T, N > & celeritas::operator+= (Array< T, N > &x, Array< T, N > const &y)
 
template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > & celeritas::operator+= (Array< T, N > &x, T2 const &y)
 
template<class T , size_type N>
Array< T, N > & celeritas::operator-= (Array< T, N > &x, Array< T, N > const &y)
 
template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > & celeritas::operator-= (Array< T, N > &x, T2 const &y)
 
template<class T , size_type N>
Array< T, N > & celeritas::operator*= (Array< T, N > &x, Array< T, N > const &y)
 
template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > & celeritas::operator*= (Array< T, N > &x, T2 const &y)
 
template<class T , size_type N>
Array< T, N > & celeritas::operator/= (Array< T, N > &x, Array< T, N > const &y)
 
template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > & celeritas::operator/= (Array< T, N > &x, T2 const &y)
 
template<class T , size_type N>
Array< T, N > celeritas::operator+ (Array< T, N > const &x, Array< T, N > const &y)
 
template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > celeritas::operator+ (Array< T, N > const &x, T2 const &y)
 
template<class T , size_type N>
Array< T, N > celeritas::operator- (Array< T, N > const &x, Array< T, N > const &y)
 
template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > celeritas::operator- (Array< T, N > const &x, T2 const &y)
 
template<class T , size_type N>
Array< T, N > celeritas::operator* (Array< T, N > const &x, Array< T, N > const &y)
 
template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > celeritas::operator* (Array< T, N > const &x, T2 const &y)
 
template<class T , size_type N>
Array< T, N > celeritas::operator/ (Array< T, N > const &x, Array< T, N > const &y)
 
template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > celeritas::operator/ (Array< T, N > const &x, T2 const &y)
 

Detailed Description

Mathematical operators for the Array type.

For performance reasons, avoid chaining these operators together: unroll arithmetic when possible. Note that all types must be consistent (unless promotion is automatically applied to scalar arguments), so you cannot multiply an array of doubles with an array of ints without explicitly converting first.

Macro Definition Documentation

◆ CELER_DEFINE_ARRAY_ARITHM

#define CELER_DEFINE_ARRAY_ARITHM (   TOKEN)
Value:
template<class T, size_type N> \
inline CELER_FUNCTION Array<T, N> operator TOKEN(Array<T, N> const& x, \
Array<T, N> const& y) \
{ \
Array<T, N> result{x}; \
return (result TOKEN## = y); \
} \
\
template<class T, size_type N, class T2 = std::remove_cv_t<T>> \
inline CELER_FUNCTION Array<T, N> operator TOKEN(Array<T, N> const& x, \
T2 const& y) \
{ \
Array<T, N> result{x}; \
return (result TOKEN## = y); \
}
#define CELER_FUNCTION
Decorate a function that works on both host and device, with and without NVCC.
Definition Macros.hh:31
@ x
X axis/I index coordinate.

◆ CELER_DEFINE_ARRAY_ASSIGN

#define CELER_DEFINE_ARRAY_ASSIGN (   TOKEN)
Value:
template<class T, size_type N> \
inline CELER_FUNCTION Array<T, N>& operator TOKEN(Array<T, N>& x, \
Array<T, N> const& y) \
{ \
for (size_type i = 0; i != N; ++i) \
{ \
x[i] TOKEN y[i]; \
} \
return x; \
} \
\
template<class T, size_type N, class T2 = std::remove_cv_t<T>> \
inline CELER_FUNCTION Array<T, N>& operator TOKEN(Array<T, N>& x, \
T2 const& y) \
{ \
for (size_type i = 0; i != N; ++i) \
{ \
x[i] TOKEN y; \
} \
return x; \
}
@ y
Y axis/J index coordinate.

Function Documentation

◆ operator*() [1/2]

template<class T , size_type N>
Array< T, N > celeritas::operator* ( Array< T, N > const x,
Array< T, N > const y 
)
inline

Arithmetic

◆ operator*() [2/2]

template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > celeritas::operator* ( Array< T, N > const x,
T2 const y 
)
inline

Arithmetic

◆ operator*=() [1/2]

template<class T , size_type N>
Array< T, N > & celeritas::operator*= ( Array< T, N > &  x,
Array< T, N > const y 
)
inline

Assignment arithmetic

◆ operator*=() [2/2]

template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > & celeritas::operator*= ( Array< T, N > &  x,
T2 const y 
)
inline

Assignment arithmetic

◆ operator+() [1/2]

template<class T , size_type N>
Array< T, N > celeritas::operator+ ( Array< T, N > const x,
Array< T, N > const y 
)
inline

Arithmetic

◆ operator+() [2/2]

template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > celeritas::operator+ ( Array< T, N > const x,
T2 const y 
)
inline

Arithmetic

◆ operator+=() [1/2]

template<class T , size_type N>
Array< T, N > & celeritas::operator+= ( Array< T, N > &  x,
Array< T, N > const y 
)
inline

Assignment arithmetic

◆ operator+=() [2/2]

template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > & celeritas::operator+= ( Array< T, N > &  x,
T2 const y 
)
inline

Assignment arithmetic

◆ operator-() [1/2]

template<class T , size_type N>
Array< T, N > celeritas::operator- ( Array< T, N > const x,
Array< T, N > const y 
)
inline

Arithmetic

◆ operator-() [2/2]

template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > celeritas::operator- ( Array< T, N > const x,
T2 const y 
)
inline

Arithmetic

◆ operator-=() [1/2]

template<class T , size_type N>
Array< T, N > & celeritas::operator-= ( Array< T, N > &  x,
Array< T, N > const y 
)
inline

Assignment arithmetic

◆ operator-=() [2/2]

template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > & celeritas::operator-= ( Array< T, N > &  x,
T2 const y 
)
inline

Assignment arithmetic

◆ operator/() [1/2]

template<class T , size_type N>
Array< T, N > celeritas::operator/ ( Array< T, N > const x,
Array< T, N > const y 
)
inline

Arithmetic

◆ operator/() [2/2]

template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > celeritas::operator/ ( Array< T, N > const x,
T2 const y 
)
inline

Arithmetic

◆ operator/=() [1/2]

template<class T , size_type N>
Array< T, N > & celeritas::operator/= ( Array< T, N > &  x,
Array< T, N > const y 
)
inline

Assignment arithmetic

◆ operator/=() [2/2]

template<class T , size_type N, class T2 = std::remove_cv_t<T>>
Array< T, N > & celeritas::operator/= ( Array< T, N > &  x,
T2 const y 
)
inline

Assignment arithmetic