Commit a6c21879 authored by Pawel Sznajder's avatar Pawel Sznajder
Browse files

refs#16

In NumA++ (trunk):
- in linear_algebra/matrix_complex and linear_algebra/vector_complex
	- dynamic vectors/matrices replaced by std::vectors
	- documentation added
	- memory leakage fixed
	- few cosmetic changes
parent a46f8502
......@@ -14,22 +14,59 @@
namespace NumA {
class MatrixComplex2D : public MatrixComplexD {
/**
* 2x2 matrix of complex numbers
*/
class MatrixComplex2D: public MatrixComplexD {
public:
/** Default constructor
*/
MatrixComplex2D();
/** Copy constructor
@param v Object to be copied
*/
MatrixComplex2D(const MatrixComplex2D& v);
/** Copy constructor
@param v Object to be copied
*/
MatrixComplex2D(const MatrixComplexD& v);
/** Destructor
*/
~MatrixComplex2D();
virtual void operator=(const MatrixComplex2D& rhs); ///< Equal
virtual MatrixComplex2D& operator+(const MatrixComplex2D& rhs); ///< Plus
virtual MatrixComplex2D& operator-(const MatrixComplex2D& rhs); ///< Minus
virtual MatrixComplex2D& operator*(const double& rhs); ///< Multiplication rhs
friend MatrixComplex2D& operator*(const double& lhs, MatrixComplex2D& rhs); ///< Multiplication lhs
virtual MatrixComplex2D& operator*(const std::complex<double>& rhs); ///< Multiplication rhs
friend MatrixComplex2D& operator*(const std::complex<double>& lhs, MatrixComplex2D& rhs); ///< Multiplication lhs
/** Operator =
*/
void operator=(const MatrixComplex2D& rhs);
/** Operator +
*/
MatrixComplex2D operator+(const MatrixComplex2D& rhs);
/** Operator -
*/
MatrixComplex2D operator-(const MatrixComplex2D& rhs);
/** Operator * by real number (rhs)
*/
MatrixComplex2D operator*(const double& rhs);
/** Operator * by real number (lhs)
*/
friend MatrixComplex2D operator*(const double& lhs, MatrixComplex2D& rhs);
/** Operator * by complex number (rhs)
*/
MatrixComplex2D operator*(const std::complex<double>& rhs);
/** Operator * by complex number (lhs)
*/
friend MatrixComplex2D operator*(const std::complex<double>& lhs,
MatrixComplex2D& rhs);
};
} /* namespace NumA */
......
......@@ -14,22 +14,59 @@
namespace NumA {
class MatrixComplex3D : public MatrixComplexD {
/**
* 3x3 matrix of complex numbers
*/
class MatrixComplex3D: public MatrixComplexD {
public:
/** Default constructor
*/
MatrixComplex3D();
/** Copy constructor
@param v Object to be copied
*/
MatrixComplex3D(const MatrixComplex3D& v);
/** Copy constructor
@param v Object to be copied
*/
MatrixComplex3D(const MatrixComplexD& v);
/** Destructor
*/
~MatrixComplex3D();
virtual void operator=(const MatrixComplex3D& rhs); ///< Equal
virtual MatrixComplex3D& operator+(const MatrixComplex3D& rhs); ///< Plus
virtual MatrixComplex3D& operator-(const MatrixComplex3D& rhs); ///< Minus
virtual MatrixComplex3D& operator*(const double& rhs); ///< Multiplication rhs
friend MatrixComplex3D& operator*(const double& lhs, MatrixComplex3D& rhs); ///< Multiplication lhs
virtual MatrixComplex3D& operator*(const std::complex<double>& rhs); ///< Multiplication rhs
friend MatrixComplex3D& operator*(const std::complex<double>& lhs, MatrixComplex3D& rhs); ///< Multiplication lhs
/** Operator =
*/
void operator=(const MatrixComplex3D& rhs);
/** Operator +
*/
MatrixComplex3D operator+(const MatrixComplex3D& rhs);
/** Operator -
*/
MatrixComplex3D operator-(const MatrixComplex3D& rhs);
/** Operator * by real number (rhs)
*/
MatrixComplex3D operator*(const double& rhs);
/** Operator * by real number (lhs)
*/
friend MatrixComplex3D operator*(const double& lhs, MatrixComplex3D& rhs);
/** Operator * by complex number (rhs)
*/
MatrixComplex3D operator*(const std::complex<double>& rhs);
/** Operator * by complex number (lhs)
*/
friend MatrixComplex3D operator*(const std::complex<double>& lhs,
MatrixComplex3D& rhs);
};
} /* namespace NumA */
......
......@@ -14,22 +14,59 @@
namespace NumA {
class MatrixComplex4D : public MatrixComplexD {
/**
* 4x4 matrix of complex numbers
*/
class MatrixComplex4D: public MatrixComplexD {
public:
/** Default constructor
*/
MatrixComplex4D();
/** Copy constructor
@param v Object to be copied
*/
MatrixComplex4D(const MatrixComplex4D& v);
/** Copy constructor
@param v Object to be copied
*/
MatrixComplex4D(const MatrixComplexD& v);
/** Destructor
*/
~MatrixComplex4D();
virtual void operator=(const MatrixComplex4D& rhs); ///< Equal
virtual MatrixComplex4D& operator+(const MatrixComplex4D& rhs); ///< Plus
virtual MatrixComplex4D& operator-(const MatrixComplex4D& rhs); ///< Minus
virtual MatrixComplex4D& operator*(const double& rhs); ///< Multiplication rhs
friend MatrixComplex4D& operator*(const double& lhs, MatrixComplex4D& rhs); ///< Multiplication lhs
virtual MatrixComplex4D& operator*(const std::complex<double>& rhs); ///< Multiplication rhs
friend MatrixComplex4D& operator*(const std::complex<double>& lhs, MatrixComplex4D& rhs); ///< Multiplication lhs
/** Operator =
*/
void operator=(const MatrixComplex4D& rhs);
/** Operator +
*/
MatrixComplex4D operator+(const MatrixComplex4D& rhs);
/** Operator -
*/
MatrixComplex4D operator-(const MatrixComplex4D& rhs);
/** Operator * by real number (rhs)
*/
MatrixComplex4D operator*(const double& rhs);
/** Operator * by real number (lhs)
*/
friend MatrixComplex4D operator*(const double& lhs, MatrixComplex4D& rhs);
/** Operator * by complex number (rhs)
*/
MatrixComplex4D operator*(const std::complex<double>& rhs);
/** Operator * by complex number (lhs)
*/
friend MatrixComplex4D operator*(const std::complex<double>& lhs,
MatrixComplex4D& rhs);
};
} /* namespace NumA */
......
......@@ -9,47 +9,115 @@
#define MATRIXCOMPLEXD_H_
#include <complex>
#include <vector>
namespace NumA {
/**
* Matrix of complex numbers of undefined size
*/
class MatrixComplexD {
public:
/** Default constructor
*/
MatrixComplexD();
/** Constructor with number of elements to be set
@param n Number of x elements
@param n Number of y elements
*/
MatrixComplexD(const unsigned int n, const unsigned int m);
/** Copy constructor
@param v Object to be copied
*/
MatrixComplexD(const MatrixComplexD& v);
/** Destructor
*/
virtual ~MatrixComplexD();
/** Dimension index
*/
enum Dim {
X = 1, Y = 2
};
MatrixComplexD& Conjunct(); ///< Conjunction
MatrixComplexD& Mult(const MatrixComplexD& v); ///< Multiplication
void Clear(); ///< Set zero-s to all elements
void MakeUnit(); ///< Set ones-s to all diagonal elements
/** Get conjunction of matrix
*/
MatrixComplexD Conjunct() const;
/** Multiply this with other matrix
@param v Other matrix
*/
MatrixComplexD Mult(const MatrixComplexD& v) const;
/** Clear vector (set zeros to all elements)
*/
void Clear();
/** Make unit (set ones to diagonal elements)
*/
void MakeUnit();
/** Operator =
*/
void operator=(const MatrixComplexD& rhs);
/** Operator +
*/
MatrixComplexD operator+(const MatrixComplexD& rhs);
/** Operator -
*/
MatrixComplexD operator-(const MatrixComplexD& rhs);
/** Operator * by real number (rhs)
*/
MatrixComplexD operator*(const double& rhs);
/** Operator * by real number (lhs)
*/
friend MatrixComplexD operator*(const double& lhs, MatrixComplexD& rhs);
/** Operator * by complex number (rhs)
*/
MatrixComplexD operator*(const std::complex<double>& rhs);
/** Operator * by complex number (lhs)
*/
friend MatrixComplexD operator*(const std::complex<double>& lhs,
MatrixComplexD& rhs);
/** Get number of elements for given dimension
@param v Dimension
*/
unsigned int GetNElements(const Dim v) const;
virtual void operator=(const MatrixComplexD& rhs); ///< Equal
virtual MatrixComplexD& operator+(const MatrixComplexD& rhs); ///< Plus
virtual MatrixComplexD& operator-(const MatrixComplexD& rhs); ///< Minus
virtual MatrixComplexD& operator*(const double& rhs); ///< Multiplication rhs
friend MatrixComplexD& operator*(const double& lhs, MatrixComplexD& rhs); ///< Multiplication lhs
virtual MatrixComplexD& operator*(const std::complex<double>& rhs); ///< Multiplication rhs
friend MatrixComplexD& operator*(const std::complex<double>& lhs,
MatrixComplexD& rhs); ///< Multiplication lhs
/** Set element
@param i Index of x element
@param j Index of y element
@param value Value to be set
*/
void SetElement(const unsigned int i, const unsigned int j,
const std::complex<double> value);
unsigned int GetDimension(const Dim v) const; ///< Get dimension
void SetElement(const unsigned int i, const unsigned int j, const std::complex<double> value); ///< Set element
std::complex<double> GetElement(const unsigned int i, const unsigned int j) const; ///< Get element
/** Get element
@param i Index of x element
@param j Index of y element
*/
std::complex<double> GetElement(const unsigned int i,
const unsigned int j) const;
private:
void CompareDimension(MatrixComplexD v); ///< Compare dimensions of this and other vector
void CompareNElements(const MatrixComplexD& v) const; ///< Compare number of elements of this and other vector
unsigned int n; ///< Dimension
unsigned int m; ///< Dimension
std::complex<double>** element; ///< Elements
unsigned int m_n; ///< Number of x elements
unsigned int m_m; ///< Number of y elements
std::vector<std::vector<std::complex<double> > > m_elements; ///< Elements
};
} /* namespace NumA */
......
......@@ -14,23 +14,59 @@
namespace NumA {
class VectorComplex2D : public VectorComplexD{
/**
* 2D vector of complex numbers
*/
class VectorComplex2D: public VectorComplexD {
public:
/** Default constructor
*/
VectorComplex2D();
/** Copy constructor
@param v Object to be copied
*/
VectorComplex2D(const VectorComplex2D& v);
/** Copy constructor
@param v Object to be copied
*/
VectorComplex2D(const VectorComplexD& v);
/** Destructor
*/
~VectorComplex2D();
virtual void operator=(const VectorComplex2D& v); ///< Equal
virtual VectorComplex2D& operator+(const VectorComplex2D& rhs); ///< Plus
virtual VectorComplex2D& operator-(const VectorComplex2D& rhs); ///< Minus
virtual VectorComplex2D& operator*(const double& rhs); ///< Multiplication rhs
friend VectorComplex2D& operator*(const double& lhs, VectorComplex2D& rhs); ///< Multiplication lhs
virtual VectorComplex2D& operator*(const std::complex<double>& rhs); ///< Multiplication rhs
friend VectorComplex2D& operator*(const std::complex<double>& lhs, VectorComplex2D& rhs); ///< Multiplication lhs
/** Operator =
*/
void operator=(const VectorComplex2D& v);
/** Operator +
*/
VectorComplex2D operator+(const VectorComplex2D& rhs);
/** Operator -
*/
VectorComplex2D operator-(const VectorComplex2D& rhs);
/** Operator * by real number (rhs)
*/
VectorComplex2D operator*(const double& rhs);
/** Operator * by real number (lhs)
*/
friend VectorComplex2D operator*(const double& lhs, VectorComplex2D& rhs);
/** Operator * by complex number (rhs)
*/
VectorComplex2D operator*(const std::complex<double>& rhs);
/** Operator * by complex number (lhs)
*/
friend VectorComplex2D operator*(const std::complex<double>& lhs,
VectorComplex2D& rhs);
};
} /* namespace NumA */
......
......@@ -14,23 +14,59 @@
namespace NumA {
class VectorComplex3D : public VectorComplexD{
/**
* 3D vector of complex numbers
*/
class VectorComplex3D: public VectorComplexD {
public:
/** Default constructor
*/
VectorComplex3D();
/** Copy constructor
@param v Object to be copied
*/
VectorComplex3D(const VectorComplex3D& v);
/** Copy constructor
@param v Object to be copied
*/
VectorComplex3D(const VectorComplexD& v);
/** Destructor
*/
~VectorComplex3D();
virtual void operator=(const VectorComplex3D& v); ///< Equal
virtual VectorComplex3D& operator+(const VectorComplex3D& rhs); ///< Plus
virtual VectorComplex3D& operator-(const VectorComplex3D& rhs); ///< Minus
virtual VectorComplex3D& operator*(const double& rhs); ///< Multiplication rhs
friend VectorComplex3D& operator*(const double& lhs, VectorComplex3D& rhs); ///< Multiplication lhs
virtual VectorComplex3D& operator*(const std::complex<double>& rhs); ///< Multiplication rhs
friend VectorComplex3D& operator*(const std::complex<double>& lhs, VectorComplex3D& rhs); ///< Multiplication lhs
/** Operator =
*/
virtual void operator=(const VectorComplex3D& v);
/** Operator +
*/
virtual VectorComplex3D operator+(const VectorComplex3D& rhs);
/** Operator -
*/
virtual VectorComplex3D operator-(const VectorComplex3D& rhs);
/** Operator * by real number (rhs)
*/
virtual VectorComplex3D operator*(const double& rhs);
/** Operator * by real number (lhs)
*/
friend VectorComplex3D operator*(const double& lhs, VectorComplex3D& rhs);
/** Operator * by complex number (rhs)
*/
virtual VectorComplex3D operator*(const std::complex<double>& rhs);
/** Operator * by complex number (lhs)
*/
friend VectorComplex3D operator*(const std::complex<double>& lhs,
VectorComplex3D& rhs);
};
} /* namespace NumA */
......
......@@ -14,23 +14,59 @@
namespace NumA {
class VectorComplex4D : public VectorComplexD{
/**
* 4D vector of complex numbers
*/
class VectorComplex4D: public VectorComplexD {
public:
/** Default constructor
*/
VectorComplex4D();
/** Copy constructor
@param v Object to be copied
*/
VectorComplex4D(const VectorComplex4D& v);
/** Copy constructor
@param v Object to be copied
*/
VectorComplex4D(const VectorComplexD& v);
/** Destructor
*/
~VectorComplex4D();
virtual void operator=(const VectorComplex4D& v); ///< Equal
virtual VectorComplex4D& operator+(const VectorComplex4D& rhs); ///< Plus
virtual VectorComplex4D& operator-(const VectorComplex4D& rhs); ///< Minus
virtual VectorComplex4D& operator*(const double& rhs); ///< Multiplication rhs
friend VectorComplex4D& operator*(const double& lhs, VectorComplex4D& rhs); ///< Multiplication lhs
virtual VectorComplex4D& operator*(const std::complex<double>& rhs); ///< Multiplication rhs
friend VectorComplex4D& operator*(const std::complex<double>& lhs, VectorComplex4D& rhs); ///< Multiplication lhs
/** Operator =
*/
virtual void operator=(const VectorComplex4D& v);
/** Operator +
*/
virtual VectorComplex4D operator+(const VectorComplex4D& rhs);
/** Operator -
*/
virtual VectorComplex4D operator-(const VectorComplex4D& rhs);
/** Operator * by real number (rhs)
*/
virtual VectorComplex4D operator*(const double& rhs);
/** Operator * by real number (lhs)
*/
friend VectorComplex4D operator*(const double& lhs, VectorComplex4D& rhs);
/** Operator * by complex number (rhs)
*/
virtual VectorComplex4D operator*(const std::complex<double>& rhs);
/** Operator * by complex number (lhs)
*/
friend VectorComplex4D operator*(const std::complex<double>& lhs,
VectorComplex4D& rhs);
};
} /* namespace NumA */
......
......@@ -9,44 +9,105 @@
#define VECTORCOMPLEXD_H_
#include <complex>
#include <vector>
namespace NumA {
/**
* Vector of complex numbers of undefined size
*/
class VectorComplexD {
public:
/** Default constructor
*/
VectorComplexD();
/** Constructor with number of elements to be set
@param n Number of elements
*/
VectorComplexD(const unsigned int n);
/** Copy constructor
@param v Object to be copied
*/
VectorComplexD(const VectorComplexD& v);
/** Destructor
*/
virtual ~VectorComplexD();
double Mag(); ///< Magnitude
VectorComplexD& Conjunct(); ///< Conjunction
std::complex<double>& Dot(const VectorComplexD& v); ///< Scalar product
void Clear(); ///< Set zero-s to all elements
/** Get magnitude of vector
*/
double Mag() const;
virtual void operator=(const VectorComplexD& rhs); ///< Equal
virtual VectorComplexD& operator+(const VectorComplexD& rhs); ///< Plus
virtual VectorComplexD& operator-(const VectorComplexD& rhs); ///< Minus
virtual VectorComplexD& operator*(const double& rhs); ///< Multiplication rhs
friend VectorComplexD& operator*(const double& lhs, VectorComplexD& rhs); ///< Multiplication lhs