Skip to content

Commit

Permalink
renamed varid_t to Index
Browse files Browse the repository at this point in the history
  • Loading branch information
dellaert committed Oct 11, 2010
1 parent 96eb939 commit 057050f
Show file tree
Hide file tree
Showing 68 changed files with 664 additions and 632 deletions.
2 changes: 1 addition & 1 deletion base/TestableAssertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace gtsam {
/**
* Equals testing for basic types
*/
bool assert_equal(const varid_t& expected, const varid_t& actual, double tol = 0.0) {
bool assert_equal(const Index& expected, const Index& actual, double tol = 0.0) {
if(expected != actual) {
std::cout << "Not equal:\nexpected: " << expected << "\nactual: " << actual << std::endl;
return false;
Expand Down
73 changes: 42 additions & 31 deletions base/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,48 @@

namespace gtsam {

typedef size_t varid_t;

/** Helper class that uses templates to select between two types based on
* whether TEST_TYPE is const or not.
*/
template<typename TEST_TYPE, typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
struct const_selector {};

/** Specialization for the non-const version */
template<typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
struct const_selector<BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST> {
typedef AS_NON_CONST type;
};
/** Specialization for the const version */
template<typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
struct const_selector<const BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST> {
typedef AS_CONST type;
};

/**
* Helper struct that encapsulates a value with a default, this is just used
* as a member object so you don't have to specify defaults in the class
* constructor.
*/
template<typename T, T defaultValue>
struct ValueWithDefault {
T value;
ValueWithDefault() : value(defaultValue) {}
ValueWithDefault(const T& _value) : value(_value) {}
T& operator*() { return value; }
};
/**
* Integer variable index type
*/
typedef size_t Index;

/** Helper class that uses templates to select between two types based on
* whether TEST_TYPE is const or not.
*/
template<typename TEST_TYPE, typename BASIC_TYPE, typename AS_NON_CONST,
typename AS_CONST>
struct const_selector {
};

/** Specialization for the non-const version */
template<typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
struct const_selector<BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST> {
typedef AS_NON_CONST type;
};
/** Specialization for the const version */
template<typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
struct const_selector<const BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST> {
typedef AS_CONST type;
};

/**
* Helper struct that encapsulates a value with a default, this is just used
* as a member object so you don't have to specify defaults in the class
* constructor.
*/
template<typename T, T defaultValue>
struct ValueWithDefault {
T value;
ValueWithDefault() :
value(defaultValue) {
}
ValueWithDefault(const T& _value) :
value(_value) {
}
T& operator*() {
return value;
}
};

}

2 changes: 1 addition & 1 deletion geometry/tensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace tensors {

/** index */
template<int Dim, char C> struct Index {
enum { dim = Dim };
static const int dim = Dim;
};

} // namespace tensors
Expand Down
10 changes: 5 additions & 5 deletions inference/BayesNet-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ namespace gtsam {

/* ************************************************************************* */
template<class Conditional>
list<varid_t> BayesNet<Conditional>::ordering() const {
list<varid_t> ord;
list<Index> BayesNet<Conditional>::ordering() const {
list<Index> ord;
BOOST_FOREACH(sharedConditional conditional,conditionals_)
ord.push_back(conditional->key());
return ord;
Expand All @@ -88,8 +88,8 @@ namespace gtsam {
ofstream of(s.c_str());
of<< "digraph G{\n";
BOOST_FOREACH(const_sharedConditional conditional,conditionals_) {
varid_t child = conditional->key();
BOOST_FOREACH(varid_t parent, conditional->parents()) {
Index child = conditional->key();
BOOST_FOREACH(Index parent, conditional->parents()) {
of << parent << "->" << child << endl;
}
}
Expand All @@ -101,7 +101,7 @@ namespace gtsam {

template<class Conditional>
typename BayesNet<Conditional>::sharedConditional
BayesNet<Conditional>::operator[](varid_t key) const {
BayesNet<Conditional>::operator[](Index key) const {
const_iterator it = find_if(conditionals_.begin(), conditionals_.end(), boost::lambda::bind(&Conditional::key, *boost::lambda::_1) == key);
if (it == conditionals_.end()) throw(invalid_argument((boost::format(
"BayesNet::operator['%1%']: not found") % key).str()));
Expand Down
4 changes: 2 additions & 2 deletions inference/BayesNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ namespace gtsam {
}

/** return keys in reverse topological sort order, i.e., elimination order */
std::list<varid_t> ordering() const;
std::list<Index> ordering() const;

/** SLOW O(n) random access to Conditional by key */
sharedConditional operator[](varid_t key) const;
sharedConditional operator[](Index key) const;

/** return last node in ordering */
sharedConditional& front() { return conditionals_.front(); }
Expand Down
Loading

0 comments on commit 057050f

Please sign in to comment.