var_square_matrix.h
00001 /* Copyright (C) 2003-2005  Martin Förg
00002 
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Lesser General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2.1 of the License, or (at your option) any later version.
00007  * 
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Lesser General Public License for more details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00016  *
00017  * Contact:
00018  *   martin.o.foerg@googlemail.com
00019  *
00020  */
00021 
00022 #ifndef var_square_matrix_h
00023 #define var_square_matrix_h
00024 
00025 #include "fixed_general_matrix.h"
00026 
00027 namespace fmatvec {
00028 
00038   template <class AT> class SquareMatrix<Var,AT> : public Matrix<General,Var,Var,AT> {
00039 
00040     using Matrix<General,Var,Var,AT>::M;
00041 
00042     public:
00043 
00048       SquareMatrix() : Matrix<General,Var,Var,AT>() { }
00049 
00050 //      template<class Ini=All<AT> >
00051 //      SquareMatrix(int m, Ini ini=All<AT>()) : Matrix<General,Var,Var,AT>(m,m,ini) { } 
00052 
00053       SquareMatrix(int m, Noinit ini) : Matrix<General,Var,Var,AT>(m,m,ini) { } 
00054       SquareMatrix(int m, Init ini=INIT, const AT &a=0) : Matrix<General,Var,Var,AT>(m,m,ini,a) { } 
00055       SquareMatrix(int m, Eye ini, const AT &a=1) : Matrix<General,Var,Var,AT>(m,m,ini,a) { } 
00056 
00057       SquareMatrix(const char *str) : Matrix<General,Var,Var,AT>(str) { }
00058 
00063       template<class Type, class Row, class Col>
00064       explicit SquareMatrix(const Matrix<Type,Row,Col,AT>&  A) : Matrix<General,Var,Var,AT>(A) {
00065       }
00066 
00067       template<class Row>
00068       SquareMatrix(const SquareMatrix<Row,AT> &A) : Matrix<General,Var,Var,AT>(A) {
00069       }
00070 
00071       SquareMatrix<Var,AT>& resize() {
00072         Matrix<General,Var,Var,AT>::resize();
00073         return *this;
00074       }
00075 
00076       SquareMatrix<Var,AT>& resize(int m, Noinit) {
00077         Matrix<General,Var,Var,AT>::resize(m,m,Noinit());
00078         return *this;
00079       }
00080 
00081       SquareMatrix<Var,AT>& resize(int m, Init ini=INIT, const AT &a=0) {
00082         Matrix<General,Var,Var,AT>::resize(m,m,ini,a);
00083         return *this;
00084       }
00085 
00086       SquareMatrix<Var,AT>& resize(int m, Eye ini, const AT &a=1) {
00087         Matrix<General,Var,Var,AT>::resize(m,m,ini,a);
00088         return *this;
00089       }
00090 
00097       template <class Type, class Row, class Col> SquareMatrix<Var,AT>& operator=(const Matrix<Type,Row,Col,AT> &A) {
00098         Matrix<General,Var,Var,AT>::operator=(A);
00099         return *this;
00100       }
00101 
00106       int size() const {return M;};
00107 
00108       using Matrix<General,Var,Var,AT>::operator();
00109       using Matrix<General,Var,Var,AT>::e;
00110 
00115       inline operator std::vector<std::vector<AT> >();
00116 
00117       inline const SquareMatrix<Var,AT> T() const;
00118 
00119   };
00120 
00121   template <class AT>
00122     inline const SquareMatrix<Var,AT> SquareMatrix<Var,AT>::T() const {
00123       SquareMatrix<Var,AT> A(NONINIT);
00124       for(int i=0; i<M; i++)
00125         for(int j=0; j<M; j++)
00126           A.e(i,j) = e(j,i);
00127       return A;
00128     }
00129 
00130   template <class AT>
00131     inline SquareMatrix<Var,AT>::operator std::vector<std::vector<AT> >() {
00132       std::vector<std::vector<AT> > ret(size());
00133       for(int r=0; r<size(); r++) {
00134         ret[r].resize(size());
00135         for(int c=0; c<size(); c++)
00136           ret[r][c]= e(r,c);
00137       }
00138       return ret;
00139     }
00140 
00141 }
00142 
00143 #endif