/usr/include/opengm/functions/accumulated_view.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 | //
// File: accumulated_view.hxx
//
// This file is part of OpenGM.
//
// Copyright (C) 2015 Stefan Haller
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
#pragma once
#ifndef OPENGM_FUNCTIONS_ACCUMULATED_VIEW_HXX
#define OPENGM_FUNCTIONS_ACCUMULATED_VIEW_HXX
#include <opengm/datastructures/fast_sequence.hxx>
#include <opengm/functions/function_properties_base.hxx>
namespace opengm {
template<class GM>
class AccumulatedViewFunction : public FunctionBase< AccumulatedViewFunction<GM>,
typename GM::ValueType,
typename GM::IndexType,
typename GM::LabelType > {
public:
typedef typename GM::IndexType IndexType;
typedef typename GM::IndexType LabelType;
typedef typename GM::ValueType ValueType;
typedef typename GM::FactorType FactorType;
typedef typename GM::OperatorType OperatorType;
AccumulatedViewFunction();
AccumulatedViewFunction(const FactorType &);
template<class ITERATOR> AccumulatedViewFunction(ITERATOR begin, ITERATOR end);
template<class ITERATOR> ValueType operator()(ITERATOR begin) const;
LabelType shape(const IndexType) const;
IndexType dimension() const;
IndexType size() const;
private:
void check() const;
opengm::FastSequence<const FactorType*> factors_;
};
template<class GM>
AccumulatedViewFunction<GM>::AccumulatedViewFunction()
{
}
template<class GM>
AccumulatedViewFunction<GM>::AccumulatedViewFunction
(
const FactorType &factor
)
{
factors_.push_back(&factor);
}
template<class GM>
template<class ITERATOR>
AccumulatedViewFunction<GM>::AccumulatedViewFunction
(
ITERATOR begin,
ITERATOR end
)
{
factors_.resize(end - begin);
std::copy(begin, end, factors_.begin());
check();
}
template<class GM>
template<class Iterator>
typename AccumulatedViewFunction<GM>::ValueType
AccumulatedViewFunction<GM>::operator()
(
Iterator begin
) const
{
check();
ValueType result = GM::OperatorType::template neutral<ValueType>();
for (size_t i = 0; i < factors_.size(); ++i)
GM::OperatorType::op(factors_[i]->operator()(begin), result);
return result;
}
template<class GM>
typename AccumulatedViewFunction<GM>::LabelType
AccumulatedViewFunction<GM>::shape
(
const IndexType index
) const
{
check();
return factors_[0]->numberOfLabels(index);
}
template<class GM>
typename AccumulatedViewFunction<GM>::IndexType
AccumulatedViewFunction<GM>::dimension() const
{
check();
return factors_[0]->numberOfVariables();
}
template<class GM>
typename AccumulatedViewFunction<GM>::IndexType
AccumulatedViewFunction<GM>::size() const
{
check();
return factors_[0]->size();
}
template<class GM>
void
AccumulatedViewFunction<GM>::check() const
{
#ifndef NDEBUG
OPENGM_ASSERT_OP(factors_.size(), >, 0);
for (size_t i = 0; i < factors_.size(); ++i)
OPENGM_ASSERT(factors_[i] != NULL);
for (size_t i = 1; i < factors_.size(); ++i) {
OPENGM_ASSERT_OP(factors_[0]->size(), ==, factors_[i]->size());
OPENGM_ASSERT_OP(factors_[0]->numberOfVariables(), ==, factors_[i]->numberOfVariables());
for (IndexType j = 0; j < factors_[0]->numberOfVariables(); ++j) {
OPENGM_ASSERT_OP(factors_[0]->numberOfLabels(j), ==, factors_[i]->numberOfLabels(j));
OPENGM_ASSERT_OP(factors_[0]->variableIndex(j), ==, factors_[i]->variableIndex(j));
}
}
#endif
}
} // namespace opengm
#endif
|