From 31f137067ca337d24a476f1abae9c9333a77f0de Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Sun, 27 Nov 2022 02:40:11 +0100 Subject: [PATCH] Added check for vector dimensions to cpp proximal decoder --- sw/cpp/CMakeLists.txt | 2 +- sw/cpp/src/cpp_decoders.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sw/cpp/CMakeLists.txt b/sw/cpp/CMakeLists.txt index 3833598..4014e74 100644 --- a/sw/cpp/CMakeLists.txt +++ b/sw/cpp/CMakeLists.txt @@ -24,7 +24,7 @@ include_directories(${pybind11_INCLUDE_DIRS}) find_package(OpenMP REQUIRED) -add_compile_options(-ffast-math) +#add_compile_options(-ffast-math) pybind11_add_module(cpp_decoders src/cpp_decoders.cpp) target_link_libraries(cpp_decoders PRIVATE Eigen3::Eigen OpenMP::OpenMP_CXX) diff --git a/sw/cpp/src/cpp_decoders.cpp b/sw/cpp/src/cpp_decoders.cpp index a00422f..39a5c27 100644 --- a/sw/cpp/src/cpp_decoders.cpp +++ b/sw/cpp/src/cpp_decoders.cpp @@ -1,14 +1,13 @@ #include +#include #include +#include +#include #include #include #include -#include - -#include - namespace py11 = pybind11; using namespace pybind11::literals; @@ -33,6 +32,9 @@ public: std::pair, int> decode(const Eigen::Ref& y) { + if (y.size() != mH.cols()) + throw std::runtime_error("Length of vector must match H matrix"); + Eigen::RowVectorXd s = Eigen::RowVectorXd::Zero(mH.cols()); Eigen::RowVectorXi x_hat; Eigen::RowVectorXd r; @@ -129,4 +131,6 @@ PYBIND11_MODULE(cpp_decoders, proximal) { t[2].cast(), t[3].cast(), t[4].cast()}; })); + + pybind11::register_exception(proximal, "CppException"); } \ No newline at end of file