/usr/include/opengm/functions/explicit_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 | #pragma once
#ifndef OPENGM_EXPLICIT_FUNCTION_HXX
#define OPENGM_EXPLICIT_FUNCTION_HXX
#include "opengm/datastructures/marray/marray.hxx"
#include "opengm/functions/function_registration.hxx"
#include "opengm/functions/function_properties_base.hxx"
namespace opengm {
/// Function encoded as a dense multi-dimensional array, marray::Marray
///
/// \ingroup functions
template<class T, class I=size_t, class L=size_t>
class ExplicitFunction
: public marray::Marray<T>,
public FunctionBase<ExplicitFunction<T, I, L>, T, I, L>
{
public:
typedef T ValueType;
typedef L LabelType;
typedef I IndexType;
ExplicitFunction()
: marray::Marray<T>()
{}
/// construct a constant explicit function of order 0
ExplicitFunction(const T& value)
: marray::Marray<T>(value)
{}
ExplicitFunction(const ExplicitFunction& other)
: marray::Marray<T>(other)
{}
ExplicitFunction& operator=(const ExplicitFunction& other)
{
marray::Marray<T>::operator=(other);
return *this;
}
/// construct a function encoded by a value table (whose entries are initialized as 0)
///
/// Example: A function depending on two variables with 3 and 4 labels, respectively.
/// \code
/// size_t shape[] = {3, 4};
/// ExplicitFunction f(shape, shape + 2};
/// \endcode
///
template <class SHAPE_ITERATOR>
ExplicitFunction(SHAPE_ITERATOR shapeBegin, SHAPE_ITERATOR shapeEnd)
: marray::Marray<T>(shapeBegin, shapeEnd)
{}
/// construct a function encoded by a value table (whose entries are initialized with the same value)
template <class SHAPE_ITERATOR>
ExplicitFunction(SHAPE_ITERATOR shapeBegin, SHAPE_ITERATOR shapeEnd, const T & value)
: marray::Marray<T>(shapeBegin, shapeEnd, value)
{}
};
/// \cond HIDDEN_SYMBOLS
/// FunctionRegistration
template<class T, class I, class L>
struct FunctionRegistration< ExplicitFunction<T, I, L> >{
enum ID {
Id=opengm::FUNCTION_TYPE_ID_OFFSET
};
};
/// FunctionSerialization
template<class T, class I, class L>
class FunctionSerialization< ExplicitFunction<T, I, L> >{
public:
typedef typename ExplicitFunction<T, I, L>::value_type ValueType;
static size_t indexSequenceSize(const ExplicitFunction<T, I, L> &);
static size_t valueSequenceSize(const ExplicitFunction<T, I, L> &);
template<class INDEX_OUTPUT_ITERATOR, class VALUE_OUTPUT_ITERATOR >
static void serialize(const ExplicitFunction<T, I, L> &, INDEX_OUTPUT_ITERATOR, VALUE_OUTPUT_ITERATOR );
template<class INDEX_INPUT_ITERATOR , class VALUE_INPUT_ITERATOR>
static void deserialize( INDEX_INPUT_ITERATOR, VALUE_INPUT_ITERATOR, ExplicitFunction<T, I, L> &);
};
/// \endcond
template<class T, class I, class L>
inline size_t FunctionSerialization<ExplicitFunction<T, I, L> >::indexSequenceSize
(
const ExplicitFunction<T, I, L> & src
) {
return src.dimension() +1;
}
template<class T, class I, class L>
inline size_t FunctionSerialization<ExplicitFunction<T, I, L> >::valueSequenceSize
(
const ExplicitFunction<T, I, L> & src
) {
return src.size();
}
template<class T, class I, class L>
template<class INDEX_OUTPUT_ITERATOR, class VALUE_OUTPUT_ITERATOR >
void FunctionSerialization< ExplicitFunction<T, I, L> >::serialize
(
const ExplicitFunction<T, I, L> & src,
INDEX_OUTPUT_ITERATOR indexOutIterator,
VALUE_OUTPUT_ITERATOR valueOutIterator
) {
if(src.dimension()==0) {
*indexOutIterator=0;
*valueOutIterator=src(0);
}
else{
*indexOutIterator=src.dimension();
++indexOutIterator;
for(size_t i=0;i<src.dimension();++i) {
*indexOutIterator=src.shape(i);
++indexOutIterator;
}
for(size_t i=0;i<src.size();++i) {
*valueOutIterator=src(i);
++valueOutIterator;
}
}
}
template<class T, class I, class L>
template<class INDEX_INPUT_ITERATOR, class VALUE_INPUT_ITERATOR >
void FunctionSerialization<ExplicitFunction<T, I, L> >::deserialize
(
INDEX_INPUT_ITERATOR indexOutIterator,
VALUE_INPUT_ITERATOR valueOutIterator,
ExplicitFunction<T, I, L> & dst
) {
if(*indexOutIterator==0) {
dst.assign();
dst=ExplicitFunction<T, I, L>(*valueOutIterator);
}
else{
const size_t dim=*indexOutIterator;
std::vector<size_t> shape(dim);
++indexOutIterator;
for(size_t i=0;i<dim;++i) {
shape[i]=*indexOutIterator;
++indexOutIterator;
}
dst.assign();
dst.resize(shape.begin(), shape.end() );
for(size_t i=0;i<dst.size();++i) {
dst(i)=*valueOutIterator;
++valueOutIterator;
}
}
}
template<class FUNC, class T, class I, class L>
ExplicitFunction<T, I, L>
cloneAsExplicitFunction
(
const FUNC &function
)
{
ExplicitFunction<T, I, L> result;
cloneAsExplicitFunction(function, result);
return result;
}
template<class FUNC, class T, class I, class L>
void
cloneAsExplicitFunction
(
const FUNC &function,
ExplicitFunction<T, I, L> &out
)
{
typedef ShapeWalker<typename FUNC::FunctionShapeIteratorType> Walker;
out.resize(function.functionShapeBegin(), function.functionShapeEnd());
Walker walker(function.functionShapeBegin(), function.dimension());
for (I i = 0; i < function.size(); ++i, ++walker) {
out(walker.coordinateTuple().begin()) =
function(walker.coordinateTuple().begin());
}
}
} // namespace opengm
#endif // OPENGM_EXPLICIT_FUNCTION_HXX
|