Source: kalamaris/tmatrix.h


Annotated List
Files
Globals
Hierarchy
Index
/*  tmatrix.h - 
    This file is part of Kalamaris
    Copyright (C) 2000  Antonio Larrosa Jimenez
    Kalamaris' homepage : http://www.arrakis.es/~rlarrosa/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, unsigned int _cdim, 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;

  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: antlarr@terminus on Mon Jun 5 03:54:02 2000, using kdoc 2.0a22.