gmf.h

Go to the documentation of this file.
00001 // -*-C++-*- 
00002 
00003 // Copyright (C) 2004 
00004 // Christian Stimming <stimming@tuhh.de>
00005 
00006 // Row-order modifications by Jacob (Jack) Gryn <jgryn at cs dot yorku dot ca>
00007 
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Lesser General Public License as
00010 // published by the Free Software Foundation; either version 2, or (at
00011 // your option) any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU Lesser General Public License for more details.
00017 
00018 // You should have received a copy of the GNU Lesser General Public License along
00019 // with this library; see the file COPYING.  If not, write to the Free
00020 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00021 // USA.
00022 
00027 //      LAPACK++ (V. 1.1)
00028 //      (C) 1992-1996 All Rights Reserved.
00029 //
00030 //      Lapack++ Rectangular Matrix Class
00031 //
00032 //      Dense (nonsingular) matrix, assumes no special structure or properties.
00033 //
00034 //      ) allows 2-d indexing
00035 //      ) non-unit strides
00036 //      ) deep (copy) assignment
00037 //      ) std::cout << A.info()  prints out internal states of A
00038 //      ) indexing via A(i,j) where i,j are either integers or
00039 //              LaIndex         
00040 
00041 #ifndef _LA_GEN_MAT_FLOAT_H_
00042 #define _LA_GEN_MAT_FLOAT_H_
00043 
00044 #include "arch.h"
00045 #include "lafnames.h"
00046 #include VECTOR_FLOAT_H
00047 #include LA_INDEX_H
00048 
00049 class LaGenMatComplex;
00050 class LaGenMatDouble;
00051 class LaGenMatFloat;
00052 class LaGenMatInt;
00053 class LaGenMatLongInt;
00054 
00055 
00056 class DLLIMPORT LaGenMatFloat
00057 {
00058    public:
00060       typedef float value_type;
00064       typedef LaGenMatFloat matrix_type;
00067       typedef VectorFloat vec_type;
00068    private:
00069     vec_type     v;
00070     LaIndex         ii[2];
00071     int             dim[2];  // size of original matrix, not submatrix
00072     int             sz[2];   // size of this submatrix
00073     void init(int m, int n);
00074     static int  debug_; // trace all entry and exits into methods and 
00075                         // operators of this class.  This variable is
00076                         // explicitly initalized in lagenmatfloat.cc
00077 
00078     static int      *info_;   // print matrix info only, not values
00079                              //   originally 0, set to 1, and then
00080                              //   reset to 0 after use.
00081                 // use as in
00082                 //
00083                 //    std::cout << B.info() << std::endl;
00084                 //
00085                 // this *info_ member is unique in that it really isn't
00086                 // part of the matrix info, just a flag as to how
00087                 // to print it.   We've included in this beta release
00088                 // as part of our testing, but we do not expect it 
00089                 // to be user accessable.
00090                 // It has to be declared as global static
00091                 // so that we may monitor expresssions like
00092                 // X::(const &X) and still utilize without violating
00093                 // the "const" condition.
00094                 // Because this *info_ is used at most one at a time,
00095                 // there is no harm in keeping only one copy of it,
00096                 // also, we do not need to malloc free space every time
00097                 // we call a matrix constructor.
00098 
00099 
00100     int shallow_; // set flag to '0' in order to return matrices
00101                     // by value from functions without unecessary
00102                     // copying.
00103 
00104 
00105     // users shouldn't be able to modify assignment semantics..
00106     //
00107     //LaGenMatFloat& shallow_assign();
00108 
00109 public:
00110 
00111 
00112 
00113         /*::::::::::::::::::::::::::*/
00114 
00115         /* Constructors/Destructors */
00116 
00117         /*::::::::::::::::::::::::::*/
00118 
00119 
00120         LaGenMatFloat();
00121         LaGenMatFloat(int, int);
00122 
00159         LaGenMatFloat(float* v, int m, int n, bool row_ordering=false);
00160 
00183         LaGenMatFloat(const LaGenMatFloat&);
00184     virtual ~LaGenMatFloat();
00185 
00186 
00191       bool is_zero() const;
00192 
00195       bool is_submatrixview() const
00196       { return size(0) != gdim(0) || size(1) != gdim(1); };
00197 
00202       bool has_unitstride() const
00203       { return inc(0) == 1 && inc(1) == 1; };
00204 
00207       bool equal_to(const matrix_type& mat) const;
00209 
00210 
00211         /*::::::::::::::::::::::::::::::::*/
00212 
00213         /*  Indices and access operations */
00214 
00215         /*::::::::::::::::::::::::::::::::*/
00216 
00217     inline int size(int d) const;   // submatrix size
00220       inline int cols() const { return size(1); }
00223       inline int rows() const { return size(0); }
00224     inline int inc(int d) const;    // explicit increment
00225     inline int gdim(int d) const;   // global dimensions
00226     inline int start(int d) const;  // return ii[d].start()
00227     inline int end(int d) const;    // return ii[d].end()
00228     inline LaIndex index(int d) const;// index
00229     inline int ref_count() const;
00230     inline LaGenMatFloat& shallow_assign();
00231     inline float* addr() const;       // begining addr of data space
00232     
00233     inline float& operator()(int i, int j);
00234     inline float& operator()(int i, int j) const;
00235     LaGenMatFloat operator()(const LaIndex& I, const LaIndex& J) ;
00236     LaGenMatFloat operator()(const LaIndex& I, const LaIndex& J) const;
00243       LaGenMatFloat row(int k);
00250       LaGenMatFloat row(int k) const;
00257       LaGenMatFloat col(int k);
00264       LaGenMatFloat col(int k) const;
00265 
00266             LaGenMatFloat& operator=(float s);
00302     LaGenMatFloat& operator=(const LaGenMatFloat& s); //copy
00303 
00304     LaGenMatFloat& operator+=(float s);
00305     LaGenMatFloat& add(float s);
00306 
00307     LaGenMatFloat& resize(int m, int n);
00308     LaGenMatFloat& resize(const LaGenMatFloat& s);
00309     LaGenMatFloat& ref(const LaGenMatFloat& s);
00310     LaGenMatFloat& inject(const LaGenMatFloat& s);
00311     LaGenMatFloat& copy(const LaGenMatFloat& s);
00312 
00317       LaGenMatFloat copy() const;
00318 
00324       matrix_type repmat (int M, int N) const;
00327       value_type trace () const;
00331       matrix_type diag () const;
00333 
00334 
00335     inline int shallow() const      // read global shallow flag
00336         { return shallow_;}
00337     inline int debug() const;       // read global debug flag
00338     inline int debug(int d);        // set global debug flag
00339     inline const LaGenMatFloat& info() const { 
00340             int *t = info_; 
00341             *t = 1; 
00342             return *this;};
00343 
00344     //* I/O *//
00345     friend DLLIMPORT std::ostream& operator<<(std::ostream&, const LaGenMatFloat&);
00346     std::ostream& Info(std::ostream& s) const
00347     {
00348         s << "Size: (" << size(0) << "x" << size(1) << ") " ;
00349         s << "Indeces: " << ii[0] << " " << ii[1];
00350         s << "#ref: " << ref_count() << "addr: " << addr() << std::endl;
00351         return s;
00352     };
00353 
00357       LaGenMatComplex to_LaGenMatComplex() const;
00359       LaGenMatDouble to_LaGenMatDouble() const;
00361       LaGenMatInt to_LaGenMatInt() const;
00363       LaGenMatLongInt to_LaGenMatLongInt() const;
00365 
00366 
00372       static matrix_type zeros (int N, int M=0);
00376       static matrix_type ones (int N, int M=0);
00380       static matrix_type eye (int N, int M=0);
00389       static matrix_type rand (int N, int M,
00390                                value_type low=0, value_type high=1);
00394       static matrix_type from_diag (const matrix_type &vect);
00398       static matrix_type linspace (value_type start, value_type end,
00399                                    int nr_points);
00401 
00402 };  //* End of LaGenMatFloat Class *//
00403 
00404 
00405 namespace la {
00408    typedef LaGenMatFloat fmat;
00409 } // namespace
00410 
00418 DLLIMPORT
00419 std::ostream& operator<<(std::ostream&, const LaGenMatFloat&);
00420 
00421         
00422 
00423     //* Member Functions *//
00424 
00425 
00426  
00427 inline int LaGenMatFloat::size(int d) const
00428 {
00429     return sz[d];
00430 }
00431 
00432 inline int LaGenMatFloat::inc(int d) const
00433 {
00434     return ii[d].inc();
00435 }
00436 
00437 inline int LaGenMatFloat::gdim(int d) const
00438 {
00439     return dim[d];
00440 }
00441 
00442 inline int LaGenMatFloat::start(int d) const
00443 {
00444     return ii[d].start();
00445 }
00446 
00447 inline int LaGenMatFloat::end(int d) const
00448 {
00449     return ii[d].end();
00450 }
00451 
00452 inline int LaGenMatFloat::ref_count() const
00453 {
00454     return v.ref_count();
00455 }
00456 
00457 
00458 inline LaIndex LaGenMatFloat::index(int d)  const
00459 {
00460     return ii[d];
00461 }
00462 
00463 inline float* LaGenMatFloat::addr() const
00464 {
00465     return  v.addr();
00466 }
00467 
00468 inline int LaGenMatFloat::debug() const
00469 {
00470     return debug_;
00471 }
00472 
00473 inline int LaGenMatFloat::debug(int d)
00474 {
00475     return debug_ = d;
00476 }
00477 
00478 inline float& LaGenMatFloat::operator()(int i, int j)
00479 {
00480 
00481 #ifdef LA_BOUNDS_CHECK
00482     assert(i>=0);
00483     assert(i<size(0));
00484     assert(j>=0);
00485     assert(j<size(1));
00486 #endif
00487     return v( dim[0]*(ii[1].start() + j*ii[1].inc()) + 
00488                 ii[0].start() + i*ii[0].inc());
00489 }
00490 
00491 inline float& LaGenMatFloat::operator()(int i, int j) const
00492 {
00493 
00494 #ifdef LA_BOUNDS_CHECK
00495     assert(i>=0);
00496     assert(i<size(0));
00497     assert(j>=0);
00498     assert(j<size(1));
00499 #endif
00500 
00501     return v( dim[0]*(ii[1].start() + j*ii[1].inc()) + 
00502                 ii[0].start() + i*ii[0].inc());
00503 }
00504 
00505 
00506 
00507 
00508 inline  LaGenMatFloat&  LaGenMatFloat::shallow_assign()
00509 {
00510     shallow_ = 1;
00511     return *this;
00512 }
00513 
00514 
00515 
00516 
00517 
00518 #endif 
00519 // _LA_GEN_MAT_H_

Generated on Sat Jul 14 11:40:36 2007 for Lapack++ by  doxygen 1.5.0