From c7b1a73193d67c745c83caeff06197500502bdee Mon Sep 17 00:00:00 2001 From: jatin Date: Mon, 8 Jul 2024 16:27:59 -0700 Subject: [PATCH 1/2] Fixing undefined behaviour in examples --- .../conv1d_stateless_example.cpp | 11 ++++------- examples/custom_layer_model/custom_layer_model.cpp | 2 +- examples/hello_rtneural/hello_rtneural.cpp | 12 ++++++------ .../rtneural_static_model/rtneural_static_model.cpp | 2 +- examples/torch/torch_conv1d/torch_conv1d.cpp | 2 +- examples/torch/torch_gru/torch_gru.cpp | 2 +- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/examples/conv1d_stateless_example/conv1d_stateless_example.cpp b/examples/conv1d_stateless_example/conv1d_stateless_example.cpp index 0eba1156..c702f813 100644 --- a/examples/conv1d_stateless_example/conv1d_stateless_example.cpp +++ b/examples/conv1d_stateless_example/conv1d_stateless_example.cpp @@ -8,14 +8,11 @@ namespace fs = std::filesystem; std::string getFileFromRoot(fs::path exe_path, const std::string& path) { - // get path of RTNeural root directory - while((--exe_path.end())->string() != "RTNeural") - exe_path = exe_path.parent_path(); + auto root_path = exe_path.parent_path(); + while(root_path.filename() != "RTNeural") + root_path = root_path.parent_path(); - // get path of model file - exe_path.append(path); - - return exe_path.string(); + return root_path.append(path).string(); } int main(int /*argc*/, char* argv[]) diff --git a/examples/custom_layer_model/custom_layer_model.cpp b/examples/custom_layer_model/custom_layer_model.cpp index d97bdf49..d2d15028 100644 --- a/examples/custom_layer_model/custom_layer_model.cpp +++ b/examples/custom_layer_model/custom_layer_model.cpp @@ -16,7 +16,7 @@ namespace fs = std::filesystem; std::string getModelFile (fs::path path) { // get path of RTNeural root directory - while((--path.end())->string() != "RTNeural") + while(path.filename() != "RTNeural") path = path.parent_path(); // get path of model file diff --git a/examples/hello_rtneural/hello_rtneural.cpp b/examples/hello_rtneural/hello_rtneural.cpp index c60a5ada..805f365b 100644 --- a/examples/hello_rtneural/hello_rtneural.cpp +++ b/examples/hello_rtneural/hello_rtneural.cpp @@ -1,18 +1,18 @@ -#include -#include #include +#include +#include namespace fs = std::filesystem; -std::string getModelFile (fs::path path) +std::string getModelFile(fs::path path) { // get path of RTNeural root directory - while((--path.end())->string() != "RTNeural") + while(path.filename() != "RTNeural") path = path.parent_path(); // get path of model file path.append("examples/hello_rtneural/test_net.json"); - + return path.string(); } @@ -29,7 +29,7 @@ int main(int argc, char* argv[]) auto model = RTNeural::json_parser::parseJson(jsonStream, true); float testInput[1] = { 5.0f }; - float testOutput = model->forward (testInput); + float testOutput = model->forward(testInput); std::cout << "Test output: " << testOutput << std::endl; return 0; diff --git a/examples/rtneural_static_model/rtneural_static_model.cpp b/examples/rtneural_static_model/rtneural_static_model.cpp index bad27fda..7fe3d532 100644 --- a/examples/rtneural_static_model/rtneural_static_model.cpp +++ b/examples/rtneural_static_model/rtneural_static_model.cpp @@ -7,7 +7,7 @@ namespace fs = std::filesystem; std::string getModelFile (fs::path path) { // get path of RTNeural root directory - while((--path.end())->string() != "RTNeural") + while(path.filename() != "RTNeural") path = path.parent_path(); // get path of model file diff --git a/examples/torch/torch_conv1d/torch_conv1d.cpp b/examples/torch/torch_conv1d/torch_conv1d.cpp index 455ea6d9..eee048ef 100644 --- a/examples/torch/torch_conv1d/torch_conv1d.cpp +++ b/examples/torch/torch_conv1d/torch_conv1d.cpp @@ -7,7 +7,7 @@ namespace fs = std::filesystem; std::string getRootDir(fs::path path) { - while((--path.end())->string() != "RTNeural") + while(path.filename() != "RTNeural") path = path.parent_path(); return path.string(); } diff --git a/examples/torch/torch_gru/torch_gru.cpp b/examples/torch/torch_gru/torch_gru.cpp index e3434915..1aa62c74 100644 --- a/examples/torch/torch_gru/torch_gru.cpp +++ b/examples/torch/torch_gru/torch_gru.cpp @@ -7,7 +7,7 @@ namespace fs = std::filesystem; std::string getRootDir(fs::path path) { - while((--path.end())->string() != "RTNeural") + while(path.filename() != "RTNeural") path = path.parent_path(); return path.string(); } From 35698c43dd62481a9dda4a32063472d1128b42c4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 8 Jul 2024 23:28:50 +0000 Subject: [PATCH 2/2] Apply clang-format --- RTNeural/common.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RTNeural/common.h b/RTNeural/common.h index 7b46c8bb..29750e98 100644 --- a/RTNeural/common.h +++ b/RTNeural/common.h @@ -37,13 +37,13 @@ constexpr T ceil_div(T num, T den) namespace RTNEURAL_NAMESPACE { #if RTNEURAL_DEFAULT_ALIGNMENT == 32 - constexpr auto RTNeuralEigenAlignment = Eigen::Aligned32; +constexpr auto RTNeuralEigenAlignment = Eigen::Aligned32; #elif RTNEURAL_DEFAULT_ALIGNMENT == 16 - constexpr auto RTNeuralEigenAlignment = Eigen::Aligned16; +constexpr auto RTNeuralEigenAlignment = Eigen::Aligned16; #elif RTNEURAL_DEFAULT_ALIGNMENT == 8 - constexpr auto RTNeuralEigenAlignment = Eigen::Aligned8; +constexpr auto RTNeuralEigenAlignment = Eigen::Aligned8; #else - #error "Unsupported alignment" +#error "Unsupported alignment" #endif } // namespace RTNEURAL_NAMESPACE