Go to the documentation of this file. 1 #ifndef PARGEMSLR_COMPLEX_H
2 #define PARGEMSLR_COMPLEX_H
11 #include <cuda_runtime.h>
105 #ifdef PARGEMSLR_CUDA
118 #ifdef PARGEMSLR_CUDA
133 return _real * _real + _imag * _imag;
143 return std::sqrt(_real * _real + _imag * _imag);
153 return std::sqrt(_real * _real + _imag * _imag);
192 #ifdef PARGEMSLR_CUDA
258 #ifdef PARGEMSLR_CUDA
303 const T new_real = _real * val.
Real() - _imag * val.
Imag();
304 _imag = _real * val.
Imag() + _imag * val.
Real();
321 const T new_lower = val.
Norm();
322 const T new_real = _real * val.
Real() + _imag * val.
Imag();
323 _imag = (val.
Real() * _imag - val.
Imag() * _real) / new_lower;
324 _real = new_real / new_lower;
337 template <
typename T>
352 template <
typename T>
367 template <
typename T>
381 template <
typename T>
394 template <
typename T>
409 template <
typename T>
424 template <
typename T>
438 template <
typename T>
451 template <
typename T>
466 template <
typename T>
481 template <
typename T>
496 template <
typename T>
511 template <
typename T>
526 template <
typename T>
541 template <
typename T>
544 return (val1.
Real() == val2) && (val1.
Imag() == T());
554 template <
typename T>
557 return (val1 == val2.
Real()) && (T() == val2.
Imag());
567 template <
typename T>
580 template <
typename T>
583 return (val1.
Real() != val2) || (val1.
Imag() != T());
593 template <
typename T>
596 return (val1 != val2.
Real()) || (T() != val2.
Imag());
606 template <
typename T>
619 template<
typename T,
typename CharT,
class Traits>
620 std::basic_ostream<CharT, Traits>&
621 operator<<(std::basic_ostream<CharT, Traits>& basic_os,
const ComplexValueClass<T>& val)
623 std::basic_ostringstream<CharT, Traits> basic_ostr;
624 basic_ostr.flags(basic_os.flags());
625 basic_ostr.imbue(basic_os.getloc());
626 basic_ostr.precision(basic_os.precision());
628 T val_r = val.Real();
629 T val_i = val.Imag();
639 basic_ostr<<std::abs(val_r);
648 basic_ostr<<std::abs(val_i)<<
"i";
649 return basic_os << basic_ostr.str();
652 typedef ComplexValueClass<float> complexs;
653 typedef ComplexValueClass<double> complexd;
655 #ifdef PARGEMSLR_OPENMP
657 #pragma omp declare reduction(+:complexs:omp_out += omp_in) initializer (omp_priv=complexs())
658 #pragma omp declare reduction(+:complexd:omp_out += omp_in) initializer (omp_priv=complexd())
ComplexValueClass< T > operator/(const ComplexValueClass< T > &val, const T &real)
/ operator.
Definition: complex.hpp:497
bool operator==(const ComplexValueClass< T > &val1, const T &val2)
== operator.
Definition: complex.hpp:542
ComplexValueClass< T > Conj() const
Get the conjugate.
Definition: complex.hpp:161
ComplexValueClass< T > & operator+=(const ComplexValueClass< T > &val)
+= operator with real value.
Definition: complex.hpp:274
Tell if a value is a real value.
Definition: complex.hpp:695
bool operator!=(const ComplexValueClass< T > &val1, const T &val2)
!= operator.
Definition: complex.hpp:581
ComplexValueClass(T real)
The constructor of complex value class.
Definition: complex.hpp:56
ComplexValueClass()
The constructor of complex value class.
Definition: complex.hpp:45
The c style struct of single complex.
Definition: complex.hpp:667
ComplexValueClass< T > & operator-=(const T &real)
-= operator with real value.
Definition: complex.hpp:220
ComplexValueClass< T > & operator*=(const ComplexValueClass< T > &val)
*= operator with real value.
Definition: complex.hpp:300
ComplexValueClass< T > & operator*=(const T &real)
*= operator with real value.
Definition: complex.hpp:232
ComplexValueClass< T > & operator+=(const T &real)
+= operator with real value.
Definition: complex.hpp:208
ComplexValueClass(T real, T imag)
The constructor of complex value class.
Definition: complex.hpp:68
T & Imag()
Get the imag part.
Definition: complex.hpp:108
const T & Real() const
Get the real part.
Definition: complex.hpp:95
ComplexValueClass< T > operator-(const ComplexValueClass< T > &val, const T &real)
operator.
Definition: complex.hpp:395
The template class complex.
Definition: complex.hpp:24
ComplexValueClass< T > & operator/=(const T &real)
/= operator with real value.
Definition: complex.hpp:245
const T & Imag() const
Get the imag part.
Definition: complex.hpp:121
T & Real()
Get the real part.
Definition: complex.hpp:82
T Norm() const
Get the square of 2-norm. Note that std::complex use the this value as norm.
Definition: complex.hpp:131
ComplexValueClass< T > & operator/=(const ComplexValueClass< T > &val)
/= operator with real value.
Definition: complex.hpp:315
ComplexValueClass< T > operator*(const ComplexValueClass< T > &val, const T &real)
operator.
Definition: complex.hpp:452
ComplexValueClass< T > & operator-=(const ComplexValueClass< T > &val)
-= operator with real value.
Definition: complex.hpp:287
ComplexValueClass< T > & operator=(const ComplexValueClass< T > &val)
= operator with real value.
Definition: complex.hpp:261
Tell if a value is a complex value.
Definition: complex.hpp:684
The c style struct of double complex.
Definition: complex.hpp:676
T Abs() const
Get the 2-norm as absolute value.
Definition: complex.hpp:151
ComplexValueClass< T > & operator=(const T &real)
Conver to real value, only keep the real part.
Definition: complex.hpp:195
ComplexValueClass< T > operator+(const ComplexValueClass< T > &val, const T &real)
operator.
Definition: complex.hpp:338
T Norm2() const
Get the 2-norm. Note that std::complex use the square of this value as norm.
Definition: complex.hpp:141