From 0b0e5d0b2bd635730e242da2ca511adf8500127d Mon Sep 17 00:00:00 2001 From: jatinchowdhury18 Date: Thu, 22 Feb 2024 11:07:56 -0800 Subject: [PATCH] Using std::integral_constant for model_detail::forEachInTuple (#129) * Using std::integral_constant for model_detail::forEachInTuple * Apply clang-format --------- Co-authored-by: github-actions[bot] --- RTNeural/ModelT.h | 4 ++-- RTNeural/RTNeural.h | 2 +- RTNeural/config.h | 4 ++-- RTNeural/conv1d/conv1d.h | 6 +++--- RTNeural/conv1d/conv1d_eigen.h | 6 +++--- RTNeural/conv1d/conv1d_xsimd.h | 8 ++++---- RTNeural/dense/dense_xsimd.h | 2 +- tests/functional/torch_conv1d_test.cpp | 2 +- tests/functional/torch_microtcn_test.cpp | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/RTNeural/ModelT.h b/RTNeural/ModelT.h index f3278c1..745be60 100644 --- a/RTNeural/ModelT.h +++ b/RTNeural/ModelT.h @@ -29,9 +29,9 @@ namespace modelt_detail /** Functions to do a function for each element in the tuple */ template - constexpr void forEachInTuple(Fn&& fn, Tuple&& tuple, std::index_sequence) noexcept(noexcept(std::initializer_list { (fn(std::get(tuple), Ix), 0)... })) + constexpr void forEachInTuple(Fn&& fn, Tuple&& tuple, std::index_sequence) noexcept(noexcept(std::initializer_list { (fn(std::get(tuple), std::integral_constant()), 0)... })) { - (void)std::initializer_list { ((void)fn(std::get(tuple), Ix), 0)... }; + (void)std::initializer_list { ((void)fn(std::get(tuple), std::integral_constant()), 0)... }; } template diff --git a/RTNeural/RTNeural.h b/RTNeural/RTNeural.h index 18a59d3..9e92c81 100644 --- a/RTNeural/RTNeural.h +++ b/RTNeural/RTNeural.h @@ -6,8 +6,8 @@ #include // RTNeural includes: -#include "config.h" #include "Model.h" #include "ModelT.h" +#include "config.h" #include "model_loader.h" #include "torch_helpers.h" diff --git a/RTNeural/config.h b/RTNeural/config.h index 5b8ad26..ac85f37 100644 --- a/RTNeural/config.h +++ b/RTNeural/config.h @@ -31,7 +31,7 @@ for which instructions may be found in the RADSan repository above. */ #ifdef RTNEURAL_RADSAN_ENABLED - #define RTNEURAL_REALTIME [[clang::realtime]] +#define RTNEURAL_REALTIME [[clang::realtime]] #else - #define RTNEURAL_REALTIME +#define RTNEURAL_REALTIME #endif diff --git a/RTNeural/conv1d/conv1d.h b/RTNeural/conv1d/conv1d.h index 253e4c7..e161c31 100644 --- a/RTNeural/conv1d/conv1d.h +++ b/RTNeural/conv1d/conv1d.h @@ -59,7 +59,7 @@ class Conv1D final : public Layer // set state pointers to particular columns of the buffer setStatePointers(); - if (groups == 1) + if(groups == 1) { // copy selected columns to a helper variable for(int k = 0; k < kernel_size; ++k) @@ -198,7 +198,7 @@ class Conv1DT /** Resets the layer state. */ RTNEURAL_REALTIME void reset(); - template = true> + template = true> /** Performs forward propagation for this layer. */ RTNEURAL_REALTIME inline void forward(const T (&ins)[in_size]) noexcept { @@ -230,7 +230,7 @@ class Conv1DT state_ptr = (state_ptr == state_size - 1 ? 0 : state_ptr + 1); // iterate state pointer forwards } - template = true> + template = true> /** Performs forward propagation for this layer. */ inline void forward(const T (&ins)[in_size]) noexcept { diff --git a/RTNeural/conv1d/conv1d_eigen.h b/RTNeural/conv1d/conv1d_eigen.h index 2b3b095..582d819 100644 --- a/RTNeural/conv1d/conv1d_eigen.h +++ b/RTNeural/conv1d/conv1d_eigen.h @@ -52,7 +52,7 @@ class Conv1D : public Layer // set state pointers to the particular columns of the buffer setStatePointers(); - if (groups == 1) + if(groups == 1) { // copy selected columns to a helper variable for(int k = 0; k < kernel_size; ++k) @@ -175,7 +175,7 @@ class Conv1DT RTNEURAL_REALTIME void reset(); /** Performs forward propagation for this layer. */ - template = true> + template = true> RTNEURAL_REALTIME inline void forward(const Eigen::Matrix& ins) noexcept { // insert input into a circular buffer @@ -196,7 +196,7 @@ class Conv1DT } /** Performs forward propagation for this layer (groups > 1). */ - template = true> + template = true> RTNEURAL_REALTIME inline void forward(const Eigen::Matrix& ins) noexcept { // insert input into a circular buffer diff --git a/RTNeural/conv1d/conv1d_xsimd.h b/RTNeural/conv1d/conv1d_xsimd.h index 89c6fb8..780f666 100644 --- a/RTNeural/conv1d/conv1d_xsimd.h +++ b/RTNeural/conv1d/conv1d_xsimd.h @@ -4,9 +4,9 @@ #include "../Layer.h" #include "../common.h" #include "../config.h" +#include #include #include -#include namespace RTNEURAL_NAMESPACE { @@ -54,7 +54,7 @@ class Conv1D : public Layer // set state pointers to particular columns of the buffer setStatePointers(); - if (groups == 1) + if(groups == 1) { // copy selected columns to a helper variable for(int k = 0; k < kernel_size; ++k) @@ -220,10 +220,10 @@ class Conv1DT { // copy selected columns to a helper variable // @TODO: I'm not sure the reinterpret_casts are 100% safe here, but they seem to work in testing! - const auto& column = reinterpret_cast&> (state[state_ptrs[j]]); + const auto& column = reinterpret_cast&>(state[state_ptrs[j]]); const auto column_begin = column.begin() + ii; const auto column_end = column_begin + filters_per_group; - std::copy(column_begin, column_end, reinterpret_cast&> (state_cols[j]).begin()); + std::copy(column_begin, column_end, reinterpret_cast&>(state_cols[j]).begin()); accum += std::inner_product( subWeights[j].begin(), diff --git a/RTNeural/dense/dense_xsimd.h b/RTNeural/dense/dense_xsimd.h index 70109ed..73c904b 100644 --- a/RTNeural/dense/dense_xsimd.h +++ b/RTNeural/dense/dense_xsimd.h @@ -338,7 +338,7 @@ class DenseT for(int i = 0; i < v_out_size; ++i) outs[i] = bias[i]; - const auto in = ins[0].get (0); + const auto in = ins[0].get(0); for(int i = 0; i < v_out_size; ++i) outs[i] += in * weights[i]; } diff --git a/tests/functional/torch_conv1d_test.cpp b/tests/functional/torch_conv1d_test.cpp index 2731a57..10be824 100644 --- a/tests/functional/torch_conv1d_test.cpp +++ b/tests/functional/torch_conv1d_test.cpp @@ -37,7 +37,7 @@ void testTorchConv1DModel() } std::ifstream modelOutputsFile { std::string { RTNEURAL_ROOT_DIR } + "test_data/conv1d_torch_y_python.csv" }; - const auto expected_y = RTNeural::torch_helpers::detail::transpose(load_csv::loadFile2d (modelOutputsFile)); + const auto expected_y = RTNeural::torch_helpers::detail::transpose(load_csv::loadFile2d(modelOutputsFile)); for(size_t n = 0; n < expected_y.size(); ++n) { diff --git a/tests/functional/torch_microtcn_test.cpp b/tests/functional/torch_microtcn_test.cpp index c602725..7aac704 100644 --- a/tests/functional/torch_microtcn_test.cpp +++ b/tests/functional/torch_microtcn_test.cpp @@ -3,7 +3,7 @@ #include "RTNeural/RTNeural.h" #include "load_csv.hpp" -#if ! (RTNEURAL_USE_EIGEN || RTNEURAL_USE_XSIMD) +#if !(RTNEURAL_USE_EIGEN || RTNEURAL_USE_XSIMD) namespace {