20 #ifndef JDFTX_CORE_SCALED_H 21 #define JDFTX_CORE_SCALED_H 28 scaled(
const T& data,
double scale=1.0) : data(data), scale(scale) {}
29 operator T()
const { T ret(data);
return ret *= scale; }
30 scaled<T>& operator*=(
double s) { scale *= s;
return *
this; }
33 template<
typename T> T&
operator+=(T& y,
const scaled<T>& x) {
if(y)
axpy(x.scale, x.data, y);
else y = x.scale * x.data;
return y; }
34 template<
typename T> T&
operator-=(T& y,
const scaled<T>& x) {
if(y)
axpy(-x.scale, x.data, y);
else y = (-x.scale) * x.data;
return y; }
Tptr & operator-=(Tptr &in, const Tptr &other)
Decrement.
Definition: Operators.h:170
Tptr operator+(const Tptr &in1, const Tptr &in2)
Add (preserve inputs)
Definition: Operators.h:171
void axpy(double alpha, const Tptr &X, Tptr &Y)
Generic axpy for complex data types (Note: null pointers are treated as zero)
Definition: Operators.h:158
Tptr & operator+=(Tptr &in, const Tptr &other)
Increment.
Definition: Operators.h:169
Tptr operator-(const Tptr &in1, const Tptr &in2)
Subtract (preserve inputs)
Definition: Operators.h:175