/usr/include/opengm/functions/absolute_difference.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 | #pragma once
#ifndef OPENGM_ABSOLUTE_DIFFERENCE_FUNCTION_HXX
#define OPENGM_ABSOLUTE_DIFFERENCE_FUNCTION_HXX
#include "opengm/opengm.hxx"
#include "opengm/functions/function_registration.hxx"
#include "opengm/functions/function_properties_base.hxx"
namespace opengm {
/// Absolute difference between two labels
///
/// \ingroup functions
template<class T, class I = size_t, class L = size_t>
class AbsoluteDifferenceFunction
: public FunctionBase<AbsoluteDifferenceFunction<T, I, L>, T, I, L>
{
public:
typedef T ValueType;
typedef I IndexType;
typedef L LabelType;
AbsoluteDifferenceFunction(const LabelType = 2, const LabelType = 2, const ValueType = 1);
size_t shape(const IndexType) const;
size_t size() const;
size_t dimension() const;
template<class ITERATOR> ValueType operator()(ITERATOR) const;
private:
LabelType numberOfLabels1_;
LabelType numberOfLabels2_;
ValueType scale_;
};
/// \cond HIDDEN_SYMBOLS
/// FunctionRegistration
template <class T, class I, class L>
struct FunctionRegistration< AbsoluteDifferenceFunction<T, I, L> >{
/// Id of the AbsoluteDifferenceFunction
enum ID {
Id = opengm::FUNCTION_TYPE_ID_OFFSET + 2
};
};
/// FunctionSerialization
template<class T, class I, class L>
class FunctionSerialization<AbsoluteDifferenceFunction<T, I, L> > {
public:
typedef typename AbsoluteDifferenceFunction<T, I, L>::ValueType ValueType;
static size_t indexSequenceSize(const AbsoluteDifferenceFunction<T, I, L>&);
static size_t valueSequenceSize(const AbsoluteDifferenceFunction<T, I, L>&);
template<class INDEX_OUTPUT_ITERATOR, class VALUE_OUTPUT_ITERATOR >
static void serialize(const AbsoluteDifferenceFunction<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, AbsoluteDifferenceFunction<T, I, L>&);
};
/// \endcond
/// Constructor
///
/// \param numberOfLabels1 number of labels of the first variable
/// \param numberOfLabels2 number of labels of the second variable
///
template <class T, class I, class L>
inline
AbsoluteDifferenceFunction<T, I, L>::AbsoluteDifferenceFunction
(
const LabelType numberOfLabels1,
const LabelType numberOfLabels2,
const ValueType scale
)
: numberOfLabels1_(numberOfLabels1),
numberOfLabels2_(numberOfLabels2),
scale_(scale)
{}
template <class T, class I, class L>
template <class ITERATOR>
inline typename AbsoluteDifferenceFunction<T, I, L>::ValueType
AbsoluteDifferenceFunction<T, I, L>::operator()
(
ITERATOR begin
) const {
ValueType value = begin[0];
value -= begin[1];
return scale_*abs(value);
}
/// extension a value table encoding this function would have
///
/// \param i dimension
template <class T, class I, class L>
inline size_t
AbsoluteDifferenceFunction<T, I, L>::shape
(
const IndexType i
) const {
OPENGM_ASSERT(i < 2);
return (i==0 ? numberOfLabels1_ : numberOfLabels2_);
}
// order (number of variables) of the function
template <class T, class I, class L>
inline size_t
AbsoluteDifferenceFunction<T, I, L>::dimension() const {
return 2;
}
/// number of entries a value table encoding this function would have (used for I/O)
template <class T, class I, class L>
inline size_t
AbsoluteDifferenceFunction<T, I, L>::size() const {
return numberOfLabels1_ * numberOfLabels2_;
}
template<class T, class I, class L>
inline size_t
FunctionSerialization<AbsoluteDifferenceFunction<T, I, L> >::indexSequenceSize
(
const AbsoluteDifferenceFunction<T, I, L>& src
) {
return 2;
}
template<class T, class I, class L>
inline size_t
FunctionSerialization<AbsoluteDifferenceFunction<T, I, L> >::valueSequenceSize
(
const AbsoluteDifferenceFunction<T, I, L>& src
) {
return 1;
}
template<class T, class I, class L>
template<class INDEX_OUTPUT_ITERATOR, class VALUE_OUTPUT_ITERATOR >
inline void
FunctionSerialization<AbsoluteDifferenceFunction<T, I, L> >::serialize
(
const AbsoluteDifferenceFunction<T, I, L>& src,
INDEX_OUTPUT_ITERATOR indexOutIterator,
VALUE_OUTPUT_ITERATOR valueOutIterator
) {
*indexOutIterator = src.shape(0);
++indexOutIterator;
*indexOutIterator = src.shape(1);
L l[]={0,1};
*valueOutIterator = src(l);
}
template<class T, class I, class L>
template<class INDEX_INPUT_ITERATOR, class VALUE_INPUT_ITERATOR >
inline void
FunctionSerialization< AbsoluteDifferenceFunction<T, I, L> >::deserialize
(
INDEX_INPUT_ITERATOR indexInIterator,
VALUE_INPUT_ITERATOR valueInIterator,
AbsoluteDifferenceFunction<T, I, L>& dst
) {
const size_t shape0=*indexInIterator;
++ indexInIterator;
dst=AbsoluteDifferenceFunction<T, I, L>(shape0, *indexInIterator,*valueInIterator);
}
} // namespace opengm
#endif // OPENGM_ABSOLUTE_DIFFERENCE_FUNCTION_HXX
|