Skip to content

Commit

Permalink
Fixing undefined behaviour in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Jul 8, 2024
1 parent 8c1847d commit c7b1a73
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
11 changes: 4 additions & 7 deletions examples/conv1d_stateless_example/conv1d_stateless_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_layer_model/custom_layer_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions examples/hello_rtneural/hello_rtneural.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include <iostream>
#include <filesystem>
#include <RTNeural/RTNeural.h>
#include <filesystem>
#include <iostream>

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();
}

Expand All @@ -29,7 +29,7 @@ int main(int argc, char* argv[])
auto model = RTNeural::json_parser::parseJson<float>(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;
Expand Down
2 changes: 1 addition & 1 deletion examples/rtneural_static_model/rtneural_static_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/torch/torch_conv1d/torch_conv1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/torch/torch_gru/torch_gru.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit c7b1a73

Please sign in to comment.