27 #include <type_traits> 37 return std::unique_ptr<T[]>(_ptr);
44 template <typename T, typename std::enable_if<std::is_trivial<T>::value,
int>::type = 0>
45 inline void set_zero(T*
const __restrict _x,
const size_t _n) noexcept {
46 memset(_x, 0, _n*
sizeof(T));
54 template <typename T, typename std::enable_if<std::is_trivial<T>::value,
int>::type = 0>
55 inline void copy(T*
const __restrict _dest,
const T*
const __restrict _src,
const size_t _n) noexcept {
56 memcpy(_dest, _src, _n*
sizeof(T));
64 template <typename T, typename std::enable_if<std::is_trivial<T>::value,
int>::type = 0>
65 inline void copy_inplace(T*
const _x,
const T*
const _y,
const size_t _n) noexcept {
66 memmove(_x, _y, _n*
sizeof(T));
74 inline void copy_scaled(T*
const __restrict _x,
const T _alpha,
const T*
const _y,
const size_t _n) noexcept {
75 for(
size_t i = 0; i < _n; ++i) {
85 inline void scale(T*
const __restrict _x,
const T _alpha,
const size_t _n) noexcept {
86 for(
size_t i = 0; i < _n; i++) {
96 inline void add(T*
const __restrict _x,
const T*
const __restrict _y,
const size_t _n) noexcept {
97 for(
size_t i = 0; i < _n; i++) {
106 template <
typename T>
107 inline void add_scaled(T*
const __restrict _x,
const T _alpha,
const T*
const __restrict _y,
const size_t _n) noexcept {
108 for(
size_t i = 0; i < _n; i++) {
109 _x[i] += _alpha*_y[i];
void add(T *const __restrict _x, const T *const __restrict _y, const size_t _n) noexcept
Adds _n entries of _y to the ones of _x. I.e. x += y.
void copy_inplace(T *const _x, const T *const _y, const size_t _n) noexcept
Copys _n entries from _y to _x, allowing the accessed memry regions of _y and _x to overlap...
std::unique_ptr< T[]> make_unique_array(T *_ptr)
The main namespace of xerus.
void copy_scaled(T *const __restrict _x, const T _alpha, const T *const _y, const size_t _n) noexcept
Copys _n entries from _y to _x, simulationously scaling each entry by the factor _alpha. I.e x = alpha*y.
void scale(T *const __restrict _x, const T _alpha, const size_t _n) noexcept
Scales _n entries of _x by the factor _alpha. I.e. x = alpha*x.
void copy(T *const __restrict _dest, const T *const __restrict _src, const size_t _n) noexcept
Copys _n entries from _y to _x, where _y and _x must be disjunkt memory regions.
void set_zero(T *const __restrict _x, const size_t _n) noexcept
Sets all entries equal to zero.
void add_scaled(T *const __restrict _x, const T _alpha, const T *const __restrict _y, const size_t _n) noexcept
Adds _n entries of _y, scaled by _alpha to the ones of _x. I.e. x += alpha*y.
Header file for global shorthand notations of elementary integer types and attribute lists...