HILA
Loading...
Searching...
No Matches
Complex< T > Class Template Reference

Complex definition. More...

#include <cmplx.h>

Inheritance diagram for Complex< T >:

Public Member Functions

 Complex ()=default
 Construct a new Complex object.
 
real () const
 Real part of Complex number.
 
imag () const
 Imaginary part of Complex number.
 
Complex< T > & operator= (const Complex< T > &s) &=default
 Assignment operator.
 
squarenorm () const
 Compute square norm of Complex number.
 
abs () const
 Compute absolute value of Complex number.
 
arg () const
 Compute argument of Complex number.
 
Complex< T > conj () const
 Compute conjugate of Complex number.
 
Complex< T > dagger () const
 Compute dagger of Complex number.
 
Complex< T > polar (const T r, const T theta)
 Stores and returns Complex number given in polar coordinates.
 
Complex< T > & random ()
 Assign random values to Complex real and imaginary part.
 
Complex< T > & gaussian_random (double width=1.0)
 Produces complex gaussian random values.
 
Complex< T > operator+ () const
 Unary + operator.
 
Complex< T > operator- () const
 Unary - operator.
 
template<typename A >
Complex< T > & operator+= (const Complex< A > &lhs) &
 += addition assignment operator
 
template<typename A >
Complex< T > & operator-= (const Complex< A > &lhs) &
 -= subtraction assignment operator
 
template<typename A >
Complex< T > & operator*= (const Complex< A > &lhs) &
 *= multiply assignment operator
 
template<typename A >
Complex< T > & operator/= (const Complex< A > &lhs) &
 /= divide assignment operator
 
Complex< T > & operator++ ()
 ++ increment operator
 
Complex< T > & operator-- ()
 – decrement operator
 
template<typename A >
Complex< T > conj_mul (const Complex< A > &b) const
 Conjugate multiply method.
 
template<typename A >
Complex< T > mul_conj (const Complex< A > &b) const
 Multiply conjugate method.
 

Detailed Description

template<typename T>
class Complex< T >

Complex definition.

Define complex type as a class. This allows Hilapp to replace the internal type with a vector.

NOTE: T must be arithmetic and integrable. In the following documentation MyType refers to T, as in an arithmetic and integrable type.

Parameters
reReal part
imImaginary part
Template Parameters
TArithmetic type

Definition at line 56 of file cmplx.h.

Constructor & Destructor Documentation

◆ Complex()

template<typename T >
Complex< T >::Complex ( )
default

Construct a new Complex object.

The following ways of constructing a Complex object are

Default constructor:

Complex definition.
Definition cmplx.h:56

The default constructor initializes Complex::re and Complex::im to 0

Complex constructor:

Initialize both real and imaginary element

MyType a,b;
Complex<MyType> C(a,b); // C.re = a, C.im = b
double random()
Real valued uniform random number generator.
Definition hila_gpu.cpp:121

Copy constructor:

Initialize form already existing Complex number

MyType a,b;
Complex<MyType> B = C; // B.re = a, B.im = b

Equivalent initializing is Complex<MyType> B(C)

Real constructor:

Initialize only real element and sets imaginary to 0

Complex<MyType> C(a); // C.re = a, C.im = 0

Not equivalent to Complex<MyType> C = a

Zero constructor:

Initialize to zero with nullpointer trick

Complex<MyType> C = 0; // C.re = 0, C.im = 0

Equivalent to Complex<MyType> C and Complex<MyType> C(0)

Member Function Documentation

◆ abs()

template<typename T >
T Complex< T >::abs ( ) const
inline

Compute absolute value of Complex number.

Essentially sqrt(squarenorm(z)):

\begin{align} |z| = \sqrt{\Re(z)^2 + \Im(z)^2}\end{align}

Returns
T

Definition at line 259 of file cmplx.h.

◆ arg()

template<typename T >
T Complex< T >::arg ( ) const
inline

Compute argument of Complex number.

\begin{align} \arg(z) = \arctan2(\Im(z)),\Re(z)\end{align}

Returns
T

Definition at line 270 of file cmplx.h.

◆ conj()

template<typename T >
Complex< T > Complex< T >::conj ( ) const
inline

Compute conjugate of Complex number.

\begin{align} z &= x + i\cdot y \\ \Rightarrow z^* &= x - i\cdot y\end{align}

Returns
Complex<T>

Definition at line 282 of file cmplx.h.

◆ conj_mul()

template<typename T >
template<typename A >
Complex< T > Complex< T >::conj_mul ( const Complex< A > &  b) const
inline

Conjugate multiply method.

Conjugate a (*this) and multiply with give argument b: a.conj_mul(b) \( \equiv a^* \cdot b\)

Template Parameters
AType for Complex number b
Parameters
bnumber to multiply with
Returns
Complex<T>

Definition at line 611 of file cmplx.h.

◆ dagger()

template<typename T >
Complex< T > Complex< T >::dagger ( ) const
inline

Compute dagger of Complex number.

Alias to Complex::conj

\begin{align} z^* = z^\dagger \end{align}

Returns
Complex<T>

Definition at line 293 of file cmplx.h.

◆ gaussian_random()

template<typename T >
Complex< T > & Complex< T >::gaussian_random ( double  width = 1.0)
inline

Produces complex gaussian random values.

Uses hila::gaussrand2 for both real and imaignary part Assigns same random value for both real and imaginary part

Parameters
widthgaussian_random
Returns
Complex<T>&

Definition at line 338 of file cmplx.h.

◆ imag()

template<typename T >
T Complex< T >::imag ( ) const
inline

Imaginary part of Complex number.

Overloads exist for pass by value and pass by reference for when Complex is defined as non-const or const

Returns
T Imaginary part

Definition at line 177 of file cmplx.h.

◆ mul_conj()

template<typename T >
template<typename A >
Complex< T > Complex< T >::mul_conj ( const Complex< A > &  b) const
inline

Multiply conjugate method.

Multiply a (*this) with conjugate of given argument b: a.mul_conj(b) \( \equiv a \cdot b^*\)

Template Parameters
AType for Complex number b
Parameters
bnumber to conjugate and multiply withv
Returns
Complex<T>

Definition at line 627 of file cmplx.h.

◆ operator*=()

template<typename T >
template<typename A >
Complex< T > & Complex< T >::operator*= ( const Complex< A > &  lhs) &
inline

*= multiply assignment operator

Multiply assignment for Complex numbers can be performed in the following ways

Complex multiply assign:

Standard Complex number multiplication

\begin{align}z &= x + iy, w = x' + iy' \\ z w &= (x + iy)(x' + iy') = (xx'-yy') + i(xy' + yx')\end{align}

//
// z,w get values
//
z*=w; // z = zw as defined above

Real multiply assign:

Multiply assign by real number to both components of Complex number

z *= 2; // z.re = 2, z.im = 2

Definition at line 475 of file cmplx.h.

◆ operator+()

template<typename T >
Complex< T > Complex< T >::operator+ ( ) const
inline

Unary + operator.

Leaves Complex number unchanged

Returns
Complex<T>

Definition at line 350 of file cmplx.h.

◆ operator++()

template<typename T >
Complex< T > & Complex< T >::operator++ ( )
inline

++ increment operator

Increments real part of Complex number

z++; // z.re = 2, z.im = 1
Returns
Complex<T>&

Definition at line 557 of file cmplx.h.

◆ operator+=()

template<typename T >
template<typename A >
Complex< T > & Complex< T >::operator+= ( const Complex< A > &  lhs) &
inline

+= addition assignment operator

Addition assignment for Complex numbers can be performed in the following ways

Complex addition assignment:

z += w; // z.re = 1, z.im = 1

Real addition assignment:

Add assign only to real part of Complex number

z += 1; // z.re = 1, z.im = 0

Definition at line 391 of file cmplx.h.

◆ operator-()

template<typename T >
Complex< T > Complex< T >::operator- ( ) const
inline

Unary - operator.

Negates Complex number

Returns
Complex<T>

Definition at line 360 of file cmplx.h.

◆ operator--()

template<typename T >
Complex< T > & Complex< T >::operator-- ( )
inline

– decrement operator

Decrement real part of Complex number

z--; // z.re = 0, z.im = 1
Returns
Complex<T>&

Definition at line 574 of file cmplx.h.

◆ operator-=()

template<typename T >
template<typename A >
Complex< T > & Complex< T >::operator-= ( const Complex< A > &  lhs) &
inline

-= subtraction assignment operator

Subtraction assignment for Complex numbers can be performed in the following ways

Complex subtract assign:

z -= w; // z.re = -1, z.im = -1

Real subtract assign:

Subtract assign only to real part of Complex number

z -= 1; // z.re = -1, z.im = 0

Definition at line 427 of file cmplx.h.

◆ operator/=()

template<typename T >
template<typename A >
Complex< T > & Complex< T >::operator/= ( const Complex< A > &  lhs) &
inline

/= divide assignment operator

Divide assignment for Complex numbers can be performed in the following ways

Complex divide assign:

Standard Complex number division

\begin{align}z &= x + iy, w = x' + iy' \\ \frac{z}{w} &= \frac{x + iy}{x' + iy'} = \frac{(xx'+ yy') + i( yx' - xy')}{|w|^2}\end{align}

//
// z,w get values
//
z/=w; // z = z/w as defined above

Real divide assign:

Divide assign by real number to both components of Complex number

z /= 2; // z.re = 1, z.im = 1

Definition at line 527 of file cmplx.h.

◆ operator=()

template<typename T >
Complex< T > & Complex< T >::operator= ( const Complex< T > &  s) &
inlinedefault

Assignment operator.

The following ways of assigning a Complex object are

Assignment for Complex:

B = C; // B.re = C.re, B.im = C.im

Assignment from real:

Assigns real part and imaginary part to zero

B = a; // B.re = a, B.im = 0
Parameters
s
Returns
Complex<T>&

◆ polar()

template<typename T >
Complex< T > Complex< T >::polar ( const T  r,
const T  theta 
)
inline

Stores and returns Complex number given in polar coordinates.

\begin{align} z = r\cdot e^{i\theta} \end{align}

double r = 1;
double theta = 3.14159265358979/2; // pi/2
c.polar(r,theta); // c.re = 0, c.im = 1
Complex< T > polar(const T r, const T theta)
Stores and returns Complex number given in polar coordinates.
Definition cmplx.h:313
Parameters
rRadius of Complex number
thetaAngle of complex number in radians
Returns
Complex<T> Complex number

Definition at line 313 of file cmplx.h.

◆ random()

template<typename T >
Complex< T > & Complex< T >::random ( )
inline

Assign random values to Complex real and imaginary part.

Uses hila::random for both real and imaginary part

Returns
Complex<T>&

Definition at line 325 of file cmplx.h.

◆ real()

template<typename T >
T Complex< T >::real ( ) const
inline

Real part of Complex number.

Overloads exist for pass by value and pass by reference for when Complex is defined as non-const or const

Returns
T Real part

Definition at line 165 of file cmplx.h.

◆ squarenorm()

template<typename T >
T Complex< T >::squarenorm ( ) const
inline

Compute square norm of Complex number.

\begin{align} |z|^2 = \Re(z)^2 + \Im(z)^2\end{align}

Returns
T Squared norm

Definition at line 248 of file cmplx.h.


The documentation for this class was generated from the following file: