2 #ifndef OPENGM_VIEW_FIX_VARIABLES_FUNCTION_HXX
3 #define OPENGM_VIEW_FIX_VARIABLES_FUNCTION_HXX
10 template<
class I,
class L>
11 struct PositionAndLabel {
12 PositionAndLabel(
const I = 0,
const L = 0);
23 :
public FunctionBase<ViewFixVariablesFunction<GM>, typename GM::ValueType, typename GM::IndexType, typename GM::LabelType> {
34 template<
class POSITION_AND_TYPE_CONTAINER>
36 template<
class Iterator>
38 IndexType
shape(
const IndexType)
const;
40 IndexType
size()
const;
43 FactorType
const* factor_;
44 std::vector<PositionAndLabel<IndexType, LabelType> > positionAndLabels_;
45 mutable std::vector<LabelType> iteratorBuffer_;
46 mutable bool computedSize_;
48 std::vector<size_t> lookUp_;
51 template<
class I,
class L>
52 PositionAndLabel<I, L>::PositionAndLabel
57 : position_(position),
75 const std::vector<PositionAndLabel<typename GM::IndexType, typename GM::LabelType> >& positionAndLabels
78 positionAndLabels_(positionAndLabels),
79 iteratorBuffer_(factor.numberOfVariables()),
82 lookUp_(factor.numberOfVariables()-positionAndLabels.
size())
85 for(
size_t i=0; i<positionAndLabels_.size(); ++i) {
86 OPENGM_ASSERT(positionAndLabels_[i].label_ < factor_->numberOfLabels(positionAndLabels_[i].position_));
89 for(
size_t ind=0; ind<lookUp_.size(); ++ind) {
91 for(
IndexType i=0; i<positionAndLabels_.size(); ++i) {
92 if( positionAndLabels_[i].position_ <= ind+add) {
105 template<
class POSITION_AND_TYPE_CONTAINER>
110 const POSITION_AND_TYPE_CONTAINER& positionAndLabels
113 positionAndLabels_(positionAndLabels.begin(), positionAndLabels.end()),
114 iteratorBuffer_(factor.numberOfVariables()),
115 computedSize_(
false),
117 lookUp_(factor.numberOfVariables()-positionAndLabels.
size())
120 for(
size_t i=0; i<positionAndLabels_.size(); ++i) {
121 OPENGM_ASSERT(positionAndLabels_[i].label_ < factor_->numberOfLabels(positionAndLabels_[i].position_));
124 for(
size_t ind=0; ind<lookUp_.size(); ++ind) {
126 for(
IndexType i=0; i<positionAndLabels_.size(); ++i) {
127 if( positionAndLabels_[i].position_ <= ind+add) {
131 lookUp_[ind]=ind+add;
136 template<
class Iterator>
144 for(
size_t ind=0; ind<lookUp_.size(); ++ind) {
145 iteratorBuffer_[lookUp_[ind]]=*begin;
148 for(
size_t i=0; i<positionAndLabels_.size(); ++i) {
149 iteratorBuffer_[positionAndLabels_[i].position_]
150 = positionAndLabels_[i].label_;
152 return factor_->operator()(iteratorBuffer_.begin());
164 for(
IndexType i=0; i<positionAndLabels_.size(); ++i) {
165 if( positionAndLabels_[i].position_ <= index+add) {
170 return factor_->numberOfLabels(index + add);
178 return factor_->numberOfVariables() - positionAndLabels_.size();
186 if(computedSize_==
false) {
187 size_ = factor_->size();
188 for(
IndexType j=0; j<positionAndLabels_.size(); ++j) {
189 size_ /= (factor_->numberOfLabels(positionAndLabels_[j].position_));
191 computedSize_ =
true;
198 #endif // #ifndef OPENGM_VIEW_FIX_VARIABLES_FUNCTION_HXX
Fallback implementation of member functions of OpenGM functions.
GM::FactorType FactorType
ViewFixVariablesFunction()
#define OPENGM_ASSERT(expression)
GM::OperatorType OperatorType
IndexType dimension() const
Funcion that refers to a factor of another GraphicalModel in which some variables are fixed...
ValueType operator()(Iterator begin) const
IndexType shape(const IndexType) const