/*============================================================================= File: matrix.h Purpose: Revision: $Id: matrix.h,v 1.3 2002/05/24 17:08:34 philosophil Exp $ Created by: Philippe Lavoie (3 Oct, 1996) Modified by: Copyright notice: Copyright (C) 1996-1998 Philippe Lavoie This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. =============================================================================*/ #ifndef _Matrix_matrix_h_ #define _Matrix_matrix_h_ #include #include "matrix_global.h" #include "barray2d.h" #include "vector.h" // Predefining every friend functions // This is required by latest ISO C++ draft /*! */ namespace PLib { template class Matrix ; template PLib::Matrix operator+(const PLib::Matrix&,const PLib::Matrix&); template PLib::Matrix operator-(const PLib::Matrix&,const PLib::Matrix&); template PLib::Matrix operator*(const PLib::Matrix&,const PLib::Matrix&); template PLib::Matrix operator*(const double,const PLib::Matrix&); template PLib::Matrix operator*(const Complex&,const PLib::Matrix&); template PLib::Vector operator*(const PLib::Matrix&,const PLib::Vector&); template int operator==(const PLib::Matrix&,const PLib::Matrix&); template int operator!=(const PLib::Matrix& a,const PLib::Matrix& b) ; template <> PLib::Matrix operator*(const double d, const PLib::Matrix &a); template <> PLib::Matrix operator*(const Complex &d, const PLib::Matrix &a); /*! \brief A templated matrix class with basic mathematical operators This is a matrix class which has basic mathematical operators and some routines for input/output. \author Philippe Lavoie \date 4 Oct. 1996 */ template class Matrix : public Basic2DArray { public: Matrix(const int r,const int c) : Basic2DArray(r,c) {} Matrix() : Basic2DArray() {} Matrix(const Matrix& M) : Basic2DArray(M) {} Matrix(T* p, const int r, const int c) : Basic2DArray(p,r,c) {} //~Matrix() {} Matrix& operator=(const Matrix&); T operator=(const T v) { reset((T)0); diag(v); return v; } void submatrix(int i, int j, Matrix&); void as(int rw, int cl, Matrix&) ; Matrix get(int rw, int cl, int nr, int nc) const ; // Mathematical functions Matrix& operator+=(const Matrix&); Matrix& operator-=(const Matrix&); Matrix& operator+=(double d) ; Matrix& operator-=(double d) ; Matrix& operator*=(double d) ; Matrix& operator/=(double d) ; #ifdef HAVE_ISO_FRIEND_DECL friend Matrix operator+ <>(const Matrix&, const Matrix&); friend Matrix operator- <>(const Matrix&, const Matrix&); friend Matrix operator* <>(const Matrix&, const Matrix&); friend Matrix operator* <>(const double, const Matrix&); friend Matrix operator* <>(const Complex&, const Matrix&); friend Vector operator* <>(const Matrix&, const Vector&); friend int operator== <>(const Matrix&, const Matrix&); friend int operator!= <>(const Matrix& a, const Matrix& b) ; #else friend Matrix operator+ (const Matrix&, const Matrix&); friend Matrix operator- (const Matrix&, const Matrix&); friend Matrix operator* (const Matrix&, const Matrix&); friend Matrix operator* (const double, const Matrix&); friend Matrix operator* (const Complex&, const Matrix&); friend Vector operator* (const Matrix&, const Vector&); friend int operator== (const Matrix&, const Matrix&); friend int operator!= (const Matrix& a, const Matrix& b) ; #endif Matrix herm() const ; Matrix transpose() const ; Matrix flop() const ; T trace() const ; double norm(void) ; void diag(const T fv); Vector getDiag(); void qSort() ; // file i/o functions int read(char* filename) ; int read(char* filename, int rows, int cols) ; int write(char* filename) ; int writeRaw(char* filename) ; // calls to LAPACK functions are defined in this class friend class LAPACK ; }; } // end namespace template PLib::Matrix comm( const PLib::Matrix& a, const PLib::Matrix& b); template inline PLib::Matrix herm( const PLib::Matrix& a) { return a.herm() ; } template inline PLib::Matrix transpose( const PLib::Matrix& a) { return a.transpose() ; } template inline T trace( const PLib::Matrix& a) { return a.trace() ; } template inline int operator!=(const PLib::Matrix& a, const PLib::Matrix& b) { return a==b?0:1 ; } typedef PLib::Matrix Matrix_INT ; typedef PLib::Matrix Matrix_BYTE ; typedef PLib::Matrix Matrix_FLOAT ; typedef PLib::Matrix Matrix_DOUBLE ; typedef PLib::Matrix Matrix_COMPLEX ; typedef PLib::Matrix Matrix_UBYTE ; typedef PLib::Matrix Matrix_Point3Df ; typedef PLib::Matrix Matrix_HPoint3Df ; typedef PLib::Matrix Matrix_Point3Dd ; typedef PLib::Matrix Matrix_HPoint3Dd ; typedef PLib::Matrix Matrix_Point2Df ; typedef PLib::Matrix Matrix_HPoint2Df ; typedef PLib::Matrix Matrix_Point2Dd ; typedef PLib::Matrix Matrix_HPoint2Dd ; typedef PLib::Matrix PlMatrix_int ; typedef PLib::Matrix PlMatrix_byte ; typedef PLib::Matrix PlMatrix_float ; typedef PLib::Matrix PlMatrix_double ; typedef PLib::Matrix PlMatrix_complex ; typedef PLib::Matrix PlMatrix_ubyte ; typedef PLib::Matrix PlMatrix_Point3Df ; typedef PLib::Matrix PlMatrix_HPoint3Df ; typedef PLib::Matrix PlMatrix_Point3Dd ; typedef PLib::Matrix PlMatrix_HPoint3Dd ; typedef PLib::Matrix PlMatrix_Point2Df ; typedef PLib::Matrix PlMatrix_HPoint2Df ; typedef PLib::Matrix PlMatrix_Point2Dd ; typedef PLib::Matrix PlMatrix_HPoint2Dd ; #ifdef INCLUDE_TEMPLATE_SOURCE #include "matrix.cpp" #endif #endif