dddualvariableblock.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_DD_DUALVARIABLEBLOCK_HXX
00003 #define OPENGM_DD_DUALVARIABLEBLOCK_HXX
00004 
00005 #include "opengm/datastructures/marray/marray.hxx"
00006 #include "opengm/graphicalmodel/decomposition/graphicalmodeldecomposition.hxx"
00007 
00008 namespace opengm {
00010 
00011    template<class DUALVAR = marray::Marray<double> >
00012    class DDDualVariableBlock{
00013    public:
00014       typedef DUALVAR  DualVariableType;
00015       typedef typename DUALVAR::ValueType ValueType; 
00016       typedef typename GraphicalModelDecomposition::SubFactor                    SubFactorType;
00017       typedef typename GraphicalModelDecomposition::SubFactorListType            SubFactorListType; 
00018 
00019       // Methods
00020       DDDualVariableBlock(){};
00021       template<class ITERATOR> DDDualVariableBlock(const SubFactorListType& subFactorList, ITERATOR shapeBegin, ITERATOR shapeEnd);
00022       std::vector<DUALVAR*> getPointers();
00023       void test() const;
00024 
00025       // Members
00026       std::vector<DualVariableType> duals_;
00027       const SubFactorListType* subFactorList_;
00028    };
00029 
00030 
00031    template<class DUALVAR = marray::Marray<double> >
00032    class DDDualVariableBlock2{
00033    public:
00034       typedef DUALVAR  DualVariableType;
00035       typedef typename DUALVAR::ValueType ValueType; 
00036       typedef typename GraphicalModelDecomposition::SubFactor                    SubFactorType;
00037       typedef typename GraphicalModelDecomposition::SubFactorListType            SubFactorListType; 
00038 
00039       // Methods
00040       DDDualVariableBlock2(){};
00041       template<class ITERATOR> DDDualVariableBlock2(const SubFactorListType& subFactorList, ITERATOR shapeBegin, ITERATOR shapeEnd);
00042       std::vector<DUALVAR*> getPointers(); 
00043       void test() const;
00044 
00045       // Members
00046       std::vector<DualVariableType> duals_;
00047       std::vector<DualVariableType> duals2_;
00048       const SubFactorListType* subFactorList_;
00049    }; 
00050 
00051 
00054 
00055    template<class DUALVAR>
00056    template<class ITERATOR> 
00057    DDDualVariableBlock<DUALVAR>::DDDualVariableBlock
00058    (
00059       const typename GraphicalModelDecomposition::SubFactorListType& subFactorList, 
00060       ITERATOR shapeBegin,
00061       ITERATOR shapeEnd
00062       )
00063    {
00064       const size_t numDuals = subFactorList.size(); 
00065       duals_.resize(numDuals, DUALVAR(shapeBegin,shapeEnd,0));
00066       subFactorList_ = &subFactorList; 
00067    }
00068    template<>
00069    template<class ITERATOR> 
00070    DDDualVariableBlock<marray::View<double,false> >::DDDualVariableBlock
00071    (
00072       const SubFactorListType& subFactorList, 
00073       ITERATOR shapeBegin,
00074       ITERATOR shapeEnd
00075       )
00076    {
00077       const size_t numDuals = subFactorList.size();
00078       double tmp;
00079       duals_.resize(numDuals, marray::View<double,false>(shapeBegin,shapeEnd,&tmp));
00080       subFactorList_ = &subFactorList; 
00081    }  
00082 
00083    template<>
00084    template<class ITERATOR> 
00085    DDDualVariableBlock<marray::View<float,false> >::DDDualVariableBlock
00086    (
00087       const SubFactorListType& subFactorList, 
00088       ITERATOR shapeBegin,
00089       ITERATOR shapeEnd
00090       )
00091    {
00092       const size_t numDuals = subFactorList.size();
00093       double tmp;
00094       duals_.resize(numDuals, marray::View<float,false>(shapeBegin,shapeEnd,&tmp));
00095       subFactorList_ = &subFactorList; 
00096    } 
00097    
00098    template<class DUALVAR>
00099    std::vector<DUALVAR*>  DDDualVariableBlock<DUALVAR>::getPointers()
00100    {
00101       std::vector<DualVariableType*> ret(duals_.size());
00102       for(size_t i=0; i<duals_.size(); ++i) ret[i] = &(duals_[i]);
00103       return ret;
00104    }
00105 
00106    template<class DUALVAR>
00107    void DDDualVariableBlock<DUALVAR>::test() const
00108    {
00109       marray::Marray<double> temp(duals_[0].shapeBegin(), duals_[0].shapeEnd() ,0);
00110       for(size_t i=0; i<duals_.size(); ++i) {
00111          temp += duals_[i];
00112       }
00113       //std::cout<<" temp size "<<temp.size()<<"\n";
00114       for(size_t j=0; j<temp.size(); ++j) {
00115          if(  (temp(j)<0.001 && temp(j)>-0.001)==false ){
00116             std::cout<<"temp("<<j<<") = "<<temp(j)<<"\n";
00117          }
00118          //OPENGM_ASSERT(temp(i)<0.00001 && temp(i)>-0.00001);
00119       }
00120    }
00121 
00123 
00124    template<class DUALVAR>
00125    template<class ITERATOR> 
00126    DDDualVariableBlock2<DUALVAR>::DDDualVariableBlock2
00127    (
00128       const typename GraphicalModelDecomposition::SubFactorListType& subFactorList, 
00129       ITERATOR shapeBegin,
00130       ITERATOR shapeEnd
00131       )
00132    {
00133       const size_t numDuals = subFactorList.size(); 
00134       duals_.resize(numDuals, DUALVAR(shapeBegin,shapeEnd,0));
00135       duals2_.resize(numDuals, DUALVAR(shapeBegin,shapeEnd,0));
00136       subFactorList_ = &subFactorList; 
00137    }
00138    template<>
00139    template<class ITERATOR> 
00140    DDDualVariableBlock2<marray::View<double,false> >::DDDualVariableBlock2
00141    (
00142       const SubFactorListType& subFactorList, 
00143       ITERATOR shapeBegin,
00144       ITERATOR shapeEnd
00145       )
00146    {
00147       const size_t numDuals = subFactorList.size();
00148       double tmp;
00149       duals_.resize(numDuals, marray::View<double,false>(shapeBegin,shapeEnd,&tmp));
00150       duals2_.resize(numDuals, marray::View<double,false>(shapeBegin,shapeEnd,&tmp));
00151       subFactorList_ = &subFactorList; 
00152    }  
00153    template<>
00154    template<class ITERATOR> 
00155    DDDualVariableBlock2<marray::View<float,false> >::DDDualVariableBlock2
00156    (
00157       const SubFactorListType& subFactorList, 
00158       ITERATOR shapeBegin,
00159       ITERATOR shapeEnd
00160       )
00161    {
00162       const size_t numDuals = subFactorList.size();
00163       float tmp;
00164       duals_.resize(numDuals, marray::View<float,false>(shapeBegin,shapeEnd,&tmp));
00165       duals2_.resize(numDuals, marray::View<float,false>(shapeBegin,shapeEnd,&tmp));
00166       subFactorList_ = &subFactorList; 
00167    } 
00168    
00169    template<class DUALVAR>
00170    std::vector<DUALVAR*>  DDDualVariableBlock2<DUALVAR>::getPointers()
00171    {
00172       std::vector<DualVariableType*> ret(duals_.size());
00173       for(size_t i=0; i<duals_.size(); ++i) ret[i] = &(duals_[i]);
00174       return ret;
00175    }
00176 
00177    template<class DUALVAR>
00178    void  DDDualVariableBlock2<DUALVAR>::test() const 
00179    {
00180       marray::Marray<double> temp(duals_[0].shapeBegin(),duals_[0].shapeEnd(),0);
00181       for(size_t i=0; i<duals_.size(); ++i) temp += duals_[i];
00182       for(size_t i=0; i<temp.size(); ++i) OPENGM_ASSERT(temp(i)<0.00001 && temp(i)>-0.00001); 
00183    }
00184   
00186 } // namespace opengm
00187 
00188 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:01 2013 for OpenGM by  doxygen 1.6.3