put Ring struct in a separate file
parent
7150f284a8
commit
9b93411d69
|
@ -20,12 +20,12 @@
|
||||||
|
|
||||||
#include <gtsam/base/Testable.h>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <gtsam/discrete/DecisionTree-inl.h>
|
#include <gtsam/discrete/DecisionTree-inl.h>
|
||||||
|
#include <gtsam/discrete/Ring.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <iomanip>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iomanip>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
@ -55,26 +55,6 @@ namespace gtsam {
|
||||||
public:
|
public:
|
||||||
using Base = DecisionTree<L, double>;
|
using Base = DecisionTree<L, double>;
|
||||||
|
|
||||||
/** The Real ring with addition and multiplication */
|
|
||||||
struct Ring {
|
|
||||||
static inline double zero() { return 0.0; }
|
|
||||||
static inline double one() { return 1.0; }
|
|
||||||
static inline double add(const double& a, const double& b) {
|
|
||||||
return a + b;
|
|
||||||
}
|
|
||||||
static inline double max(const double& a, const double& b) {
|
|
||||||
return std::max(a, b);
|
|
||||||
}
|
|
||||||
static inline double mul(const double& a, const double& b) {
|
|
||||||
return a * b;
|
|
||||||
}
|
|
||||||
static inline double div(const double& a, const double& b) {
|
|
||||||
return a / b;
|
|
||||||
}
|
|
||||||
static inline double id(const double& x) { return x; }
|
|
||||||
static inline double negate(const double& x) { return -x; }
|
|
||||||
};
|
|
||||||
|
|
||||||
AlgebraicDecisionTree(double leaf = 1.0) : Base(leaf) {}
|
AlgebraicDecisionTree(double leaf = 1.0) : Base(leaf) {}
|
||||||
|
|
||||||
// Explicitly non-explicit constructor
|
// Explicitly non-explicit constructor
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <gtsam/base/Testable.h>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <gtsam/base/debug.h>
|
#include <gtsam/base/debug.h>
|
||||||
#include <gtsam/discrete/DiscreteConditional.h>
|
#include <gtsam/discrete/DiscreteConditional.h>
|
||||||
|
#include <gtsam/discrete/Ring.h>
|
||||||
#include <gtsam/discrete/Signature.h>
|
#include <gtsam/discrete/Signature.h>
|
||||||
#include <gtsam/hybrid/HybridValues.h>
|
#include <gtsam/hybrid/HybridValues.h>
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ DiscreteConditional DiscreteConditional::operator*(
|
||||||
// Finally, add parents to keys, in order
|
// Finally, add parents to keys, in order
|
||||||
for (auto&& dk : parents) discreteKeys.push_back(dk);
|
for (auto&& dk : parents) discreteKeys.push_back(dk);
|
||||||
|
|
||||||
ADT product = ADT::apply(other, ADT::Ring::mul);
|
ADT product = ADT::apply(other, Ring::mul);
|
||||||
return DiscreteConditional(newFrontals.size(), discreteKeys, product);
|
return DiscreteConditional(newFrontals.size(), discreteKeys, product);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||||
|
* Atlanta, Georgia 30332-0415
|
||||||
|
* All Rights Reserved
|
||||||
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
||||||
|
|
||||||
|
* See LICENSE for the license information
|
||||||
|
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file Ring.h
|
||||||
|
* @brief Real Ring definition
|
||||||
|
* @author Varun Agrawal
|
||||||
|
* @date Dec 8, 2024
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
/** The Real ring with addition and multiplication */
|
||||||
|
struct Ring {
|
||||||
|
static inline double zero() { return 0.0; }
|
||||||
|
static inline double one() { return 1.0; }
|
||||||
|
static inline double add(const double& a, const double& b) { return a + b; }
|
||||||
|
static inline double max(const double& a, const double& b) {
|
||||||
|
return std::max(a, b);
|
||||||
|
}
|
||||||
|
static inline double mul(const double& a, const double& b) { return a * b; }
|
||||||
|
static inline double div(const double& a, const double& b) {
|
||||||
|
return (a == 0 || b == 0) ? 0 : (a / b);
|
||||||
|
}
|
||||||
|
static inline double id(const double& x) { return x; }
|
||||||
|
static inline double negate(const double& x) { return -x; }
|
||||||
|
};
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <gtsam/discrete/DiscreteFactor.h>
|
#include <gtsam/discrete/DiscreteFactor.h>
|
||||||
#include <gtsam/discrete/DiscreteKey.h>
|
#include <gtsam/discrete/DiscreteKey.h>
|
||||||
|
#include <gtsam/discrete/Ring.h>
|
||||||
#include <gtsam/inference/Ordering.h>
|
#include <gtsam/inference/Ordering.h>
|
||||||
|
|
||||||
#include <Eigen/Sparse>
|
#include <Eigen/Sparse>
|
||||||
|
@ -99,21 +100,6 @@ class GTSAM_EXPORT TableFactor : public DiscreteFactor {
|
||||||
using Binary = std::function<double(const double, const double)>;
|
using Binary = std::function<double(const double, const double)>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** The Real ring with addition and multiplication */
|
|
||||||
struct Ring {
|
|
||||||
static inline double zero() { return 0.0; }
|
|
||||||
static inline double one() { return 1.0; }
|
|
||||||
static inline double add(const double& a, const double& b) { return a + b; }
|
|
||||||
static inline double max(const double& a, const double& b) {
|
|
||||||
return std::max(a, b);
|
|
||||||
}
|
|
||||||
static inline double mul(const double& a, const double& b) { return a * b; }
|
|
||||||
static inline double div(const double& a, const double& b) {
|
|
||||||
return (a == 0 || b == 0) ? 0 : (a / b);
|
|
||||||
}
|
|
||||||
static inline double id(const double& x) { return x; }
|
|
||||||
};
|
|
||||||
|
|
||||||
/// @name Standard Constructors
|
/// @name Standard Constructors
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <gtsam/base/Testable.h>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <gtsam/base/serializationTestHelpers.h>
|
#include <gtsam/base/serializationTestHelpers.h>
|
||||||
#include <gtsam/discrete/DecisionTree-inl.h>
|
#include <gtsam/discrete/DecisionTree-inl.h>
|
||||||
|
#include <gtsam/discrete/Ring.h>
|
||||||
#include <gtsam/discrete/Signature.h>
|
#include <gtsam/discrete/Signature.h>
|
||||||
#include <gtsam/inference/Symbol.h>
|
#include <gtsam/inference/Symbol.h>
|
||||||
|
|
||||||
|
@ -124,14 +125,6 @@ struct traits<DT> : public Testable<DT> {};
|
||||||
|
|
||||||
GTSAM_CONCEPT_TESTABLE_INST(DT)
|
GTSAM_CONCEPT_TESTABLE_INST(DT)
|
||||||
|
|
||||||
struct Ring {
|
|
||||||
static inline int zero() { return 0; }
|
|
||||||
static inline int one() { return 1; }
|
|
||||||
static inline int id(const int& a) { return a; }
|
|
||||||
static inline int add(const int& a, const int& b) { return a + b; }
|
|
||||||
static inline int mul(const int& a, const int& b) { return a * b; }
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
// Check that creating decision trees respects key order.
|
// Check that creating decision trees respects key order.
|
||||||
TEST(DecisionTree, ConstructorOrder) {
|
TEST(DecisionTree, ConstructorOrder) {
|
||||||
|
|
Loading…
Reference in New Issue