Skip to content

Commit

Permalink
Fixing undefined behaviour in examples (#142)
Browse files Browse the repository at this point in the history
* Fixing undefined behaviour in examples

* Apply clang-format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jatinchowdhury18 and github-actions[bot] authored Jul 8, 2024
1 parent 8c1847d commit f9c2c64
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 21 deletions.
8 changes: 4 additions & 4 deletions RTNeural/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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 f9c2c64

Please sign in to comment.