2 #ifndef OPENGM_SHAPE_ACCESSOR_HXX 3 #define OPENGM_SHAPE_ACCESSOR_HXX 9 template<
class FUNCTION>
10 class FunctionShapeAccessor {
12 typedef size_t value_type;
13 typedef const value_type reference;
14 typedef const value_type* pointer;
15 typedef const FUNCTION& factor_reference;
16 typedef const FUNCTION* factor_pointer;
18 FunctionShapeAccessor(factor_pointer f = NULL)
21 FunctionShapeAccessor(factor_reference f)
25 return factor_ == NULL ? 0 : factor_->dimension();
27 value_type operator[](
const size_t j) {
29 return factor_->shape(j);
31 const value_type operator[](
const size_t j)
const {
33 return factor_->shape(j);
35 bool operator==(
const FunctionShapeAccessor<FUNCTION> & other)
const 36 {
return factor_ == other.factor_; }
39 factor_pointer factor_;
42 template<
class FACTOR>
43 class FactorShapeAccessor {
45 typedef size_t value_type;
46 typedef const value_type reference;
47 typedef const value_type* pointer;
48 typedef const FACTOR& factor_reference;
49 typedef const FACTOR* factor_pointer;
51 FactorShapeAccessor(factor_pointer f = 0)
54 FactorShapeAccessor(factor_reference f)
58 {
return factor_ == 0 ? 0 : factor_->numberOfVariables(); }
59 reference operator[](
const size_t j)
60 {
return factor_->numberOfLabels(j); }
61 const value_type operator[](
const size_t j)
const 62 {
return factor_->numberOfLabels(j); }
63 bool operator==(
const FactorShapeAccessor<FACTOR> & other)
const 64 {
return factor_ == other.factor_; }
67 factor_pointer factor_;
72 template<
class SUBSET_ITERATOR,
class GM_LABEL_ITER>
73 class SubsetAccessor {
75 typedef typename std::iterator_traits<GM_LABEL_ITER>::value_type value_type;
77 typedef const value_type reference;
78 typedef const value_type* pointer;
85 SubsetAccessor(SUBSET_ITERATOR sBegin, SUBSET_ITERATOR sEnd , GM_LABEL_ITER iter)
91 {
return std::distance(sBegin_, sEnd_); }
92 reference operator[](
const size_t j)
93 {
return gmLabelIter_[sBegin_[j]]; }
94 const value_type operator[](
const size_t j)
const 95 {
return gmLabelIter_[sBegin_[j]]; }
96 bool operator==(
const SubsetAccessor & other)
const 98 return sBegin_ == other.sBegin_ &&
99 sEnd_ == other.sEnd_ &&
100 gmLabelIter_==other.gmLabelIter_;
104 SUBSET_ITERATOR sBegin_;
105 SUBSET_ITERATOR sEnd_;
106 GM_LABEL_ITER gmLabelIter_;
111 template<
class FACTOR,
class GM_LABEL_ITER>
112 class GmLabelFactorLabelAccessor {
114 typedef typename std::iterator_traits<GM_LABEL_ITER>::value_type value_type;
116 typedef const value_type reference;
117 typedef const value_type* pointer;
118 typedef const FACTOR& factor_reference;
119 typedef const FACTOR* factor_pointer;
121 GmLabelFactorLabelAccessor()
125 GmLabelFactorLabelAccessor(factor_reference f , GM_LABEL_ITER iter)
130 {
return factor_ == 0 ? 0 : factor_->numberOfVariables(); }
131 reference operator[](
const size_t j)
132 {
return gmLabelIter_[factor_->variableIndex(j)]; }
133 const value_type operator[](
const size_t j)
const 134 {
return gmLabelIter_[factor_->variableIndex(j)]; }
135 bool operator==(
const FactorShapeAccessor<FACTOR> & other)
const 136 {
return factor_ == other.factor_ && gmLabelIter_==other.gmLabelIter_;
140 factor_pointer factor_;
141 GM_LABEL_ITER gmLabelIter_;
146 template<
class FACTOR>
147 class FactorVariablesAccessor {
149 typedef typename FACTOR::IndexType IndexType;
150 typedef IndexType value_type;
151 typedef const value_type reference;
152 typedef const value_type* pointer;
153 typedef const FACTOR& factor_reference;
154 typedef const FACTOR* factor_pointer;
156 FactorVariablesAccessor(factor_pointer f = 0)
159 FactorVariablesAccessor(factor_reference f)
162 IndexType size()
const 163 {
return factor_ == 0 ? 0 : factor_->numberOfVariables(); }
164 reference operator[](
const size_t j)
165 {
return factor_->numberOfLabels(j); }
166 const value_type operator[](
const size_t j)
const 167 {
return factor_->variableIndex(j); }
168 bool operator==(
const FactorVariablesAccessor<FACTOR> & other)
const 169 {
return factor_ == other.factor_; }
172 factor_pointer factor_;
179 #endif // #ifndef OPENGM_SHAPE_ACCESSOR_HXX
bool operator==(const IndicatorVariable< INDEX1_TYPE, LABEL1_TYPE > &indicatorVar1, const IndicatorVariable< INDEX2_TYPE, LABEL2_TYPE > &indicatorVar2)
#define OPENGM_ASSERT(expression)