gmc.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_COMPLEX_H_
00042 #define _LA_GEN_MAT_COMPLEX_H_
00043 
00044 #ifndef LA_COMPLEX_SUPPORT
00045 /* An application must define LA_COMPLEX_SUPPORT if it wants to use
00046  * complex numbers here. */
00047 # error "The macro LA_COMPLEX_SUPPORT needs to be defined if you want to use complex-valued matrices."
00048 #endif
00049 
00050 #include "arch.h"
00051 #include "lafnames.h"
00052 #include VECTOR_COMPLEX_H
00053 #include LA_INDEX_H
00054 #include LA_GEN_MAT_DOUBLE_H
00055 
00056 class LaGenMatComplex;
00057 class LaGenMatDouble;
00058 class LaGenMatFloat;
00059 class LaGenMatInt;
00060 class LaGenMatLongInt;
00061 
00088 class DLLIMPORT LaGenMatComplex
00089 {
00090    public:
00092       typedef COMPLEX value_type;
00096       typedef LaGenMatComplex matrix_type;
00099       typedef VectorComplex vec_type;
00100    private:
00101       vec_type     v;
00102       LaIndex           ii[2];
00103       int             dim[2];  // size of original matrix, not submatrix
00104       //int             sz[2];   // size of this submatrix
00105       void init(int m, int n);
00106       int size0;
00107       int size1;
00108       static int  debug_; // trace all entry and exits into methods and 
00109       // operators of this class.  This variable is
00110       // explicitly initalized in lagenmatCOMPLEX.cc
00111 
00112       static int      *info_;   // print matrix info only, not values
00113       //   originally 0, set to 1, and then
00114       //   reset to 0 after use.
00115       // use as in
00116       //
00117       //    std::cout << B.info() << std::endl;
00118       //
00119       // this *info_ member is unique in that it really isn't
00120       // part of the matrix info, just a flag as to how
00121       // to print it.   We've included in this beta release
00122       // as part of our testing, but we do not expect it 
00123       // to be user accessable.
00124       // It has to be declared as global static
00125       // so that we may monitor expresssions like
00126       // X::(const &X) and still utilize without violating
00127       // the "const" condition.
00128       // Because this *info_ is used at most one at a time,
00129       // there is no harm in keeping only one copy of it,
00130       // also, we do not need to malloc free space every time
00131       // we call a matrix constructor.
00132 
00133 
00134       int shallow_; // set flag to '0' in order to return matrices
00135                     // by value from functions without unecessary
00136                     // copying.
00137 
00138 
00139       // users shouldn't be able to modify assignment semantics..
00140       //
00141       //LaGenMatComplex& shallow_assign();
00142 
00143    public:
00144 
00145 
00148       /*::::::::::::::::::::::::::*/
00149       /* Constructors/Destructors */
00150       /*::::::::::::::::::::::::::*/
00151 
00153       LaGenMatComplex();
00154 
00157       LaGenMatComplex(int m, int n);
00158 
00195       LaGenMatComplex(COMPLEX*v, int m, int n, bool row_ordering=false);
00196 
00219       LaGenMatComplex(const LaGenMatComplex&);
00220 
00225       explicit LaGenMatComplex(const LaGenMatDouble& s_real, 
00226                       const LaGenMatDouble& s_imag = LaGenMatDouble());
00227 
00231       LaGenMatComplex& resize(int m, int n);
00232 
00236       LaGenMatComplex& resize(const LaGenMatComplex& s);
00237 
00240       virtual ~LaGenMatComplex();
00242 
00243 
00248       bool is_zero() const;
00249 
00252       bool is_submatrixview() const
00253       { return size(0) != gdim(0) || size(1) != gdim(1); };
00254 
00259       bool has_unitstride() const
00260       { return inc(0) == 1 && inc(1) == 1; };
00261 
00264       bool equal_to(const LaGenMatComplex& mat) const;
00266 
00267 
00270       /*::::::::::::::::::::::::::::::::*/
00271       /*  Indices and access operations */
00272       /*::::::::::::::::::::::::::::::::*/
00273 
00276       inline int size(int d) const;   // submatrix size
00279       inline int cols() const { return size(1); }
00282       inline int rows() const { return size(0); }
00283 
00289       inline int inc(int d) const;    // explicit increment
00290 
00295       inline int gdim(int d) const;   // global dimensions
00296 
00301       inline int start(int d) const;  // return ii[d].start()
00302 
00307       inline int end(int d) const;    // return ii[d].end()
00308 
00313       inline LaIndex index(int d) const;// index
00314 
00318       inline int ref_count() const;
00319 
00322       inline COMPLEX* addr() const;       // begining addr of data space
00324 
00341       inline COMPLEX& operator()(int i, int j);
00342 
00357       inline COMPLEX& operator()(int i, int j) const;
00358 
00370       LaGenMatComplex operator()(const LaIndex& I, const LaIndex& J) ;
00371 
00383       LaGenMatComplex operator()(const LaIndex& I, const LaIndex& J) const;
00384 
00391       LaGenMatComplex row(int k);
00398       LaGenMatComplex row(int k) const;
00405       LaGenMatComplex col(int k);
00412       LaGenMatComplex col(int k) const;
00414 
00421       LaGenMatComplex& operator=(COMPLEX s);
00422 
00423       // CS: addition
00428       LaGenMatComplex& operator=(const LaComplex& s);
00429 
00430       /* Set elements of left-hand size to the scalar value s. No
00431        * new matrix is created, so that if there are other matrices
00432        * that reference this memory space, they will also be
00433        * affected. */
00434       //LaGenMatComplex& operator=(const std::complex<double>& s);
00435       // CS: end
00436 
00472       LaGenMatComplex& operator=(const LaGenMatComplex& s); //copy
00473 
00482       LaGenMatComplex& operator+=(COMPLEX s);
00483 
00488       LaGenMatComplex& add(COMPLEX s);
00489 
00494       LaGenMatComplex& scale(const LaComplex& s);
00495 
00500       LaGenMatComplex& scale(COMPLEX s);
00501 
00506       LaGenMatComplex& operator*=(COMPLEX s);
00507 
00516       LaGenMatComplex& inject(const LaGenMatComplex& s);
00517 
00522       LaGenMatComplex& copy(const LaGenMatComplex& s);
00523 
00528       LaGenMatComplex copy() const;
00529 
00537       LaGenMatComplex& copy(const LaGenMatDouble& s_real, 
00538                             const LaGenMatDouble& s_imag = LaGenMatDouble());
00539 
00544       inline LaGenMatComplex& shallow_assign();
00545 
00553       LaGenMatComplex& ref(const LaGenMatComplex& s);
00555 
00561       LaGenMatComplex repmat (int M, int N) const;
00564       value_type trace () const;
00568       LaGenMatComplex diag () const;
00569 
00574       LaGenMatDouble real() const;
00575 
00580       LaGenMatDouble imag() const;
00582 
00583 
00587       inline int shallow() const      // read global shallow flag
00588       { return shallow_;}
00590       inline int debug() const;       // read global debug flag
00592       inline int debug(int d);        // set global debug flag
00593 
00605       inline const LaGenMatComplex& info() const { 
00606          *(const_cast<LaGenMatComplex*>(this)->info_) = 1; 
00607          return *this; 
00608       };
00609 
00612       inline std::ostream& Info(std::ostream& s) const
00613       {
00614          s << "Size: (" << size(0) << "x" << size(1) << ") " ;
00615          s << "Indeces: " << ii[0] << " " << ii[1];
00616          s << "#ref: " << ref_count() << "addr: " << addr() << std::endl;
00617          return s;
00618       };
00620 
00627       friend DLLIMPORT std::ostream& operator<<(std::ostream&, const LaGenMatComplex&);
00628 
00633       LaGenMatDouble real_to_LaGenMatDouble() const;
00636       LaGenMatFloat real_to_LaGenMatFloat() const;
00638       LaGenMatInt real_to_LaGenMatInt() const;
00641       LaGenMatLongInt real_to_LaGenMatLongInt() const;
00644       LaGenMatDouble imag_to_LaGenMatDouble() const;
00647       LaGenMatFloat imag_to_LaGenMatFloat() const;
00650       LaGenMatInt imag_to_LaGenMatInt() const;
00653       LaGenMatLongInt imag_to_LaGenMatLongInt() const;
00655 
00656 
00662       static LaGenMatComplex zeros (int N, int M=0);
00666       static LaGenMatComplex ones (int N, int M=0);
00670       static LaGenMatComplex eye (int N, int M=0);
00680       static LaGenMatComplex rand (int N, int M,
00681                                double low=0, double high=1);
00685       static LaGenMatComplex from_diag (const LaGenMatComplex &vect);
00689       static LaGenMatComplex linspace (value_type start, 
00690                                    value_type end,
00691                                    int nr_points);
00693 
00694 };  //* End of LaGenMatComplex Class *//
00695 
00696 
00697 
00698 namespace la {
00701    typedef LaGenMatComplex cmat;
00702 } // namespace
00703 
00711 DLLIMPORT
00712 std::ostream& operator<<(std::ostream&, const LaGenMatComplex&);
00713 
00714 
00715     //* Member Functions *//
00716 
00717 
00718  
00719 inline int LaGenMatComplex::size(int d) const
00720 {
00721    if (d==0)
00722       return size0;
00723    else
00724       return size1;
00725    //return sz[d];
00726 }
00727 
00728 inline int LaGenMatComplex::inc(int d) const
00729 {
00730    return ii[d].inc();
00731 }
00732 
00733 inline int LaGenMatComplex::gdim(int d) const
00734 {
00735    return dim[d];
00736 }
00737 
00738 inline int LaGenMatComplex::start(int d) const
00739 {
00740    return ii[d].start();
00741 }
00742 
00743 inline int LaGenMatComplex::end(int d) const
00744 {
00745    return ii[d].end();
00746 }
00747 
00748 inline int LaGenMatComplex::ref_count() const
00749 {
00750    return v.ref_count();
00751 }
00752 
00753 
00754 inline LaIndex LaGenMatComplex::index(int d)  const
00755 {
00756    return ii[d];
00757 }
00758 
00759 inline COMPLEX* LaGenMatComplex::addr() const
00760 {
00761    return  v.addr();
00762 }
00763 
00764 inline int LaGenMatComplex::debug() const
00765 {
00766    return debug_;
00767 }
00768 
00769 inline int LaGenMatComplex::debug(int d)
00770 {
00771    return debug_ = d;
00772 }
00773 
00774 inline COMPLEX& LaGenMatComplex::operator()(int i, int j)
00775 {
00776 
00777 #ifdef LA_BOUNDS_CHECK
00778    assert(i>=0);
00779    assert(i<size(0));
00780    assert(j>=0);
00781    assert(j<size(1));
00782 #endif
00783    return v( dim[0]*(ii[1].start() + j*ii[1].inc()) + 
00784              ii[0].start() + i*ii[0].inc());
00785 }
00786 
00787 inline COMPLEX& LaGenMatComplex::operator()(int i, int j) const
00788 {
00789 
00790 #ifdef LA_BOUNDS_CHECK
00791    assert(i>=0);
00792    assert(i<size(0));
00793    assert(j>=0);
00794    assert(j<size(1));
00795 #endif
00796 
00797    return v( dim[0]*(ii[1].start() + j*ii[1].inc()) + 
00798              ii[0].start() + i*ii[0].inc());
00799 }
00800 
00801 
00802 
00803 
00804 inline  LaGenMatComplex&  LaGenMatComplex::shallow_assign()
00805 {
00806    shallow_ = 1;
00807    return *this;
00808 }
00809 
00810 
00811 
00812 #ifndef LA_COMPLEX_SUPPORT
00813 // Repeat this warning again
00814 # error "The macro LA_COMPLEX_SUPPORT needs to be defined if you want to use complex-valued matrices."
00815 #endif
00816 
00817 
00818 #endif 
00819 // _LA_GEN_MAT_H_

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