qmatrix.h

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Alan Grimes   *
00003  *   agrimes@speakeasy.net   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef QMATRIX_H
00022 #define QMATRIX_H
00023 
00024 #ifndef QVECTOR_H
00025 #include "qvector.h"
00026 #endif
00027 
00028 class QuickMatrix {
00029 public :
00030          QuickMatrix(CUI m_in, CUI n_in);
00031          QuickMatrix(CUI m_in);
00032          QuickMatrix(const QuickMatrix *old); // ye olde copy constructor.
00033         ~QuickMatrix();
00034 
00035 // accessors
00036 // we use accessors so that we can provide range checking.
00037 // we use Smalltalk style naming conventions.
00038         double at(CUI m_a, CUI n_a) const;
00039         bool atPut(CUI m_a, CUI n_a, const double val);
00040         bool atAdd(CUI m_a, CUI n_a, const double val); // just give a negative val to subtract. =)
00041 
00042         bool isSquare() const;
00043 
00044         double *&operator[]( const int i ) { return values[i]; }
00045         const double *operator[]( const int i ) const { return values[i]; }
00046 
00047         unsigned int size_m() const;
00048         unsigned int size_n() const;
00049 
00050 // functions for some elementary row operations.
00051 // these are actually procedures because they operate on the current matrix rather than
00052 // producing a results matrix.  
00053         bool scaleRow(CUI m_a, const double scalor);
00054                 // changes B by adding A.
00055         bool addRowToRow(CUI m_a, CUI m_b);
00056                 // changes B by adding the result of A times a scalor 
00057         bool scaleAndAdd(CUI m_a, CUI m_b, const double scalor);
00058         bool partialScaleAndAdd(CUI m_a, CUI m_b, const double scalor);
00059         bool swapRows(CUI m_a, CUI m_b);
00060 
00061 // functions that accelerate certain types of
00062 // operations that would otherwise require millions of at()'s
00063         double multstep(CUI row, CUI pos, CUI col) const;
00064         double multRowCol(CUI row, CUI col, CUI lim) const;
00065 
00066         QuickMatrix *transposeSquare() const; // Multiplies self by transpose.
00067         QuickVector *transposeMult(const QuickVector *operandvec) const;
00068 
00069 // utility functions:
00070         void fillWithRandom();
00071         void fillWithZero();
00072         double rowsum(CUI m);
00073         double absrowsum(CUI m);
00074         QuickVector *normalizeRows();
00075 
00076 // Matrix arithmetic.
00077         QuickMatrix *operator +=(const QuickMatrix *othermat);
00078         QuickMatrix *operator *=(const double y);
00079         QuickMatrix *operator =(const double y); // sets the diagonal to a constant.
00080         QuickMatrix *operator =(const QuickMatrix *oldmat);
00081         QuickVector *operator *(const QuickVector *operandvec) const;
00082         QuickMatrix *operator *(const QuickMatrix *operandmat) const;
00083 
00084 // debugging
00085         void dumpToAux() const;
00086 
00087 private :
00088 // We don't have a default matrix size so therefore we lock the default constructor. 
00089         QuickMatrix() {};
00090 
00091         void allocator();
00092 
00093         unsigned int m, n;
00094         double **values;
00095 };
00096 
00097 #endif

Generated on Tue May 8 17:05:32 2007 for KTechLab by  doxygen 1.5.1