- /// Tool for looping over the states of several variables.
- /** The class IndexFor is an important tool for indexing of Factors.
- * Its usage can best be explained by an example.
- * Assume indexVars, forVars are two VarSets.
- * Then the following code:
- * \code
- * IndexFor i( indexVars, forVars );
- * for( ; i >= 0; ++i ) {
- * // use long(i)
- * }
- * \endcode
- * loops over all joint states of the variables in forVars,
- * and (long)i is equal to the linear index of the corresponding
- * state of indexVars, where the variables in indexVars that are
- * not in forVars assume their zero'th value.
- */
- class IndexFor {
- private:
- /// The current linear index corresponding to the state of indexVars
- long _index;
-
- /// For each variable in forVars, the amount of change in _index
- std::vector<long> _sum;
-
- /// For each variable in forVars, the current state
- std::vector<size_t> _count;
-
- /// For each variable in forVars, its number of possible values
- std::vector<size_t> _dims;
-
- public:
- /// Default constructor
- IndexFor() {
- _index = -1;
- }
+/// Tool for looping over the states of several variables.
+/** The class IndexFor is an important tool for indexing Factor entries.
+ * Its usage can best be explained by an example.
+ * Assume indexVars, forVars are both VarSets.
+ * Then the following code:
+ * \code
+ * IndexFor i( indexVars, forVars );
+ * for( ; i >= 0; ++i ) {
+ * // use long(i)
+ * }
+ * \endcode
+ * loops over all joint states of the variables in forVars,
+ * and (long)i is equal to the linear index of the corresponding
+ * state of indexVars, where the variables in indexVars that are
+ * not in forVars assume their zero'th value.
+ * \idea Optimize all indices as follows: keep a cache of all (or only
+ * relatively small) indices that have been computed (use a hash). Then,
+ * instead of computing on the fly, use the precomputed ones.
+ */
+class IndexFor {
+ private:
+ /// The current linear index corresponding to the state of indexVars
+ long _index;