gmli.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_LONG_INT_H_
00042 #define _LA_GEN_MAT_LONG_INT_H_
00043 
00044 #include "arch.h"
00045 #include "lafnames.h"
00046 #include VECTOR_LONG_INT_H
00047 #include LA_INDEX_H
00048 
00049 class LaGenMatComplex;
00050 class LaGenMatDouble;
00051 class LaGenMatFloat;
00052 class LaGenMatInt;
00053 class LaGenMatLongInt;
00054 
00055 
00071 class DLLIMPORT LaGenMatLongInt
00072 {
00073    public:
00075       typedef long int value_type;
00079       typedef LaGenMatLongInt matrix_type;
00082       typedef VectorLongInt vec_type;
00083    private:
00084       vec_type     v;
00085       LaIndex           ii[2];
00086       int             dim[2];  // size of original matrix, not submatrix
00087       int             sz[2];   // size of this submatrix
00088       void init(int m, int n);
00089       static int  debug_; // trace all entry and exits into methods and 
00090       // operators of this class.  This variable is
00091       // explicitly initalized in gmd.cc
00092 
00093       static int      *info_;   // print matrix info only, not values
00094       //   originally 0, set to 1, and then
00095       //   reset to 0 after use.
00096       // use as in
00097       //
00098       //    std::cout << B.info() << std::endl;
00099       //
00100       // this *info_ member is unique in that it really isn't
00101       // part of the matrix info, just a flag as to how
00102       // to print it.   We've included in this beta release
00103       // as part of our testing, but we do not expect it 
00104       // to be user accessable.
00105       // It has to be declared as global static
00106       // so that we may monitor expresssions like
00107       // X::(const &X) and still utilize without violating
00108       // the "const" condition.
00109       // Because this *info_ is used at most one at a time,
00110       // there is no harm in keeping only one copy of it,
00111       // also, we do not need to malloc free space every time
00112       // we call a matrix constructor.
00113 
00114 
00115       int shallow_; // set flag to '0' in order to return matrices
00116                     // by value from functions without unecessary
00117                     // copying.
00118 
00119 
00120       // users shouldn't be able to modify assignment semantics..
00121       //
00122       //LaGenMatLongInt& shallow_assign();
00123 
00124    public:
00125 
00126 
00129       /*::::::::::::::::::::::::::*/
00130       /* Constructors/Destructors */
00131       /*::::::::::::::::::::::::::*/
00132       
00134       LaGenMatLongInt();
00135 
00138       LaGenMatLongInt(int m, int n);
00139 
00176       LaGenMatLongInt(long int* v, int m, int n, bool row_ordering=false);
00177 
00200       LaGenMatLongInt(const LaGenMatLongInt&);
00201 
00205       LaGenMatLongInt& resize(int m, int n);
00206 
00210       LaGenMatLongInt& resize(const LaGenMatLongInt& s);
00211 
00214       virtual ~LaGenMatLongInt();
00215 
00216 
00221       bool is_zero() const;
00222 
00225       bool is_submatrixview() const
00226       { return size(0) != gdim(0) || size(1) != gdim(1); };
00227 
00232       bool has_unitstride() const
00233       { return inc(0) == 1 && inc(1) == 1; };
00234 
00237       bool equal_to(const matrix_type& mat) const;
00239 
00240 
00243       /*::::::::::::::::::::::::::::::::*/
00244       /*  Indices and access operations */
00245       /*::::::::::::::::::::::::::::::::*/
00246 
00249       inline int size(int d) const;   // submatrix size
00252       inline int cols() const { return size(1); }
00255       inline int rows() const { return size(0); }
00256 
00262       inline int inc(int d) const;    // explicit increment
00263 
00268       inline int gdim(int d) const;   // global dimensions
00269 
00274       inline int start(int d) const;  // return ii[d].start()
00275 
00280       inline int end(int d) const;    // return ii[d].end()
00281 
00286       inline LaIndex index(int d) const;// index
00287 
00291       inline int ref_count() const;
00292 
00295       inline long int* addr() const;       // begining addr of data space
00297 
00300     
00315       inline long int& operator()(int i, int j);
00316 
00331       inline long int& operator()(int i, int j) const;
00332 
00344       LaGenMatLongInt operator()(const LaIndex& I, const LaIndex& J) ;
00345 
00357       LaGenMatLongInt operator()(const LaIndex& I, const LaIndex& J) const;
00358 
00365       LaGenMatLongInt row(int k);
00372       LaGenMatLongInt row(int k) const;
00379       LaGenMatLongInt col(int k);
00386       LaGenMatLongInt col(int k) const;
00388 
00395       LaGenMatLongInt& operator=(long int s);
00396 
00432       LaGenMatLongInt& operator=(const LaGenMatLongInt& s); //copy
00433 
00438       LaGenMatLongInt& operator+=(long int s);
00439 
00444       LaGenMatLongInt& add(long int s);
00445 
00454       LaGenMatLongInt& inject(const LaGenMatLongInt& s);
00455 
00460       LaGenMatLongInt& copy(const LaGenMatLongInt& s);
00461 
00466       LaGenMatLongInt copy() const;
00467 
00472       inline LaGenMatLongInt& shallow_assign();
00473 
00481       LaGenMatLongInt& ref(const LaGenMatLongInt& s);
00482 
00488       matrix_type repmat (int M, int N) const;
00491       value_type trace () const;
00495       matrix_type diag () const;
00497 
00498 
00502       inline int shallow() const      // read global shallow flag
00503       { return shallow_;}
00505       inline int debug() const;       // read global debug flag
00507       inline int debug(int d);        // set global debug flag
00519       inline const LaGenMatLongInt& info() const { 
00520          *(const_cast<LaGenMatLongInt*>(this)->info_) = 1; 
00521          return *this;};
00524       inline std::ostream& Info(std::ostream& s) const
00525       {
00526          s << "Size: (" << size(0) << "x" << size(1) << ") " ;
00527          s << "Indeces: " << ii[0] << " " << ii[1];
00528          s << "#ref: " << ref_count() << "addr: " << addr() << std::endl;
00529          return s;
00530       };
00532 
00536       friend DLLIMPORT std::ostream& operator<<(std::ostream&, const LaGenMatLongInt&);
00537 
00541       LaGenMatComplex to_LaGenMatComplex() const;
00543       LaGenMatDouble to_LaGenMatDouble() const;
00545       LaGenMatFloat to_LaGenMatFloat() const;
00547       LaGenMatInt to_LaGenMatInt() const;
00549 
00550 
00556       static matrix_type zeros (int N, int M=0);
00560       static matrix_type ones (int N, int M=0);
00564       static matrix_type eye (int N, int M=0);
00573       static matrix_type rand (int N, int M,
00574                                value_type low=0, value_type high=1);
00578       static matrix_type from_diag (const matrix_type &vect);
00582       static matrix_type linspace (value_type start, value_type end,
00583                                    int nr_points);
00585 
00586 };  //* End of LaGenMatLongInt Class *//
00587 
00588 
00589 namespace la {
00591    typedef LaGenMatLongInt limat;
00592 } // namespace
00593 
00601 DLLIMPORT
00602 std::ostream& operator<<(std::ostream&, const LaGenMatLongInt&);
00603 
00604         
00605 
00606     //* Member Functions *//
00607 
00608 
00609  
00610 inline int LaGenMatLongInt::size(int d) const
00611 {
00612    return sz[d];
00613 }
00614 
00615 inline int LaGenMatLongInt::inc(int d) const
00616 {
00617    return ii[d].inc();
00618 }
00619 
00620 inline int LaGenMatLongInt::gdim(int d) const
00621 {
00622    return dim[d];
00623 }
00624 
00625 inline int LaGenMatLongInt::start(int d) const
00626 {
00627    return ii[d].start();
00628 }
00629 
00630 inline int LaGenMatLongInt::end(int d) const
00631 {
00632    return ii[d].end();
00633 }
00634 
00635 inline int LaGenMatLongInt::ref_count() const
00636 {
00637    return v.ref_count();
00638 }
00639 
00640 
00641 inline LaIndex LaGenMatLongInt::index(int d)  const
00642 {
00643    return ii[d];
00644 }
00645 
00646 inline long int* LaGenMatLongInt::addr() const
00647 {
00648    return  v.addr();
00649 }
00650 
00651 inline int LaGenMatLongInt::debug() const
00652 {
00653    return debug_;
00654 }
00655 
00656 inline int LaGenMatLongInt::debug(int d)
00657 {
00658    return debug_ = d;
00659 }
00660 
00661 inline long int& LaGenMatLongInt::operator()(int i, int j)
00662 {
00663 
00664 #ifdef LA_BOUNDS_CHECK
00665    assert(i>=0);
00666    assert(i<size(0));
00667    assert(j>=0);
00668    assert(j<size(1));
00669 #endif
00670    return v( dim[0]*(ii[1].start() + j*ii[1].inc()) + 
00671              ii[0].start() + i*ii[0].inc());
00672 }
00673 
00674 inline long int& LaGenMatLongInt::operator()(int i, int j) const
00675 {
00676 
00677 #ifdef LA_BOUNDS_CHECK
00678    assert(i>=0);
00679    assert(i<size(0));
00680    assert(j>=0);
00681    assert(j<size(1));
00682 #endif
00683 
00684    return v( dim[0]*(ii[1].start() + j*ii[1].inc()) + 
00685              ii[0].start() + i*ii[0].inc());
00686 }
00687 
00688 
00689 
00690 
00691 inline  LaGenMatLongInt&  LaGenMatLongInt::shallow_assign()
00692 {
00693    shallow_ = 1;
00694    return *this;
00695 }
00696 
00697 
00698 
00699 
00700 
00701 #endif 
00702 // _LA_GEN_MAT_H_

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