2 #ifndef OPENGM_EXPLICIT_FUNCTION_HXX
3 #define OPENGM_EXPLICIT_FUNCTION_HXX
14 template<
class T,
class I=
size_t,
class L=
size_t>
51 template <
class SHAPE_ITERATOR>
57 template <
class SHAPE_ITERATOR>
65 template<
class T,
class I,
class L>
66 struct FunctionRegistration< ExplicitFunction<T, I, L> >{
73 template<
class T,
class I,
class L>
74 class FunctionSerialization< ExplicitFunction<T, I, L> >{
76 typedef typename ExplicitFunction<T, I, L>::value_type ValueType;
78 static size_t indexSequenceSize(
const ExplicitFunction<T, I, L> &);
79 static size_t valueSequenceSize(
const ExplicitFunction<T, I, L> &);
80 template<
class INDEX_OUTPUT_ITERATOR,
class VALUE_OUTPUT_ITERATOR >
81 static void serialize(
const ExplicitFunction<T, I, L> &, INDEX_OUTPUT_ITERATOR, VALUE_OUTPUT_ITERATOR );
82 template<
class INDEX_INPUT_ITERATOR ,
class VALUE_INPUT_ITERATOR>
83 static void deserialize( INDEX_INPUT_ITERATOR, VALUE_INPUT_ITERATOR, ExplicitFunction<T, I, L> &);
87 template<
class T,
class I,
class L>
88 inline size_t FunctionSerialization<ExplicitFunction<T, I, L> >::indexSequenceSize
90 const ExplicitFunction<T, I, L> & src
92 return src.dimension() +1;
95 template<
class T,
class I,
class L>
96 inline size_t FunctionSerialization<ExplicitFunction<T, I, L> >::valueSequenceSize
98 const ExplicitFunction<T, I, L> & src
103 template<
class T,
class I,
class L>
104 template<
class INDEX_OUTPUT_ITERATOR,
class VALUE_OUTPUT_ITERATOR >
105 void FunctionSerialization< ExplicitFunction<T, I, L> >::serialize
107 const ExplicitFunction<T, I, L> & src,
108 INDEX_OUTPUT_ITERATOR indexOutIterator,
109 VALUE_OUTPUT_ITERATOR valueOutIterator
111 if(src.dimension()==0) {
113 *valueOutIterator=src(0);
116 *indexOutIterator=src.dimension();
118 for(
size_t i=0;i<src.dimension();++i) {
119 *indexOutIterator=src.shape(i);
122 for(
size_t i=0;i<src.size();++i) {
123 *valueOutIterator=src(i);
129 template<
class T,
class I,
class L>
130 template<
class INDEX_INPUT_ITERATOR,
class VALUE_INPUT_ITERATOR >
131 void FunctionSerialization<ExplicitFunction<T, I, L> >::deserialize
133 INDEX_INPUT_ITERATOR indexOutIterator,
134 VALUE_INPUT_ITERATOR valueOutIterator,
135 ExplicitFunction<T, I, L> & dst
137 if(*indexOutIterator==0) {
139 dst=ExplicitFunction<T, I, L>(*valueOutIterator);
142 const size_t dim=*indexOutIterator;
143 std::vector<size_t> shape(dim);
145 for(
size_t i=0;i<dim;++i) {
146 shape[i]=*indexOutIterator;
150 dst.resize(shape.begin(), shape.end() );
151 for(
size_t i=0;i<dst.size();++i) {
152 dst(i)=*valueOutIterator;
158 template<
class FUNC,
class T,
class I,
class L>
159 ExplicitFunction<T, I, L>
170 template<
class FUNC,
class T,
class I,
class L>
174 const FUNC &
function,
178 typedef ShapeWalker<typename FUNC::FunctionShapeIteratorType> Walker;
179 out.
resize(
function.functionShapeBegin(),
function.functionShapeEnd());
180 Walker walker(
function.functionShapeBegin(),
function.dimension());
181 for (I i = 0; i <
function.size(); ++i, ++walker) {
182 out(walker.coordinateTuple().begin()) =
183 function(walker.coordinateTuple().begin());
189 #endif // OPENGM_EXPLICIT_FUNCTION_HXX
ExplicitFunction< T, I, L > cloneAsExplicitFunction(const FUNC &function)
Fallback implementation of member functions of OpenGM functions.
Marray(const allocator_type &=allocator_type())
Runtime-flexible multi-dimensional views and arrays.
Marray< T, A > & operator=(const T &)
Assignment.
ExplicitFunction(const T &value)
construct a constant explicit function of order 0
Function encoded as a dense multi-dimensional array, marray::Marray.
const size_t FUNCTION_TYPE_ID_OFFSET
User-defined function have ids smaller than FUNCTION_TYPE_ID_OFFSET.
ExplicitFunction & operator=(const ExplicitFunction &other)
Runtime-flexible multi-dimensional array.
ExplicitFunction(SHAPE_ITERATOR shapeBegin, SHAPE_ITERATOR shapeEnd, const T &value)
construct a function encoded by a value table (whose entries are initialized with the same value) ...
ExplicitFunction(SHAPE_ITERATOR shapeBegin, SHAPE_ITERATOR shapeEnd)
construct a function encoded by a value table (whose entries are initialized as 0) ...
const size_t * shapeEnd() const
const size_t * shapeBegin() const
void resize(ShapeIterator, ShapeIterator, const T &=T())
ExplicitFunction(const ExplicitFunction &other)