Added check for vector dimensions to cpp proximal decoder

This commit is contained in:
Andreas Tsouchlos 2022-11-27 02:40:11 +01:00
parent b33a0735f0
commit 31f137067c
2 changed files with 9 additions and 5 deletions

View File

@ -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)

View File

@ -1,14 +1,13 @@
#include <Eigen/Dense>
#include <bit>
#include <iostream>
#include <stdexcept>
#include <pybind11/eigen.h>
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/eigen.h>
#include <bit>
namespace py11 = pybind11;
using namespace pybind11::literals;
@ -33,6 +32,9 @@ public:
std::pair<std::optional<Eigen::RowVectorXi>, int>
decode(const Eigen::Ref<const Eigen::VectorXd>& 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<double>(), t[3].cast<double>(),
t[4].cast<double>()};
}));
pybind11::register_exception<std::runtime_error>(proximal, "CppException");
}