Main Page   Class Hierarchy   Compound List   File List   Compound Members  

mmatrix.h

00001 /***************************************************************************
00002     copyright            : (C) 2000 by Marko Grönroos
00003     email                : magi@iki.fi
00004  ***************************************************************************
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  ***************************************************************************
00012  *
00013  **/
00014 
00015 #ifndef __MATRIX_H__
00016 #define __MATRIX_H__
00017 
00018 #include "magic/mobject.h"
00019 #include "magic/mtable.h"
00020 
00023 class Matrix : public PackTable<double> {
00024   public:
00025                     Matrix          () : PackTable<double> () {;}
00026                     Matrix          (int rows, int cols) : PackTable<double> (rows, cols) {}
00027                     Matrix          (const Matrix& o) : PackTable<double> (o) {;}
00028                     ~Matrix         () {}
00029 
00030     void            make            (int rs, int cs) {
00031         PackTable<double>::make (rs, cs);
00032         operator= (0.0);
00033     }
00034 
00038     void            load            (const String& filename);
00039 
00043     void            load            (FILE* in);
00044 
00045     void            save            (FILE* out) const;
00046     
00047     const Matrix&   transpose       ();
00048     const Matrix&   multiplyToSum   (double s);
00049     double          sum             () const;
00050 
00051     void            splitVertical   (Matrix& a, Matrix& b, int column) const;
00052     void            splitHorizontal (Matrix& a, Matrix& b, int column) const;
00053 
00054     Matrix          sub             (int row0, int row1, int col0, int col1) const;
00055     void            insertColumn    (int cols);
00056     
00057     enum iters {end=-1};
00058 
00059     void            joinVertical    (const Matrix& a, const Matrix& b);
00060     void            joinHorizontal  (const Matrix& a, const Matrix& b);
00061     
00062     const Matrix&   operator=       (double x);
00063     const Matrix&   operator+=      (const Matrix& other);
00064     const Matrix&   operator+       (const Matrix& other) const {return Matrix(*this)+=other;}
00065     const Matrix&   operator+=      (double k);
00066     const Matrix&   operator+       (double k) const {return Matrix(*this)+=k;}
00067     const Matrix&   operator*=      (const Matrix& other);
00068     const Matrix&   operator*       (const Matrix& other) const {return Matrix(*this)*=other;}
00069     const Matrix&   operator*=      (double k);
00070     const Matrix&   operator*       (double k) const {return Matrix(*this)*=k;}
00071     const Matrix&   operator/       (double k) const {return Matrix(*this)*=1/k;}
00072     const Matrix&   operator/=      (double k) {return operator *= (1/k);}
00073 
00074     void            operator>>      (OStream& out) const;
00075     const Matrix&   operator= (const Matrix& other);
00076 
00077   private:
00078 };
00079 
00080 inline Matrix transpose (const Matrix& m) {
00081     Matrix res = m;
00082     res.transpose ();
00083     return res;
00084 }
00085 
00086 /*
00087 class SubMatrix : public Matrix {
00088     Matrix& matrix;
00089     int srow, scol, erow, ecol;
00090   public:
00091                     SubMatrix       (Matrix& m, int sr, int sc, int er, int ec) : matrix (m) {
00092                         ASSERT (sr<m.rows);
00093                         ASSERT (sc<m.cols);
00094                         ASSERT (er<m.rows);
00095                         ASSERT (ec<m.cols);
00096                         ASSERT (sr<=er);
00097                         ASSERT (sc<=ec);
00098                         srow=sr, scol=sc, erow=er, ecol=ec;
00099                         rows = erow-srow+1;
00100                         cols = ecol-scol+1;
00101                     }
00102     double&         get             (int row, int col);
00103 };
00104 */
00105 
00106 #endif

Generated at Tue Dec 4 19:53:26 2001 for MagiC++ by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001