From ef1878a9442be3063bf941cdf4a98a8b9a944bbf Mon Sep 17 00:00:00 2001 From: Nathaniel Chinn Date: Thu, 11 May 2023 15:52:35 -0600 Subject: [PATCH 1/4] Add support for in placement new operator w/o new lib --- cpp/neuralnet.hpp | 20 ++++++++++++++++++++ cpp/qformat.hpp | 7 +++++++ cpp/qlearn.hpp | 16 +++++++++++++++- examples/maze/Makefile | 6 ++++++ examples/maze/maze.cpp | 7 +++++++ examples/maze/mazelearner.h | 2 ++ 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/cpp/neuralnet.hpp b/cpp/neuralnet.hpp index 5fa85e5..e7e3cb4 100644 --- a/cpp/neuralnet.hpp +++ b/cpp/neuralnet.hpp @@ -1201,6 +1201,12 @@ namespace tinymind { this->mWeight = value; } +#if !(defined(_LIB_NEW) || defined(_NEW)) + void * operator new(size_t, void *p) + { + return p; + } +#endif protected: ValueType mWeight; }; @@ -1323,6 +1329,13 @@ namespace tinymind { this->mOutputValue = value; } +#if !(defined(_LIB_NEW) || defined(_NEW)) + void * operator new(size_t, void *p) + { + return p; + } +#endif + protected: // Don't instantiate class. Only for use by child classses Neuron() { @@ -1960,6 +1973,13 @@ namespace tinymind { NeuronType* pNeuron = reinterpret_cast(&this->mNeuronsBuffer[bufferIndex]); pNeuron->setWeightForConnection(connection, weight); } + +#if !(defined(_LIB_NEW) || defined(_NEW)) + void * operator new(size_t, void *p) + { + return p; + } +#endif protected: Layer() { diff --git a/cpp/qformat.hpp b/cpp/qformat.hpp index 7b2e4cd..3e2e0c7 100644 --- a/cpp/qformat.hpp +++ b/cpp/qformat.hpp @@ -400,6 +400,13 @@ namespace tinymind { return (mValue.getValue() != value); } +#if !(defined(_LIB_NEW) || defined(_NEW)) + void * operator new(size_t, void *p) + { + return p; + } +#endif + #if TINYMIND_ENABLE_OSTREAMS friend std::ostream& operator<<(std::ostream& os, const QValue& value) { diff --git a/cpp/qlearn.hpp b/cpp/qlearn.hpp index a15d8d9..de9a944 100644 --- a/cpp/qlearn.hpp +++ b/cpp/qlearn.hpp @@ -338,7 +338,7 @@ namespace tinymind { typedef typename EnvironmentType::EnvironmentStateType StateType; typedef typename EnvironmentType::EnvironmentActionType ActionType; typedef typename EnvironmentType::EnvironmentValueType ValueType; - + static ActionType selectBestActionForState(const StateType state, ActionType const* const actions, const size_t numberOfValidActions, const QLearnerQValuePolicy& qValuePolicy) { ActionType bestAction; @@ -526,6 +526,13 @@ namespace tinymind { } } } + +#if !(defined(_LIB_NEW) || defined(_NEW)) + void * operator new(size_t, void *p) + { + return p; + } +#endif private: void copyNetworkWeights() { @@ -652,6 +659,13 @@ namespace tinymind { this->mState = experience.newState; } + +#if !(defined(_LIB_NEW) || defined(_NEW)) + void * operator new(size_t, void *p) + { + return p; + } +#endif private: // Private methods ValueType calculateFutureQValue(const StateType state) diff --git a/examples/maze/Makefile b/examples/maze/Makefile index dc0b6e8..8437ea2 100644 --- a/examples/maze/Makefile +++ b/examples/maze/Makefile @@ -11,6 +11,12 @@ debug : # Build the example with default build flags g++ -g -Wall -o ./output/maze maze.cpp mazelearner.cpp -I../../cpp +nonewlib : +# Make an output dir to hold the executable + mkdir -p ./output +# Build the example with default build flags and do not include the new library + g++ -O3 -Wall -o ./output/maze maze.cpp mazelearner.cpp -I../../cpp -DTINYMIND_DISABLE_NEW_LIB=1 + # Remove all object files clean: rm -f ./output/* diff --git a/examples/maze/maze.cpp b/examples/maze/maze.cpp index e33ec39..822167c 100644 --- a/examples/maze/maze.cpp +++ b/examples/maze/maze.cpp @@ -57,6 +57,13 @@ The paths out of the maze: #include "mazelearner.h" +#if !(defined(_LIB_NEW) || defined(_NEW)) +void * operator new(size_t, void *p) +{ + return p; +} +#endif + extern QLearnerType qLearner; int main(const int argc, char *argv[]) diff --git a/examples/maze/mazelearner.h b/examples/maze/mazelearner.h index 343283d..aac947d 100644 --- a/examples/maze/mazelearner.h +++ b/examples/maze/mazelearner.h @@ -25,7 +25,9 @@ #include #include #include +#if !(TINYMIND_DISBLE_NEW_LIB) #include +#endif #include "qformat.hpp" #include "qlearn.hpp" From 4ea22cc1be2aaf4cbc3f958ec99db91b1318259f Mon Sep 17 00:00:00 2001 From: Nathaniel Chinn Date: Fri, 12 May 2023 11:57:14 -0600 Subject: [PATCH 2/4] remove build flags --- cpp/neuralnet.hpp | 6 ------ cpp/qformat.hpp | 2 -- cpp/qlearn.hpp | 4 ---- examples/maze/Makefile | 6 ------ examples/maze/maze.cpp | 7 ------- examples/maze/mazelearner.h | 2 -- 6 files changed, 27 deletions(-) diff --git a/cpp/neuralnet.hpp b/cpp/neuralnet.hpp index e7e3cb4..3e0905a 100644 --- a/cpp/neuralnet.hpp +++ b/cpp/neuralnet.hpp @@ -1201,12 +1201,10 @@ namespace tinymind { this->mWeight = value; } -#if !(defined(_LIB_NEW) || defined(_NEW)) void * operator new(size_t, void *p) { return p; } -#endif protected: ValueType mWeight; }; @@ -1329,12 +1327,10 @@ namespace tinymind { this->mOutputValue = value; } -#if !(defined(_LIB_NEW) || defined(_NEW)) void * operator new(size_t, void *p) { return p; } -#endif protected: // Don't instantiate class. Only for use by child classses Neuron() @@ -1974,12 +1970,10 @@ namespace tinymind { pNeuron->setWeightForConnection(connection, weight); } -#if !(defined(_LIB_NEW) || defined(_NEW)) void * operator new(size_t, void *p) { return p; } -#endif protected: Layer() { diff --git a/cpp/qformat.hpp b/cpp/qformat.hpp index 3e2e0c7..e6ede28 100644 --- a/cpp/qformat.hpp +++ b/cpp/qformat.hpp @@ -400,12 +400,10 @@ namespace tinymind { return (mValue.getValue() != value); } -#if !(defined(_LIB_NEW) || defined(_NEW)) void * operator new(size_t, void *p) { return p; } -#endif #if TINYMIND_ENABLE_OSTREAMS friend std::ostream& operator<<(std::ostream& os, const QValue& value) diff --git a/cpp/qlearn.hpp b/cpp/qlearn.hpp index de9a944..6c96af4 100644 --- a/cpp/qlearn.hpp +++ b/cpp/qlearn.hpp @@ -527,12 +527,10 @@ namespace tinymind { } } -#if !(defined(_LIB_NEW) || defined(_NEW)) void * operator new(size_t, void *p) { return p; } -#endif private: void copyNetworkWeights() { @@ -660,12 +658,10 @@ namespace tinymind { this->mState = experience.newState; } -#if !(defined(_LIB_NEW) || defined(_NEW)) void * operator new(size_t, void *p) { return p; } -#endif private: // Private methods ValueType calculateFutureQValue(const StateType state) diff --git a/examples/maze/Makefile b/examples/maze/Makefile index 8437ea2..dc0b6e8 100644 --- a/examples/maze/Makefile +++ b/examples/maze/Makefile @@ -11,12 +11,6 @@ debug : # Build the example with default build flags g++ -g -Wall -o ./output/maze maze.cpp mazelearner.cpp -I../../cpp -nonewlib : -# Make an output dir to hold the executable - mkdir -p ./output -# Build the example with default build flags and do not include the new library - g++ -O3 -Wall -o ./output/maze maze.cpp mazelearner.cpp -I../../cpp -DTINYMIND_DISABLE_NEW_LIB=1 - # Remove all object files clean: rm -f ./output/* diff --git a/examples/maze/maze.cpp b/examples/maze/maze.cpp index 822167c..e33ec39 100644 --- a/examples/maze/maze.cpp +++ b/examples/maze/maze.cpp @@ -57,13 +57,6 @@ The paths out of the maze: #include "mazelearner.h" -#if !(defined(_LIB_NEW) || defined(_NEW)) -void * operator new(size_t, void *p) -{ - return p; -} -#endif - extern QLearnerType qLearner; int main(const int argc, char *argv[]) diff --git a/examples/maze/mazelearner.h b/examples/maze/mazelearner.h index aac947d..343283d 100644 --- a/examples/maze/mazelearner.h +++ b/examples/maze/mazelearner.h @@ -25,9 +25,7 @@ #include #include #include -#if !(TINYMIND_DISBLE_NEW_LIB) #include -#endif #include "qformat.hpp" #include "qlearn.hpp" From 77ed7901584d28b9593f3ebac22fa16c6ad26031 Mon Sep 17 00:00:00 2001 From: Nathaniel Chinn Date: Fri, 12 May 2023 13:39:31 -0600 Subject: [PATCH 3/4] remove unneeded placement new ops --- cpp/qlearn.hpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/cpp/qlearn.hpp b/cpp/qlearn.hpp index 6c96af4..cf351d1 100644 --- a/cpp/qlearn.hpp +++ b/cpp/qlearn.hpp @@ -338,7 +338,7 @@ namespace tinymind { typedef typename EnvironmentType::EnvironmentStateType StateType; typedef typename EnvironmentType::EnvironmentActionType ActionType; typedef typename EnvironmentType::EnvironmentValueType ValueType; - + static ActionType selectBestActionForState(const StateType state, ActionType const* const actions, const size_t numberOfValidActions, const QLearnerQValuePolicy& qValuePolicy) { ActionType bestAction; @@ -527,10 +527,6 @@ namespace tinymind { } } - void * operator new(size_t, void *p) - { - return p; - } private: void copyNetworkWeights() { @@ -657,11 +653,6 @@ namespace tinymind { this->mState = experience.newState; } - - void * operator new(size_t, void *p) - { - return p; - } private: // Private methods ValueType calculateFutureQValue(const StateType state) From 86324192fe95f78edcfa2527aba04ddb4d98c882 Mon Sep 17 00:00:00 2001 From: Nathaniel Chinn Date: Fri, 12 May 2023 13:56:15 -0600 Subject: [PATCH 4/4] remove extra whitespace --- cpp/qlearn.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/cpp/qlearn.hpp b/cpp/qlearn.hpp index cf351d1..a15d8d9 100644 --- a/cpp/qlearn.hpp +++ b/cpp/qlearn.hpp @@ -526,7 +526,6 @@ namespace tinymind { } } } - private: void copyNetworkWeights() {