Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing undefined behaviour in examples #142

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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