gmd.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.0a Beta)
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 //      ) inject 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_DOUBLE_H_
00042 #define _LA_GEN_MAT_DOUBLE_H_
00043 
00044 #include "arch.h"
00045 #include "lafnames.h"
00046 #include VECTOR_DOUBLE_H
00047 #include LA_INDEX_H
00048 #include LA_GEN_MAT_FLOAT_H
00049 
00050 class LaGenMatComplex;
00051 class LaGenMatDouble;
00052 class LaGenMatFloat;
00053 class LaGenMatInt;
00054 class LaGenMatLongInt;
00055 
00078 class DLLIMPORT LaGenMatDouble
00079 {
00080    public:
00082       typedef double value_type;
00086       typedef LaGenMatDouble matrix_type;
00089       typedef VectorDouble vec_type;
00090    private:
00091       vec_type     v;
00092       LaIndex           ii[2];
00093       int             dim[2];  // size of original matrix, not submatrix
00094       int             sz[2];   // size of this submatrix
00095       void init(int m, int n);
00096       static int  debug_; // trace all entry and exits into methods and 
00097       // operators of this class.  This variable is
00098       // explicitly initalized in gmd.cc
00099 
00100       static int      *info_;   // print matrix info only, not values
00101       //   originally 0, set to 1, and then
00102       //   reset to 0 after use.
00103       // use as in
00104       //
00105       //    std::cout << B.info() << std::endl;
00106       //
00107       // this *info_ member is unique in that it really isn't
00108       // part of the matrix info, just a flag as to how
00109       // to print it.   We've included in this beta release
00110       // as part of our testing, but we do not expect it 
00111       // to be user accessable.
00112       // It has to be declared as global static
00113       // so that we may monitor expresssions like
00114       // X::(const &X) and still utilize without violating
00115       // the "const" condition.
00116       // Because this *info_ is used at most one at a time,
00117       // there is no harm in keeping only one copy of it,
00118       // also, we do not need to malloc free space every time
00119       // we call a matrix constructor.
00120 
00121 
00122       int shallow_; // set flag to '0' in order to return matrices
00123                     // by value from functions without unecessary
00124                     // copying.
00125 
00126 
00127       // users shouldn't be able to modify assignment semantics..
00128       //
00129       //LaGenMatDouble& shallow_assign();
00130 
00131    public:
00132 
00135       /*::::::::::::::::::::::::::*/
00136       /* Constructors/Destructors */
00137       /*::::::::::::::::::::::::::*/
00138 
00140       LaGenMatDouble();
00141 
00144       LaGenMatDouble(int m, int n);
00145 
00182       LaGenMatDouble(double*v, int m, int n, bool row_ordering=false);
00183 
00206       LaGenMatDouble(const LaGenMatDouble&);
00207 
00210       explicit LaGenMatDouble(const LaGenMatFloat&);
00211 
00215       LaGenMatDouble& resize(int m, int n);
00216 
00220       LaGenMatDouble& resize(const LaGenMatDouble& s);
00221 
00224       virtual ~LaGenMatDouble();
00226 
00227 
00232       bool is_zero() const;
00233 
00236       bool is_submatrixview() const
00237       { return size(0) != gdim(0) || size(1) != gdim(1); };
00238 
00243       bool has_unitstride() const
00244       { return inc(0) == 1 && inc(1) == 1; };
00245 
00248       bool equal_to(const LaGenMatDouble& mat) const;
00250 
00251 
00254       /*::::::::::::::::::::::::::::::::*/
00255       /*  Indices and access operations */
00256       /*::::::::::::::::::::::::::::::::*/
00257 
00260       inline int size(int d) const;   // submatrix size
00263       inline int cols() const { return size(1); }
00266       inline int rows() const { return size(0); }
00267 
00273       inline int inc(int d) const;    // explicit increment
00274 
00279       inline int gdim(int d) const;   // global dimensions
00280 
00285       inline int start(int d) const;  // return ii[d].start()
00286 
00291       inline int end(int d) const;    // return ii[d].end()
00292 
00297       inline LaIndex index(int d) const;// index
00298 
00302       inline int ref_count() const;
00303 
00306       inline double* addr() const;       // begining addr of data space
00308 
00325       inline double& operator()(int i, int j);
00326 
00340       inline double& operator()(int i, int j) const;
00341 
00353       LaGenMatDouble operator()(const LaIndex& I, const LaIndex& J) ;
00354 
00366       LaGenMatDouble operator()(const LaIndex& I, const LaIndex& J) const;
00367 
00374       LaGenMatDouble row(int k);
00381       LaGenMatDouble row(int k) const;
00388       LaGenMatDouble col(int k);
00395       LaGenMatDouble col(int k) const;
00397 
00404       LaGenMatDouble& operator=(double s);
00405 
00441       LaGenMatDouble& operator=(const LaGenMatDouble& s);
00442 
00451       LaGenMatDouble& operator+=(double s);
00452 
00457       LaGenMatDouble& add(double s);
00458 
00463       LaGenMatDouble& operator*=(double s);
00464 
00469       LaGenMatDouble& scale(double s);
00470 
00479       LaGenMatDouble& inject(const LaGenMatDouble& s);
00480 
00485       LaGenMatDouble& copy(const LaGenMatDouble& s);
00486 
00491       LaGenMatDouble copy() const;
00492 
00497       inline LaGenMatDouble& shallow_assign();
00498 
00506       LaGenMatDouble& ref(const LaGenMatDouble& s);
00508 
00514       LaGenMatDouble repmat (int M, int N) const;
00517       value_type trace () const;
00521       LaGenMatDouble diag () const;
00523 
00527       inline int shallow() const      // read global shallow flag
00528       { return shallow_;}
00530       inline int debug() const;       // read global debug flag
00532       inline int debug(int d);        // set global debug flag
00544       inline const LaGenMatDouble& info() const { 
00545          *(const_cast<LaGenMatDouble*>(this)->info_) = 1; 
00546          return *this;
00547       };
00548         
00551       inline std::ostream& Info(std::ostream& s) const
00552       {
00553          s << "Size: (" << size(0) << "x" << size(1) << ") " ;
00554          s << "Indeces: " << ii[0] << " " << ii[1];
00555          s << "#ref: " << ref_count() 
00556            << "addr: " << addr() << " shallow:" << shallow_ << std::endl;
00557          return s;
00558       };
00560 
00567       friend DLLIMPORT std::ostream& operator<<(std::ostream&, const LaGenMatDouble&);
00568 
00572       LaGenMatComplex to_LaGenMatComplex() const;
00574       LaGenMatFloat to_LaGenMatFloat() const;
00576       LaGenMatInt to_LaGenMatInt() const;
00578       LaGenMatLongInt to_LaGenMatLongInt() const;
00580 
00581 
00587       static LaGenMatDouble zeros (int N, int M=0);
00591       static LaGenMatDouble ones (int N, int M=0);
00595       static LaGenMatDouble eye (int N, int M=0);
00604       static LaGenMatDouble rand (int N, int M,
00605                                value_type low=0, value_type high=1);
00609       static LaGenMatDouble from_diag (const LaGenMatDouble &vect);
00613       static LaGenMatDouble linspace (value_type start, value_type end,
00614                                    int nr_points);
00616 
00617 };  //* End of LaGenMatDouble Class *//
00618 
00619 namespace la {
00621    typedef LaGenMatDouble mat;
00622 } // namespace
00623 
00631 DLLIMPORT
00632 std::ostream& operator<<(std::ostream&, const LaGenMatDouble&);
00633         
00634 
00635 //* Member Functions *//
00636  
00637 inline int LaGenMatDouble::size(int d) const
00638 {
00639    return sz[d];
00640 }
00641 
00642 inline int LaGenMatDouble::inc(int d) const
00643 {
00644    return ii[d].inc();
00645 }
00646 
00647 inline int LaGenMatDouble::gdim(int d) const
00648 {
00649    return dim[d];
00650 }
00651 
00652 inline int LaGenMatDouble::start(int d) const
00653 {
00654    return ii[d].start();
00655 }
00656 
00657 inline int LaGenMatDouble::end(int d) const
00658 {
00659    return ii[d].end();
00660 }
00661 
00662 inline int LaGenMatDouble::ref_count() const
00663 {
00664    return v.ref_count();
00665 }
00666 
00667 
00668 inline LaIndex LaGenMatDouble::index(int d)  const
00669 {
00670    return ii[d];
00671 }
00672 
00673 inline double* LaGenMatDouble::addr() const
00674 {
00675    return  v.addr();
00676 }
00677 
00678 inline int LaGenMatDouble::debug() const
00679 {
00680    return debug_;
00681 }
00682 
00683 inline int LaGenMatDouble::debug(int d)
00684 {
00685    return debug_ = d;
00686 }
00687 
00688 inline double& LaGenMatDouble::operator()(int i, int j)
00689 {
00690 #ifdef LA_BOUNDS_CHECK
00691    assert(i>=0);
00692    assert(i<size(0));
00693    assert(j>=0);
00694    assert(j<size(1));
00695 #endif
00696    return v( dim[0]*(ii[1].start() + j*ii[1].inc()) + 
00697              ii[0].start() + i*ii[0].inc());
00698 }
00699 
00700 inline double& LaGenMatDouble::operator()(int i, int j) const
00701 {
00702 
00703 #ifdef LA_BOUNDS_CHECK
00704    assert(i>=0);
00705    assert(i<size(0));
00706    assert(j>=0);
00707    assert(j<size(1));
00708 #endif
00709 
00710    return v( dim[0]*(ii[1].start() + j*ii[1].inc()) + 
00711              ii[0].start() + i*ii[0].inc());
00712 }
00713 
00714 inline  LaGenMatDouble&  LaGenMatDouble::shallow_assign()
00715 {
00716    shallow_ = 1;
00717    return *this;
00718 }
00719 
00720 
00721 #endif 
00722 // _LA_GEN_MAT_H_

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