/usr/include/opengm/functions/view_fix_variables_function.hxx is in libopengm-dev 2.3.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | #pragma once
#ifndef OPENGM_VIEW_FIX_VARIABLES_FUNCTION_HXX
#define OPENGM_VIEW_FIX_VARIABLES_FUNCTION_HXX
#include "opengm/functions/function_properties_base.hxx"
namespace opengm {
/// \cond HIDDEN_SYMBOLS
template<class I, class L>
struct PositionAndLabel {
PositionAndLabel(const I = 0, const L = 0);
I position_;
L label_;
};
/// \endcond
/// Funcion that refers to a factor of another GraphicalModel in which some variables are fixed
///
/// \ingroup functions
template<class GM>
class ViewFixVariablesFunction
: public FunctionBase<ViewFixVariablesFunction<GM>, typename GM::ValueType, typename GM::IndexType, typename GM::LabelType> {
public:
typedef typename GM::ValueType ValueType;
typedef ValueType value_type;
typedef typename GM::FactorType FactorType;
typedef typename GM::OperatorType OperatorType;
typedef typename GM::IndexType IndexType;
typedef typename GM::LabelType LabelType;
ViewFixVariablesFunction();
ViewFixVariablesFunction(const FactorType &, const std::vector<PositionAndLabel<IndexType, LabelType> > &);
template<class POSITION_AND_TYPE_CONTAINER>
ViewFixVariablesFunction(const FactorType &, const POSITION_AND_TYPE_CONTAINER &);
template<class Iterator>
ValueType operator()(Iterator begin)const;
IndexType shape(const IndexType)const;
IndexType dimension()const;
IndexType size()const;
private:
FactorType const* factor_;
std::vector<PositionAndLabel<IndexType, LabelType> > positionAndLabels_;
mutable std::vector<LabelType> iteratorBuffer_;
mutable bool computedSize_;
mutable size_t size_;
std::vector<size_t> lookUp_;
};
template<class I, class L>
PositionAndLabel<I, L>::PositionAndLabel
(
const I position,
const L label
)
: position_(position),
label_(label)
{}
template<class GM>
inline
ViewFixVariablesFunction<GM>::ViewFixVariablesFunction()
: factor_(NULL),
iteratorBuffer_(),
computedSize_(false),
size_(1)
{}
template<class GM>
inline
ViewFixVariablesFunction<GM>::ViewFixVariablesFunction
(
const typename ViewFixVariablesFunction<GM>::FactorType& factor,
const std::vector<PositionAndLabel<typename GM::IndexType, typename GM::LabelType> >& positionAndLabels
)
: factor_(&factor),
positionAndLabels_(positionAndLabels),
iteratorBuffer_(factor.numberOfVariables()),
computedSize_(false),
size_(1),
lookUp_(factor.numberOfVariables()-positionAndLabels.size())
{
if(opengm::NO_DEBUG==false) {
for(size_t i=0; i<positionAndLabels_.size(); ++i) {
OPENGM_ASSERT(positionAndLabels_[i].label_ < factor_->numberOfLabels(positionAndLabels_[i].position_));
}
}
for(size_t ind=0; ind<lookUp_.size(); ++ind) {
size_t add=0;
for(IndexType i=0; i<positionAndLabels_.size(); ++i) {
if( positionAndLabels_[i].position_ <= ind+add) {
++add;
}
}
lookUp_[ind]=ind+add;
}
}
/// constructor
/// \tparam POSITION_AND_TYPE_CONTAINER container holding positions and labels of the variable to fix
/// \param factor the factor to reference
/// \param positionAndLabels positions and labels of the variable to fix
template<class GM>
template<class POSITION_AND_TYPE_CONTAINER>
inline
ViewFixVariablesFunction<GM>::ViewFixVariablesFunction
(
const typename ViewFixVariablesFunction<GM>::FactorType& factor,
const POSITION_AND_TYPE_CONTAINER& positionAndLabels
)
: factor_(&factor),
positionAndLabels_(positionAndLabels.begin(), positionAndLabels.end()),
iteratorBuffer_(factor.numberOfVariables()),
computedSize_(false),
size_(1),
lookUp_(factor.numberOfVariables()-positionAndLabels.size())
{
if(!(opengm::NO_DEBUG)) {
for(size_t i=0; i<positionAndLabels_.size(); ++i) {
OPENGM_ASSERT(positionAndLabels_[i].label_ < factor_->numberOfLabels(positionAndLabels_[i].position_));
}
}
for(size_t ind=0; ind<lookUp_.size(); ++ind) {
size_t add = 0;
for(IndexType i=0; i<positionAndLabels_.size(); ++i) {
if( positionAndLabels_[i].position_ <= ind+add) {
++add;
}
}
lookUp_[ind]=ind+add;
}
}
template<class GM>
template<class Iterator>
inline typename ViewFixVariablesFunction<GM>::ValueType
ViewFixVariablesFunction<GM>::operator()
(
Iterator begin
) const
{
OPENGM_ASSERT(factor_ != NULL);
for(size_t ind=0; ind<lookUp_.size(); ++ind) {
iteratorBuffer_[lookUp_[ind]]=*begin;
++begin;
}
for(size_t i=0; i<positionAndLabels_.size(); ++i) {
iteratorBuffer_[positionAndLabels_[i].position_]
= positionAndLabels_[i].label_;
}
return factor_->operator()(iteratorBuffer_.begin());
}
template<class GM>
inline typename ViewFixVariablesFunction<GM>::IndexType
ViewFixVariablesFunction<GM>::shape
(
const typename ViewFixVariablesFunction<GM>::IndexType index
) const
{
OPENGM_ASSERT(factor_ != NULL);
size_t add = 0;
for(IndexType i=0; i<positionAndLabels_.size(); ++i) {
if( positionAndLabels_[i].position_ <= index+add) {
++add;
}
}
OPENGM_ASSERT(index + add < factor_->numberOfVariables());
return factor_->numberOfLabels(index + add);
}
template<class GM>
inline typename ViewFixVariablesFunction<GM>::IndexType
ViewFixVariablesFunction<GM>::dimension() const
{
OPENGM_ASSERT(factor_!=NULL);
return factor_->numberOfVariables() - positionAndLabels_.size();
}
template<class GM>
inline typename ViewFixVariablesFunction<GM>::IndexType
ViewFixVariablesFunction<GM>::size() const
{
OPENGM_ASSERT(factor_!=NULL);
if(computedSize_== false) {
size_ = factor_->size();
for(IndexType j=0; j<positionAndLabels_.size(); ++j) {
size_ /= (factor_->numberOfLabels(positionAndLabels_[j].position_));
}
computedSize_ = true;
}
return size_;
}
} // namespace opengm
#endif // #ifndef OPENGM_VIEW_FIX_VARIABLES_FUNCTION_HXX
|