Cofactors.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 ConstCofactorsView;
00025 
00027 template<class Rep>
00028 class ConstCofactorsView : public CofactorsViewTag
00029 {
00030 public:
00031     typedef ConstCofactorsView<Rep> self_type;
00032     typedef CofactorsViewTag            exp_tag;
00033     typedef NullTag                         extra_param_type;
00034 
00035     //COMMON_CONST_VIEW_TYPEDEFS();
00036     typedef typename Rep::rep_type                  super_type;
00037     typedef self_type                               rep_type;
00038     typedef super_type                              inner_rep_type;
00039     typedef self_type                               const_view_type;
00040     typedef typename super_type::row_type           row_type;
00041     typedef const ExpRow<self_type>                 const_row_type;
00042     typedef typename super_type::col_type           col_type;
00043     typedef typename super_type::value_type         value_type;
00044     typedef value_type                              reference;
00045     typedef const value_type                        const_reference;
00046     typedef typename super_type::index_type         index_type;
00047     typedef typename super_type::param_type         param_type;
00048     typedef typename super_type::const_param_type   const_param_type;
00049     typedef const_mat_iterator<self_type>           iterator;
00050     typedef const_mat_iterator<self_type>           const_iterator;
00051     typename OperandTypeChooser<super_type>::RET    rep;
00052     EXMAT_INLINE2 const_iterator begin() const
00053     {   return const_iterator(*this, 0, 0); }
00054     EXMAT_INLINE2 const_iterator end() const
00055     {   return const_iterator(*this, rows(), 0);    }
00056 
00057     enum {
00058         ROWS = super_type::COLS,
00059         COLS = super_type::ROWS,
00060         IsLinear = false,
00061         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00062         ENOP = (ROWS == 0 || COLS == 0) ? -1 :
00063             DynConstMinorView<Rep>::TNOP +                      // Complexity of accessing the minor
00064             exmat::PNS::DeterminantComplexity<ROWS-1>::RET +    // Complexity of the determinant only
00065             4,                                                  // Complexity of *, +, %, ==
00066         TNOP = (ROWS == 0 || COLS == 0) ? -1 : ENOP * ROWS * COLS,
00067         EXPLevel = Rep::EXPLevel + 1
00068     };
00069 
00071     typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00072 
00073     /************************************************/
00074     // Constructors
00075     EXMAT_INLINE2 ConstCofactorsView(const self_type& self)
00076         : rep(self.rep) {}
00077     EXMAT_INLINE2 ConstCofactorsView(const Rep& mat)
00078         : rep(mat) { ComErrCheck(); }
00080     template<class Rep2> EXMAT_INLINE2
00081     ConstCofactorsView(const Rep2& self, const Rep& mat)
00082         : rep(mat) {}
00083 
00084     /************************************************/
00085     // Dimension information
00086     EXMAT_INLINE2 size_t size() const { return rep.size(); }
00087     EXMAT_INLINE2 size_t rows() const { return rep.rows(); }
00088     EXMAT_INLINE2 size_t cols() const { return rep.cols(); }
00089     /************************************************/
00090     // Index function (for internal use, no error checking applied)
00091     EXMAT_INLINE2 const_reference getAt(index_type i) const
00092     {   return this->getAt(i/cols(), i%cols()); }
00093     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const {
00094         return determinant(
00095             minor( Mat<ExpMat<ConstDummyView<TTYPENAME Rep::rep_type> >, EmptyErrorChecker>(
00096                 ExpMat<ConstDummyView<TTYPENAME Rep::rep_type> >(rep)
00097             ), i, j)
00098         ) * ( (i+j) % 2 == 0 ? 1 : -1 );
00099     }
00100 
00101 private:
00102     // Compatibility error checking
00103     EXMAT_INLINE2 void ComErrCheck() {
00104         DefaultErrorChecker::AssertCompat(
00105             rows() == cols()
00106         );
00107     }
00108 };
00112 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00113 const Mat<ExpMat<ConstCofactorsView<Rep> >, ErrChk>
00114 cofactors(const Mat<Rep, ErrChk>& mat) {
00115     return Mat<ExpMat<ConstCofactorsView<Rep> >, ErrChk>(
00116         ExpMat<ConstCofactorsView<Rep> >(mat)
00117     );
00118 }

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