Minor.h

00001 /*
00002  * Expression Template Matrix Library
00003  *
00004  * Copyright (C) 2004 - 2006 Ricky Lung <mtlung@users.sourceforge.net>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 // Forward declaration
00024 template<class Rep, class ExtraTParam> class StaticConstMinorView;
00025 template<class Rep> class DynConstMinorView;
00026 
00028 template<class Rep, class ExtraTParam>
00029 class StaticMinorView : public StaticMinorViewTag
00030 {
00031 public:
00032     typedef StaticMinorView<Rep, ExtraTParam>       self_type;
00033     typedef StaticMinorViewTag                      exp_tag;
00034     typedef ExtraTParam                             extra_param_type;
00035     typedef StaticConstMinorView<Rep, ExtraTParam>  const_view_type;
00036     COMMON_VIEW_TYPEDEFS();
00037 
00038     enum {
00039         MI = ExtraTParam::INT1, // Minor row index
00040         MJ= ExtraTParam::INT2,  // Minor col index
00041         ROWS = super_type::ROWS == 0 ? 0 : super_type::ROWS-1,
00042         COLS = super_type::COLS == 0 ? 0 : super_type::COLS-1,
00043         IsLinear = true,
00044         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00045         ENOP = Rep::ENOP == -1 ? -1 : Rep::ENOP + 2,    // Complexity from the 2 comparisons and 2 additions
00046         TNOP = (ROWS == 0 || COLS == 0) ? -1 : ENOP * ROWS * COLS,
00047         EXPLevel = Rep::EXPLevel + 1
00048     };
00049 
00051     typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00052 
00053     /************************************************/
00054     // Constructors
00055     EXMAT_INLINE2 StaticMinorView(const self_type& self)
00056         : rep(self.rep) {}
00057     EXMAT_INLINE2 StaticMinorView(Rep& mat)
00058         : rep(mat) { ComErrCheck(); }
00060     template<class Rep2> EXMAT_INLINE2
00061     StaticMinorView(const Rep2& self, Rep& mat)
00062         : rep(mat) {
00063         ComErrCheck();
00064     }
00065 
00066     /************************************************/
00067     // Dimension information
00068     EXMAT_INLINE2 size_t size() const { return rows()*cols(); }
00069     EXMAT_INLINE2 size_t rows() const { return rep.rows()-1; }
00070     EXMAT_INLINE2 size_t cols() const { return rep.cols()-1; }
00071     /************************************************/
00072     // Index function (for internal use, no error checking applied)
00073     EXMAT_INLINE2 reference setAt(index_type i)
00074     {   return this->setAt(i/cols(), i%cols()); }
00075     EXMAT_INLINE2 const_reference getAt(index_type i) const
00076     {   return this->getAt(i/cols(), i%cols()); }
00077     EXMAT_INLINE2 reference setAt(index_type i, index_type j)
00078     {   return rep.setAt(i<MI?i:i+1, j<MJ?j:j+1);   }
00079     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00080     {   return rep.getAt(i<MI?i:i+1, j<MJ?j:j+1);   }
00081 
00082 private:
00083     // Compatibility error checking
00084     EXMAT_INLINE2 void ComErrCheck() {
00085         DefaultErrorChecker::AssertCompat(
00086             MI >= 0 && MJ >= 0 &&
00087             (MI < rep.rows()) && (MJ < rep.cols())
00088         );
00089     }
00090 };
00091 #ifdef minor
00092 #   undef minor
00093 #endif
00094 #if !EXMAT_VC6
00095 
00098 template<class Rep, class ErrChk, int MI, int MJ> EXMAT_INLINE2 static
00099 Mat<ExpMat<StaticMinorView<Rep,TParamINT2<MI,MJ> > >, ErrChk>
00100 minor(Mat<Rep, ErrChk>& mat, Int2Type<MI>, Int2Type<MJ>) {
00101     return Mat<ExpMat<StaticMinorView<Rep,TParamINT2<MI,MJ> > >, ErrChk>(
00102         ExpMat<StaticMinorView<Rep,TParamINT2<MI,MJ> > >(mat)
00103     );
00104 }
00105 #endif  // !EXMAT_VC6
00106 
00107 
00109 template<class Rep, class ExtraTParam>
00110 class StaticConstMinorView : public StaticMinorViewTag
00111 {
00112 public:
00113     typedef StaticConstMinorView<Rep, ExtraTParam>  self_type;
00114     typedef StaticMinorViewTag                      exp_tag;
00115     typedef ExtraTParam                             extra_param_type;
00116     COMMON_CONST_VIEW_TYPEDEFS();
00117 
00118     enum {
00119         MI = ExtraTParam::INT1, // Minor row index
00120         MJ= ExtraTParam::INT2,  // Minor col index
00121         ROWS = super_type::ROWS == 0 ? 0 : super_type::ROWS-1,
00122         COLS = super_type::COLS == 0 ? 0 : super_type::COLS-1,
00123         IsLinear = true,
00124         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00125         ENOP = Rep::ENOP == -1 ? -1 : Rep::ENOP + 2,    // Complexity from the 2 comparisons and 2 additions
00126         TNOP = (ROWS == 0 || COLS == 0) ? -1 : ENOP * ROWS * COLS,
00127         EXPLevel = Rep::EXPLevel + 1
00128     };
00129 
00131     typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00132 
00133     /************************************************/
00134     // Constructors
00135     EXMAT_INLINE2 StaticConstMinorView(const self_type& self)
00136         : rep(self.rep) {}
00137     EXMAT_INLINE2 StaticConstMinorView(const Rep& mat)
00138         : rep(mat) { ComErrCheck(); }
00140     template<class Rep2> EXMAT_INLINE2
00141     StaticConstMinorView(const Rep2& self, const Rep& mat)
00142         : rep(mat) {
00143         ComErrCheck();
00144     }
00145 
00146     /************************************************/
00147     // Dimension information
00148     EXMAT_INLINE2 size_t size() const { return rows()*cols(); }
00149     EXMAT_INLINE2 size_t rows() const { return rep.rows()-1; }
00150     EXMAT_INLINE2 size_t cols() const { return rep.cols()-1; }
00151     /************************************************/
00152     // Index function (for internal use, no error checking applied)
00153     EXMAT_INLINE2 const_reference getAt(index_type i) const
00154     {   return this->getAt(i/cols(), i%cols()); }
00155     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00156     {   return rep.getAt(i<MI?i:i+1, j<MJ?j:j+1);   }
00157 
00158 private:
00159     // Compatibility error checking
00160     EXMAT_INLINE2 void ComErrCheck() {
00161         DefaultErrorChecker::AssertCompat(
00162             MI >= 0 && MJ >= 0 &&
00163             (MI < rep.rows()) && (MJ < rep.cols())
00164         );
00165     }
00166 };
00167 #if !EXMAT_VC6
00168 
00171 template<class Rep, class ErrChk, int MI, int MJ> EXMAT_INLINE2 static
00172 const Mat<ExpMat<StaticConstMinorView<Rep,TParamINT2<MI,MJ> > >, ErrChk>
00173 minor(const Mat<Rep, ErrChk>& mat, Int2Type<MI>, Int2Type<MJ>) {
00174     return Mat<ExpMat<StaticConstMinorView<Rep,TParamINT2<MI,MJ> > >, ErrChk>(
00175         ExpMat<StaticConstMinorView<Rep,TParamINT2<MI,MJ> > >(mat)
00176     );
00177 }
00178 #endif  // !EXMAT_VC6
00179 
00180 
00182 template<class Rep>
00183 class DynMinorView : public DynMinorViewTag
00184 {
00185 public:
00186     typedef DynMinorView<Rep>       self_type;
00187     typedef DynMinorViewTag         exp_tag;
00188     typedef NullTag                 extra_param_type;
00189     typedef DynConstMinorView<Rep>  const_view_type;
00190     COMMON_VIEW_TYPEDEFS();
00191 
00192     enum {
00193         ROWS = super_type::ROWS == 0 ? 0 : super_type::ROWS-1,
00194         COLS = super_type::COLS == 0 ? 0 : super_type::COLS-1,
00195         IsLinear = true,
00196         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00197         ENOP = Rep::ENOP == -1 ? -1 : Rep::ENOP + 4,    // Complexity from the 2 comparisons and 2 additions
00198         TNOP = (ROWS == 0 || COLS == 0) ? -1 : ENOP * ROWS * COLS,
00199         EXPLevel = Rep::EXPLevel + 1
00200     };
00201 
00203     typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00204 
00205     /************************************************/
00206     // Constructors
00207     EXMAT_INLINE2 DynMinorView(const self_type& self)
00208         : rep(self.rep), mi(self.mi), mj(self.mj) {}
00209     EXMAT_INLINE2 DynMinorView(Rep& mat, size_t i, size_t j)
00210         : rep(mat), mi(i), mj(j) { ComErrCheck(); }
00212     template<class Rep2> EXMAT_INLINE2
00213     DynMinorView(const Rep2& self, Rep& mat)
00214         : rep(mat), mi(self.mi), mj(self.mj) { ComErrCheck(); }
00215 
00216     /************************************************/
00217     // Dimension information
00218     EXMAT_INLINE2 size_t size() const { return rows()*cols(); }
00219     EXMAT_INLINE2 size_t rows() const { return rep.rows()-1; }
00220     EXMAT_INLINE2 size_t cols() const { return rep.cols()-1; }
00221     /************************************************/
00222     // Index function (for internal use, no error checking applied)
00223     EXMAT_INLINE2 reference setAt(index_type i)
00224     {   return this->setAt(i/cols(), i%cols()); }
00225     EXMAT_INLINE2 const_reference getAt(index_type i) const
00226     {   return this->getAt(i/cols(), i%cols()); }
00227     EXMAT_INLINE2 reference setAt(index_type i, index_type j)
00228     {   return rep.setAt(i<mi?i:i+1, j<mj?j:j+1);   }
00229     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00230     {   return rep.getAt(i<mi?i:i+1, j<mj?j:j+1);   }
00231 
00232 public:
00233     const size_t mi, mj;
00234 
00235 private:
00236     // Compatibility error checking
00237     EXMAT_INLINE2 void ComErrCheck() {
00238         DefaultErrorChecker::AssertCompat(
00239             mi >= 0 && mj >= 0 &&
00240             (mi < rep.rows()) && (mj < rep.cols())
00241         );
00242     }
00243 };
00247 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00248 Mat<ExpMat<DynMinorView<Rep> >, ErrChk>
00249 minor(Mat<Rep, ErrChk>& mat, size_t i, size_t j) {
00250     return Mat<ExpMat<DynMinorView<Rep> >, ErrChk>(ExpMat<DynMinorView<Rep> >(mat, i, j));
00251 }
00252 
00253 
00255 template<class Rep>
00256 class DynConstMinorView : public DynMinorViewTag
00257 {
00258 public:
00259     typedef DynConstMinorView<Rep>  self_type;
00260     typedef DynMinorViewTag         exp_tag;
00261     typedef NullTag                 extra_param_type;
00262     COMMON_CONST_VIEW_TYPEDEFS();
00263 
00264     enum {
00265         ROWS = super_type::ROWS == 0 ? 0 : super_type::ROWS-1,
00266         COLS = super_type::COLS == 0 ? 0 : super_type::COLS-1,
00267         IsLinear = true,
00268         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00269         ENOP = Rep::ENOP == -1 ? -1 : Rep::ENOP + 4,    // Complexity from the 2 comparisons and 2 additions
00270         TNOP = (ROWS == 0 || COLS == 0) ? -1 : ENOP * ROWS * COLS,
00271         EXPLevel = Rep::EXPLevel + 1
00272     };
00273 
00275     typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00276 
00277     /************************************************/
00278     // Constructors
00279     EXMAT_INLINE2 DynConstMinorView(const self_type& self)
00280         : rep(self.rep), mi(self.mi), mj(self.mj) {}
00281     EXMAT_INLINE2 DynConstMinorView(const Rep& mat, size_t i, size_t j)
00282         : rep(mat), mi(i), mj(j) { ComErrCheck(); }
00284     template<class Rep2> EXMAT_INLINE2
00285     DynConstMinorView(const Rep2& self, const Rep& mat)
00286         : rep(mat), mi(self.mi), mj(self.mj) { ComErrCheck(); }
00287 
00288     /************************************************/
00289     // Dimension information
00290     EXMAT_INLINE2 size_t size() const { return rows()*cols(); }
00291     EXMAT_INLINE2 size_t rows() const { return rep.rows()-1; }
00292     EXMAT_INLINE2 size_t cols() const { return rep.cols()-1; }
00293     /************************************************/
00294     // Index function (for internal use, no error checking applied)
00295     EXMAT_INLINE2 const_reference getAt(index_type i) const
00296     {   return this->getAt(i/cols(), i%cols()); }
00297     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00298     {   return rep.getAt(i<mi?i:i+1, j<mj?j:j+1);   }
00299 
00300 public:
00301     const size_t mi, mj;
00302 
00303 private:
00304     // Compatibility error checking
00305     EXMAT_INLINE2 void ComErrCheck() {
00306         DefaultErrorChecker::AssertCompat(
00307             mi >= 0 && mj >= 0 &&
00308             (mi < rep.rows()) && (mj < rep.cols())
00309         );
00310     }
00311 };
00315 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00316 const Mat<ExpMat<DynConstMinorView<Rep> >, ErrChk>
00317 minor(const Mat<Rep, ErrChk>& mat, size_t i, size_t j) {
00318     return Mat<ExpMat<DynConstMinorView<Rep> >, ErrChk>(ExpMat<DynConstMinorView<Rep> >(mat, i, j));
00319 }

Generated on Sat May 6 23:11:59 2006 for Exmat by  doxygen 1.4.6-NO