Source: kalamaris/tmatrix.h
|
|
|
|
/* tmatrix.h -
This file is part of Kalamaris
Copyright (C) 2000 Antonio Larrosa Jimenez
Kalamaris' homepage : http://perso.wanadoo.es/antlarr/kalamaris.html
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
***************************************************************************/
#ifndef _TMATRIX_H
#define _TMATRIX_H
#include "vartype.h"
#include "map.h"
class Map;
class TMatrix : public T
{
protected:
Map ***matrix;
unsigned int nrows,ncols;
/*
* These variables are used to allocate more space than neccesary in
* autoExpand matrices, in order to allocate less chunks of memory when
* expanding time after time
*/
unsigned int maxrows,maxcols;
/**
* expandRows make sure that the row with number i exists and if it doesn't,
* it expands the current matrix to be big enough
*/
void expandRows(unsigned int i);
/**
* expandCols make sure that the column with number j exists and if it doesn't,
* it expands the current matrix to be big enough
*/
void expandCols(unsigned int j);
bool m_autoExpand;
public:
TMatrix(unsigned int _rdim=1, unsigned int _cdim=1, Map ***_maps=0L);
TMatrix( const TMatrix &x);
virtual ~TMatrix();
/**
* Deletes each element of the matrix (but doesn't change the dimensions)
*/
void clear(void);
const unsigned int nRows(void) const { return nrows; };
const unsigned int nCols(void) const { return ncols; };
virtual TMatrix *copy(void) const;
/**
* Sets the element (i,j) to point to m.
* Note that this method doesn't make a copy of m, but points directly to m.
* This is better in case you don't need that map anymore, so that your
* TMatrix object manages it from now on.
* If you want to keep your map object (for example, because it's already
* managed by another TMatrix object) you can use m->copy() instead of m
*/
virtual void set(unsigned int i, unsigned int j, Map *m);
/**
* Sets the column j to point to the elements in the column vj of v.
* This method just "reparents" the elements of v to this object.
* If you don't want to do that (but using a copy of v
*
*/
virtual void setCol(unsigned int j, TMatrix *v, unsigned int vj, bool managev=false);
virtual void setRow(unsigned int i, TMatrix *v, unsigned int vi, bool managev=false);
virtual Map *at(unsigned int i, unsigned int j) const;
virtual Map *at(unsigned int i) const;
virtual T *t(unsigned int i) const;
virtual T *t(unsigned int i, unsigned int j) const;
virtual T &tRef(unsigned int i) const;
virtual T &tRef(unsigned int i, unsigned int j) const;
/**
* Returns a copy of the submatrix given by the elements from i0,j0 to i1,j1
* (both included)
*/
virtual TMatrix *submatrix(unsigned int i0,unsigned int j0, unsigned i1, unsigned int j1) const;
/**
* Returns a copy of the j-th column
*/
TMatrix *column(unsigned int j) const;
/**
* Returns a copy of the i-th row
*/
TMatrix *row(unsigned int i) const;
bool isAutoExpandable(void) const { return m_autoExpand; };
void setAutoExpand(bool b);
virtual inline int operator==( TMatrix v1 ) const;
virtual inline int operator==( double v1 ) const;
virtual inline int operator!=( TMatrix v1 ) const;
virtual inline int operator!=( double v1 ) const;
virtual inline int operator<( TMatrix v1 ) const;
virtual inline int operator<( double v1 ) const;
virtual inline int operator>( TMatrix v1 ) const;
virtual inline int operator>( double v1 ) const;
virtual inline int operator>=( TMatrix v1 ) const;
virtual inline int operator>=( double v1 ) const;
virtual inline int operator<=( TMatrix v1 ) const;
virtual inline int operator<=( double v1 ) const;
TMatrix &operator=( const TMatrix &x );
TMatrix &operator=( double &x );
virtual TMatrix &operator+=( const TMatrix &x );
virtual TMatrix &operator-=( const TMatrix &x );
virtual TMatrix &operator*=( const TMatrix &x );
virtual TMatrix &operator/=( const TMatrix &x );
/* virtual inline TMatrix *operator+( const T *v1 );
virtual inline TMatrix *operator-( const T *v1 );
virtual inline TMatrix *operator*( const T *v1 );
friend inline TMatrix *operator*( const T &v1, const TMatrix *m);
virtual inline TMatrix *operator/( const T *v1 );
*/
void traspose(void);
static T *distMax(TMatrix *v,TMatrix *w);
// static T *dist;
static T &distMaxCol(TMatrix *v, unsigned int c1,
TMatrix *w, unsigned int c2);
static TMatrix *add(TMatrix *&m1, TMatrix *&m2,
bool managem1=false, bool managem2=false);
static TMatrix *sub(TMatrix *&m1, TMatrix *&m2,
bool managem1=false, bool managem2=false);
static TMatrix *mul(TMatrix *&m1, TMatrix *&m2,
bool managem1=false, bool managem2=false);
static TMatrix *mul(T *&c1, TMatrix *&m2,
bool managem1=false, bool managem2=false);
static TMatrix *div(TMatrix *&m1, TMatrix *&m2,
bool managem1=false, bool managem2=false);
static TMatrix *pow(TMatrix *&m1, T *&c2,
bool managem1=false, bool managem2=false);
operator const double () const { return 0; };
virtual QString string(void) const;
virtual QString htmlString(void) const;
virtual const char *isA() const { return "TMatrix"; };
virtual bool isA(const char *str) const { return strlen(str)==7; };
virtual void load(const QString &file);
};
inline TMatrix operator+( const TMatrix &v1, const TMatrix &v2 )
{
TMatrix tmp( v1 );
tmp+=v2;
return tmp;
}
inline TMatrix operator-( const TMatrix &v1, const TMatrix &v2 )
{
TMatrix tmp( v1 );
tmp-=v2;
return tmp;
}
inline TMatrix operator*( const TMatrix &v1, const TMatrix &v2 )
{
TMatrix tmp( v1 );
tmp*=v2;
return tmp;
}
inline TMatrix operator/( const TMatrix &v1, const TMatrix &v2 )
{
TMatrix tmp( v1 );
tmp/=v2;
return tmp;
}
#endif
Generated by: antonio@tazend on Fri May 25 22:16:00 2001, using kdoc 2.0a38. |