Fixed VariableIndex deep copy
parent
6fb80c983d
commit
995fda8e21
|
@ -23,6 +23,20 @@ namespace gtsam {
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
VariableIndex::VariableIndex(const VariableIndex& other) :
|
||||||
|
index_(indexUnpermuted_) {
|
||||||
|
*this = other;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
VariableIndex& VariableIndex::operator=(const VariableIndex& rhs) {
|
||||||
|
index_ = rhs.index_;
|
||||||
|
nFactors_ = rhs.nFactors_;
|
||||||
|
nEntries_ = rhs.nEntries_;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void VariableIndex::permute(const Permutation& permutation) {
|
void VariableIndex::permute(const Permutation& permutation) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
|
@ -70,6 +70,16 @@ public:
|
||||||
*/
|
*/
|
||||||
template<class FactorGraph> VariableIndex(const FactorGraph& factorGraph);
|
template<class FactorGraph> VariableIndex(const FactorGraph& factorGraph);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy constructor
|
||||||
|
*/
|
||||||
|
VariableIndex(const VariableIndex& other);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assignment operator
|
||||||
|
*/
|
||||||
|
VariableIndex& operator=(const VariableIndex& rhs);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Standard Interface
|
/// @name Standard Interface
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -127,7 +137,6 @@ public:
|
||||||
*/
|
*/
|
||||||
template<typename CONTAINER, class FactorGraph> void remove(const CONTAINER& indices, const FactorGraph& factors);
|
template<typename CONTAINER, class FactorGraph> void remove(const CONTAINER& indices, const FactorGraph& factors);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a variable permutation. Does not rearrange data, just permutes
|
* Apply a variable permutation. Does not rearrange data, just permutes
|
||||||
* future lookups by variable.
|
* future lookups by variable.
|
||||||
|
|
|
@ -75,7 +75,41 @@ TEST(VariableIndex, remove) {
|
||||||
actual.remove(indices, fg1);
|
actual.remove(indices, fg1);
|
||||||
|
|
||||||
CHECK(assert_equal(expected, actual));
|
CHECK(assert_equal(expected, actual));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST(VariableIndex, deep_copy) {
|
||||||
|
|
||||||
|
SymbolicFactorGraph fg1, fg2;
|
||||||
|
fg1.push_factor(0, 1);
|
||||||
|
fg1.push_factor(0, 2);
|
||||||
|
fg1.push_factor(5, 9);
|
||||||
|
fg1.push_factor(2, 3);
|
||||||
|
fg2.push_factor(1, 3);
|
||||||
|
fg2.push_factor(2, 4);
|
||||||
|
fg2.push_factor(3, 5);
|
||||||
|
fg2.push_factor(5, 6);
|
||||||
|
|
||||||
|
// Create original graph and VariableIndex
|
||||||
|
SymbolicFactorGraph fgOriginal; fgOriginal.push_back(fg1); fgOriginal.push_back(fg2);
|
||||||
|
VariableIndex original(fgOriginal);
|
||||||
|
VariableIndex expectedOriginal(fgOriginal);
|
||||||
|
|
||||||
|
// Create a factor graph containing only the factors from fg2 and with null
|
||||||
|
// factors in the place of those of fg1, so that the factor indices are correct.
|
||||||
|
SymbolicFactorGraph fg2removed(fgOriginal);
|
||||||
|
fg2removed.remove(0); fg2removed.remove(1); fg2removed.remove(2); fg2removed.remove(3);
|
||||||
|
VariableIndex expectedRemoved(fg2removed);
|
||||||
|
|
||||||
|
// Create a clone and modify the clone - the original should not change
|
||||||
|
VariableIndex clone(original);
|
||||||
|
vector<size_t> indices;
|
||||||
|
indices.push_back(0); indices.push_back(1); indices.push_back(2); indices.push_back(3);
|
||||||
|
clone.remove(indices, fg1);
|
||||||
|
|
||||||
|
// When modifying the clone, the original should have stayed the same
|
||||||
|
EXPECT(assert_equal(expectedOriginal, original));
|
||||||
|
EXPECT(assert_equal(expectedRemoved, clone));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue