/usr/include/opengm/utilities/indexing.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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | #pragma once
#ifndef OPENGM_INDEXING_HXX
#define OPENGM_INDEXING_HXX
#include "opengm/opengm.hxx"
#include "opengm/datastructures/fast_sequence.hxx"
namespace opengm {
/// \cond HIDDEN_SYMBOLS
template<class VECTOR>
bool isEqualValueVector(const VECTOR vector) {
for(size_t i=0;i<vector.size();++i) {
if(vector[0]!=vector[i]) {
return false;
}
}
return true;
}
/// walk over a factor / function , and some variables can be fixed
template<class Iterator,class FIXED_COORDINATE_INDEX_CONTAINER,class FIXED_COORDINATE_VALUE_CONTAINER>
class SubShapeWalker{
public:
/// constructor
/// \param shapeBegin begin of the shape of the function
/// \param dimension size of the function / shape
/// \param fixedCoordinateIndex container/ random access iterator which contains the position of the variables to fix
/// \param fixedCoordinateValue container/ random access iterator which contains the values of the variables which are fixed
SubShapeWalker
(
Iterator shapeBegin,
const size_t dimension,
const FIXED_COORDINATE_INDEX_CONTAINER & fixedCoordinateIndex,
const FIXED_COORDINATE_VALUE_CONTAINER & fixedCoordinateValue
)
: shapeBegin_(shapeBegin),
coordinateTuple_(dimension,0),
fixedCoordinateValue_(fixedCoordinateValue),
fixedCoordinateIndex_(fixedCoordinateIndex),
dimension_(dimension) {
for(size_t d = 0; d < fixedCoordinateIndex_.size(); ++d) {
coordinateTuple_[fixedCoordinateIndex_[d]] = fixedCoordinateValue_[d];
}
};
/// reset coordinate to zeros
void resetCoordinate() {
for(size_t i = 0; i < dimension_; ++i) {
coordinateTuple_[i] = static_cast<size_t>(0);
}
for(size_t i = 0; i < fixedCoordinateIndex_.size(); ++i) {
coordinateTuple_[fixedCoordinateIndex_[i]] = fixedCoordinateValue_[i];
}
};
/// increment coordinate in last - coordinate major order (therefore the first coordinate is incremented first)
inline SubShapeWalker & operator++() {
size_t counter = 0;
for(size_t d = 0; d < dimension_; ++d) {
bool atFixedValue = false;
for(size_t i = counter; i < fixedCoordinateIndex_.size(); ++i) {
if(d == fixedCoordinateIndex_[i]) {
atFixedValue = true;
++counter;
}
}
if(atFixedValue == false) {
if(coordinateTuple_[d] != shapeBegin_[d] - 1) {
coordinateTuple_[d]++;
break;
}
else {
if(d != dimension_ - 1) {
coordinateTuple_[d] = 0;
}
else {
coordinateTuple_[d]++;
break;
}
}
}
}
return *this;
};
/// get the coordinate tuple
const opengm::FastSequence<size_t> & coordinateTuple()const {
return coordinateTuple_;
};
/// get the number of elements over which one wants to walk
size_t subSize() {
size_t result = 1;
size_t counter = 0;
for(size_t d = 0; d < dimension_; ++d) {
bool fixedVal = false;
for(size_t i = counter; i < fixedCoordinateIndex_.size(); ++i) {
if(d == fixedCoordinateIndex_[i]) ///??? replace i with counter for old version
{
fixedVal = true;
counter++;
break;
}
}
if(fixedVal == false) {
result *= shapeBegin_[d];
}
}
return result;
}
private:
Iterator shapeBegin_;
opengm::FastSequence<size_t> coordinateTuple_;
const FIXED_COORDINATE_VALUE_CONTAINER & fixedCoordinateValue_;
const FIXED_COORDINATE_INDEX_CONTAINER & fixedCoordinateIndex_;
const size_t dimension_;
//size_t subSize_;
};
template<class Iterator>
class ShapeWalker
{
public:
ShapeWalker(Iterator shapeBegin,size_t dimension)
: shapeBegin_(shapeBegin),
coordinateTuple_(dimension, 0),
dimension_(dimension) { }
ShapeWalker & operator++() {
for(size_t d = 0; d < dimension_; ++d) {
if( size_t(coordinateTuple_[d]) != (size_t(shapeBegin_[d]) - size_t(1)) ) {
++coordinateTuple_[d];
OPENGM_ASSERT(coordinateTuple_[d]<shapeBegin_[d]);
break;
}
else {
if(d != dimension_ - 1) {
coordinateTuple_[d] = 0;
}
else {
coordinateTuple_[d]++;
break;
}
}
}
return *this;
};
const opengm::FastSequence<size_t> & coordinateTuple()const {
return coordinateTuple_;
};
void reset(){
std::fill(coordinateTuple_.begin(),coordinateTuple_.end(),0);
}
private:
Iterator shapeBegin_;
opengm::FastSequence<size_t> coordinateTuple_;
const size_t dimension_;
};
template<class Iterator>
class ShapeWalkerSwitchedOrder
{
public:
ShapeWalkerSwitchedOrder(Iterator shapeBegin,size_t dimension)
: shapeBegin_(shapeBegin),
coordinateTuple_(dimension, 0),
dimension_(dimension) { }
ShapeWalkerSwitchedOrder & operator++() {
for(size_t d = dimension_-1; true; --d) {
if( size_t(coordinateTuple_[d]) != (size_t(shapeBegin_[d]) - size_t(1)) ) {
++coordinateTuple_[d];
OPENGM_ASSERT(coordinateTuple_[d]<shapeBegin_[d]);
break;
}
else {
if(d != 0) {
coordinateTuple_[d] = 0;
}
else {
coordinateTuple_[d]++;
break;
}
}
//if(d==0){
// break;
//}
}
return *this;
};
const opengm::FastSequence<size_t> & coordinateTuple()const {
return coordinateTuple_;
};
private:
Iterator shapeBegin_;
opengm::FastSequence<size_t> coordinateTuple_;
const size_t dimension_;
};
template<class SHAPE_AB_ITERATOR>
class TripleShapeWalker{
public:
template<class VI_AB,class VI_A,class VI_B>
TripleShapeWalker
(
SHAPE_AB_ITERATOR shapeABBegin,
const size_t dimAB,
const VI_AB & viAB,
const VI_A & viA,
const VI_B & viB
): shapeABBegin_(shapeABBegin),
dimensionAB_(dimAB),
coordinateTupleAB_(viAB.size(), 0),
coordinateTupleA_(viA.size(), 0),
coordinateTupleB_(viB.size(), 0),
viMatchA_(viAB.size(), false),
viMatchB_(viAB.size(), false),
viMatchIndexA_(viAB.size()),
viMatchIndexB_(viAB.size()) {
OPENGM_ASSERT(dimAB == viAB.size());
OPENGM_ASSERT( viA.size() != 0);
OPENGM_ASSERT( viB.size() != 0);
//vi matching:
size_t counterA = 0;
size_t counterB = 0;
for(size_t d = 0; d < dimensionAB_; ++d) {
if(counterA<viA.size()) {
if(viAB[d] == viA[counterA]) {
viMatchA_[d] = true;
viMatchIndexA_[d] = counterA;
counterA++;
}
}
if(counterB<viB.size()) {
if(viAB[d] == viB[counterB]) {
viMatchB_[d] = true;
viMatchIndexB_[d] = counterB;
counterB++;
}
}
}
}
TripleShapeWalker & operator++() {
for(size_t d = 0; d < dimensionAB_; ++d) {
if( int (coordinateTupleAB_[d]) != int( int(shapeABBegin_[d]) - int(1))) {
coordinateTupleAB_[d]++;
if(viMatchA_[d]) {
coordinateTupleA_[viMatchIndexA_[d]]++;
}
if(viMatchB_[d]) {
coordinateTupleB_[viMatchIndexB_[d]]++;
}
break;
}
else {
coordinateTupleAB_[d] = 0;
if(viMatchA_[d]) {
coordinateTupleA_[viMatchIndexA_[d]] = 0;
}
if(viMatchB_[d]) {
coordinateTupleB_[viMatchIndexB_[d]] = 0;
}
}
}
return *this;
};
const opengm::FastSequence<size_t> &coordinateTupleA()const {
return coordinateTupleA_;
};
const opengm::FastSequence<size_t> & coordinateTupleB()const {
return coordinateTupleB_;
};
const opengm::FastSequence<size_t> & coordinateTupleAB()const {
return coordinateTupleAB_;
};
private:
SHAPE_AB_ITERATOR shapeABBegin_;
const size_t dimensionAB_;
opengm::FastSequence<size_t> coordinateTupleAB_;
opengm::FastSequence<size_t> coordinateTupleA_;
opengm::FastSequence<size_t> coordinateTupleB_;
opengm::FastSequence<bool> viMatchA_;
opengm::FastSequence<bool> viMatchB_;
opengm::FastSequence<size_t> viMatchIndexA_;
opengm::FastSequence<size_t> viMatchIndexB_;
};
template<class SHAPE_AB_ITERATOR>
class DoubleShapeWalker {
public:
template<class VI_A,class VI_B>
DoubleShapeWalker
(
SHAPE_AB_ITERATOR shapeABbegin,
const size_t dimAb,
const VI_A & viAB,
const VI_B & viA
)
:shapeABbegin_(shapeABbegin),
dimensionAB_(dimAb),
coordinateTupleAB_(dimensionAB_, 0),
coordinateTupleA_(viA.size(), 0),
viMatchA_(dimensionAB_, false),
viMatchIndexA_(dimensionAB_) {
//vi matching:
size_t counterA = 0;
for(size_t d = 0; d < dimensionAB_; ++d) {
for(size_t i = counterA; i < viA.size(); ++i) {
if(viAB[d] == viA[i]) {
viMatchA_[d] = true;
viMatchIndexA_[d] = i;
++counterA;
}
}
}
}
DoubleShapeWalker & operator++() {
for(size_t d = 0; d < dimensionAB_; ++d) {
if(coordinateTupleAB_[d] != shapeABbegin_[d] - 1) {
coordinateTupleAB_[d]++;
if(viMatchA_[d] == true) {
coordinateTupleA_[viMatchIndexA_[d]]++;
}
break;
}
else {
coordinateTupleAB_[d] = 0;
if(viMatchA_[d] == true) {
coordinateTupleA_[viMatchIndexA_[d]] = 0;
}
}
}
return *this;
};
const opengm::FastSequence<size_t> & coordinateTupleA()const {
return coordinateTupleA_;
};
const opengm::FastSequence<size_t> & coordinateTupleAB()const {
return coordinateTupleAB_;
};
private:
SHAPE_AB_ITERATOR shapeABbegin_;
const size_t dimensionAB_;
opengm::FastSequence<size_t> coordinateTupleAB_;
opengm::FastSequence<size_t> coordinateTupleA_;
opengm::FastSequence<bool> viMatchA_;
opengm::FastSequence<size_t> viMatchIndexA_;
};
} // namespace opengm
#endif // #ifndef OPENGM_INDEXING_HXX
|