From 4a4de532dc3a539a075e6d648ce3129b13cc544f Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Sat, 6 Mar 2021 17:56:00 -0500 Subject: [PATCH] Move initialization of static members into a cpp file. --- .../environment/CMakeLists.txt | 1 + .../environment/env_type.cpp | 27 +++++++++++++++++++ .../environment/env_type.hpp | 4 --- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/mlpack/methods/reinforcement_learning/environment/env_type.cpp diff --git a/src/mlpack/methods/reinforcement_learning/environment/CMakeLists.txt b/src/mlpack/methods/reinforcement_learning/environment/CMakeLists.txt index 04e5b8b2a8..f93995ab75 100644 --- a/src/mlpack/methods/reinforcement_learning/environment/CMakeLists.txt +++ b/src/mlpack/methods/reinforcement_learning/environment/CMakeLists.txt @@ -2,6 +2,7 @@ # Anything not in this list will not be compiled into mlpack. set(SOURCES env_type.hpp + env_type.cpp mountain_car.hpp cart_pole.hpp continuous_mountain_car.hpp diff --git a/src/mlpack/methods/reinforcement_learning/environment/env_type.cpp b/src/mlpack/methods/reinforcement_learning/environment/env_type.cpp new file mode 100644 index 0000000000..d5363b5501 --- /dev/null +++ b/src/mlpack/methods/reinforcement_learning/environment/env_type.cpp @@ -0,0 +1,27 @@ +/** + * @file methods/reinforcement_learning/environment/env_type.cpp + * @author Nishant Kumar + * + * This file defines the static variables used by the discrete and continuous + * environments. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#include "env_type.hpp" + +namespace mlpack { +namespace rl { + +// Instantiate static members. + +size_t DiscreteActionEnv::State::dimension = 0; +size_t DiscreteActionEnv::Action::size = 0; + +size_t ContinuousActionEnv::State::dimension = 0; +size_t ContinuousActionEnv::Action::size = 0; + +} // namespace rl +} // namespace mlpack diff --git a/src/mlpack/methods/reinforcement_learning/environment/env_type.hpp b/src/mlpack/methods/reinforcement_learning/environment/env_type.hpp index e8513e3bb9..4fcf797322 100644 --- a/src/mlpack/methods/reinforcement_learning/environment/env_type.hpp +++ b/src/mlpack/methods/reinforcement_learning/environment/env_type.hpp @@ -105,8 +105,6 @@ class DiscreteActionEnv */ bool IsTerminal(const State& /* state */) const { return false; } }; -size_t DiscreteActionEnv::State::dimension = 0; -size_t DiscreteActionEnv::Action::size = 0; /** * To use the dummy environment, one may start by specifying the state and @@ -201,8 +199,6 @@ class ContinuousActionEnv */ bool IsTerminal(const State& /* state */) const { return false; } }; -size_t ContinuousActionEnv::State::dimension = 0; -size_t ContinuousActionEnv::Action::size = 0; } // namespace rl } // namespace mlpack