From 29c1816a81b245a4f599db7a47caa5a80db0f5f7 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 9 Jun 2023 20:13:06 -0400 Subject: [PATCH] change to GTSAM_DT_MERGING and expose via CMake --- cmake/HandleGeneralOptions.cmake | 1 + gtsam/config.h.in | 3 +++ gtsam/discrete/DecisionTree-inl.h | 2 +- gtsam/discrete/tests/testAlgebraicDecisionTree.cpp | 1 - gtsam/discrete/tests/testDecisionTree.cpp | 1 - 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmake/HandleGeneralOptions.cmake b/cmake/HandleGeneralOptions.cmake index 9ebb07331..c5fd9898c 100644 --- a/cmake/HandleGeneralOptions.cmake +++ b/cmake/HandleGeneralOptions.cmake @@ -19,6 +19,7 @@ option(GTSAM_FORCE_STATIC_LIB "Force gtsam to be a static library, option(GTSAM_USE_QUATERNIONS "Enable/Disable using an internal Quaternion representation for rotations instead of rotation matrices. If enable, Rot3::EXPMAP is enforced by default." OFF) option(GTSAM_POSE3_EXPMAP "Enable/Disable using Pose3::EXPMAP as the default mode. If disabled, Pose3::FIRST_ORDER will be used." ON) option(GTSAM_ROT3_EXPMAP "Ignore if GTSAM_USE_QUATERNIONS is OFF (Rot3::EXPMAP by default). Otherwise, enable Rot3::EXPMAP, or if disabled, use Rot3::CAYLEY." ON) +option(GTSAM_DT_MERGING "Enable/Disable merging of equal leaf nodes in DecisionTrees. This leads to significant speed up and memory savings." ON) option(GTSAM_ENABLE_CONSISTENCY_CHECKS "Enable/Disable expensive consistency checks" OFF) option(GTSAM_ENABLE_MEMORY_SANITIZER "Enable/Disable memory sanitizer" OFF) option(GTSAM_WITH_TBB "Use Intel Threaded Building Blocks (TBB) if available" ON) diff --git a/gtsam/config.h.in b/gtsam/config.h.in index 7f8936d1e..7c08d36bf 100644 --- a/gtsam/config.h.in +++ b/gtsam/config.h.in @@ -39,6 +39,9 @@ #cmakedefine GTSAM_ROT3_EXPMAP #endif +// Whether to enable merging of equal leaf nodes in the Discrete Decision Tree. +#cmakedefine GTSAM_DT_MERGING + // Whether we are using TBB (if TBB was found and GTSAM_WITH_TBB is enabled in CMake) #cmakedefine GTSAM_USE_TBB diff --git a/gtsam/discrete/DecisionTree-inl.h b/gtsam/discrete/DecisionTree-inl.h index 5c2b735a0..2f36007a9 100644 --- a/gtsam/discrete/DecisionTree-inl.h +++ b/gtsam/discrete/DecisionTree-inl.h @@ -212,7 +212,7 @@ namespace gtsam { f->push_back(Unique(branch)); } -#ifndef GTSAM_DT_NO_MERGING +#ifdef GTSAM_DT_MERGING // If all the branches are the same, we can merge them into one if (f->allSame_) { assert(f->branches().size() > 0); diff --git a/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp b/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp index d7e7a071c..55f5b61d7 100644 --- a/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp +++ b/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp @@ -20,7 +20,6 @@ #include // make sure we have traits #include // headers first to make sure no missing headers -//#define GTSAM_DT_NO_MERGING #include #include // for convert only #define DISABLE_TIMING diff --git a/gtsam/discrete/tests/testDecisionTree.cpp b/gtsam/discrete/tests/testDecisionTree.cpp index 0559a782b..336945503 100644 --- a/gtsam/discrete/tests/testDecisionTree.cpp +++ b/gtsam/discrete/tests/testDecisionTree.cpp @@ -18,7 +18,6 @@ */ // #define DT_DEBUG_MEMORY -// #define GTSAM_DT_NO_MERGING #define DISABLE_DOT #include #include