From 279df65a966c63d12f04067ffa7321e4b9c72cd4 Mon Sep 17 00:00:00 2001 From: Sciroccogti Date: Wed, 13 Mar 2024 22:10:00 +0800 Subject: [PATCH 1/8] add Source_user_numpy --- template/py_aff3ct_template.cpp | 5 ++ template/py_aff3ct_template.hpp | 1 + .../Module/Source/User/Source_user_numpy.cpp | 70 +++++++++++++++++++ .../Module/Source/User/Source_user_numpy.hpp | 35 ++++++++++ .../Module/Source/User/Source_user_numpy.hxx | 31 ++++++++ .../Module/Source/User/Source_user_numpy.cpp | 33 +++++++++ .../Module/Source/User/Source_user_numpy.hpp | 41 +++++++++++ 7 files changed, 216 insertions(+) create mode 100644 template/src/Module/Source/User/Source_user_numpy.cpp create mode 100644 template/src/Module/Source/User/Source_user_numpy.hpp create mode 100644 template/src/Module/Source/User/Source_user_numpy.hxx create mode 100644 template/src/Wrapper_py/Module/Source/User/Source_user_numpy.cpp create mode 100644 template/src/Wrapper_py/Module/Source/User/Source_user_numpy.hpp diff --git a/template/py_aff3ct_template.cpp b/template/py_aff3ct_template.cpp index 49689b1..1314fc1 100644 --- a/template/py_aff3ct_template.cpp +++ b/template/py_aff3ct_template.cpp @@ -90,6 +90,7 @@ R"pbdoc( monitor switcher interleaver + source )pbdoc"; std::unique_ptr wrapper_socket (new wrapper::Wrapper_Socket (m1)); wrappers.push_back(wrapper_socket.get()); @@ -137,6 +138,10 @@ R"pbdoc( wrappers.push_back(wrapper_interleaver_double.get()); {other_module_wrappers} + + std::unique_ptr wrapper_source_user_numpy(new aff3ct::wrapper::Wrapper_Source_user_numpy<>(mod_source)); + wrappers.push_back(wrapper_source_user_numpy.get()); + m1.doc() = doc_m1.c_str(); for (size_t i = 0; i < wrappers.size(); i++) wrappers[i]->definitions(); diff --git a/template/py_aff3ct_template.hpp b/template/py_aff3ct_template.hpp index ba38ce6..aedb376 100644 --- a/template/py_aff3ct_template.hpp +++ b/template/py_aff3ct_template.hpp @@ -32,5 +32,6 @@ #include "Wrapper_py/Module/Interleaver/Interleaver.hpp" {other_includes} +#include "Wrapper_py/Module/Source/User/Source_user_numpy.hpp" #endif //PY_AFF3CT_HPP_ \ No newline at end of file diff --git a/template/src/Module/Source/User/Source_user_numpy.cpp b/template/src/Module/Source/User/Source_user_numpy.cpp new file mode 100644 index 0000000..0f6745f --- /dev/null +++ b/template/src/Module/Source/User/Source_user_numpy.cpp @@ -0,0 +1,70 @@ +/** + * @file Source_user_numpy.cpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-13 15:12:01 + * @modified: 2024-03-13 20:19:13 + */ + +#include "Module/Source/User/Source_user_numpy.hpp" + +using namespace aff3ct; +using namespace aff3ct::module; + +template +Source_user_numpy::Source_user_numpy(const int K, const std::vector>& input) + : Source(K) + , source(input) + , src_counter(0) +{ + const std::string name = "Source_user_numpy"; + this->set_name(name); + + int n_src = input.size(); + int src_size = input[0].size(); + + if (n_src <= 0 || src_size <= 0) { + std::stringstream message; + message << "'n_src', and 'src_size' have to be greater than 0 ('n_src' = " << n_src + << ", 'src_size' = " << src_size << ")."; + throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); + } + + if (src_size == this->K) { + this->source = input; + } else { + std::stringstream message; + message << "The size is wrong (read: " << src_size << ", expected: " << this->K << ")."; + throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); + } +} + +template +Source_user_numpy* Source_user_numpy::clone() const +{ + auto m = new Source_user_numpy(*this); + m->deep_copy(*this); + return m; +} + +template +void Source_user_numpy::_generate(B* U_K, const size_t frame_id) +{ + if (this->src_counter == this->source.size()) + this->src_counter = 0; + + std::copy(this->source[this->src_counter].begin(), this->source[this->src_counter].end(), U_K); + this->src_counter++; +} + +// ==================================================================================== explicit template instantiation +#include "Tools/types.h" +#ifdef AFF3CT_MULTI_PREC +template class aff3ct::module::Source_user_numpy; +template class aff3ct::module::Source_user_numpy; +template class aff3ct::module::Source_user_numpy; +template class aff3ct::module::Source_user_numpy; +#else +template class aff3ct::module::Source_user; +#endif +// ==================================================================================== explicit template instantiation diff --git a/template/src/Module/Source/User/Source_user_numpy.hpp b/template/src/Module/Source/User/Source_user_numpy.hpp new file mode 100644 index 0000000..0ef52c7 --- /dev/null +++ b/template/src/Module/Source/User/Source_user_numpy.hpp @@ -0,0 +1,35 @@ +/** + * @file Source_user_numpy.hpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-13 15:12:47 + * @modified: 2024-03-13 20:17:37 + */ +#ifndef SOURCE_USER_NUMPY_HPP_ +#define SOURCE_USER_NUMPY_HPP_ + +#include + +#include "Module/Source/Source.hpp" + +namespace aff3ct { +namespace module { + template + class Source_user_numpy : public Source { + private: + std::vector> source; + size_t src_counter; + + public: + Source_user_numpy(const int K, const std::vector>& input); + virtual ~Source_user_numpy() = default; + virtual Source_user_numpy* clone() const; + + protected: + void _generate(B* U_K, const size_t frame_id); + }; + +} +} + +#endif /* SOURCE_USER_NUMPY_HPP_ */ diff --git a/template/src/Module/Source/User/Source_user_numpy.hxx b/template/src/Module/Source/User/Source_user_numpy.hxx new file mode 100644 index 0000000..0e8ebb7 --- /dev/null +++ b/template/src/Module/Source/User/Source_user_numpy.hxx @@ -0,0 +1,31 @@ +/** + * @file Source_user_numpy.hxx + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-13 21:27:20 + * @modified: 2024-03-13 21:30:08 + */ + +#include "Module/Module.hpp" +#include "Module/Source/User/Source_user_numpy.hpp" + +namespace aff3ct +{ +namespace module +{ + template + Task& Source_user_numpy::operator[](const src::tsk t) + { + switch (t) { + case src::tsk::generate: + return Module::operator[](static_cast(src::tsk::generate)); + default: + break; + } + + std::stringstream message; + message << "Unknown task"; + throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); + } +} +} \ No newline at end of file diff --git a/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.cpp b/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.cpp new file mode 100644 index 0000000..e0f517d --- /dev/null +++ b/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.cpp @@ -0,0 +1,33 @@ +/** + * @file Source_user_numpy.cpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-13 20:04:08 + * @modified: 2024-03-13 21:13:55 + */ +#include "Wrapper_py/Module/Source/User/Source_user_numpy.hpp" + +namespace py = pybind11; +using namespace py::literals; +using namespace aff3ct; +using namespace aff3ct::module; +using namespace aff3ct::tools; +using namespace aff3ct::wrapper; + +template +Wrapper_Source_user_numpy +::Wrapper_Source_user_numpy(py::handle scope) +: Wrapper_py(), + py::class_,aff3ct::module::Source>(scope, "Source_user_numpy") +{ +} + +template +void Wrapper_Source_user_numpy +::definitions() +{ + this->def(py::init> &>(),"K"_a, "input"_a, R"pbdoc()pbdoc", py::return_value_policy::take_ownership); +}; + +#include "Tools/types.h" +template class aff3ct::wrapper::Wrapper_Source_user_numpy; \ No newline at end of file diff --git a/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.hpp b/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.hpp new file mode 100644 index 0000000..317c363 --- /dev/null +++ b/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.hpp @@ -0,0 +1,41 @@ +/** + * @file Source_user_numpy.hpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-13 20:04:16 + * @modified: 2024-03-13 21:32:45 + */ + +#ifndef WRAPPER_SOURCE_USER_NUMPY_HPP_ +#define WRAPPER_SOURCE_USER_NUMPY_HPP_ + + +#include +#include +#include + +#include "Module/Source/User/Source_user_numpy.hpp" + +#include "Wrapper_py/Wrapper_py.hpp" + +namespace py = pybind11; +using namespace aff3ct; +using namespace aff3ct::module; +using namespace aff3ct::tools; + +namespace aff3ct +{ +namespace wrapper +{ +template +class Wrapper_Source_user_numpy : public Wrapper_py, + public py::class_, aff3ct::module::Source> +{ + public: + Wrapper_Source_user_numpy(py::handle scope); + virtual void definitions(); + virtual ~Wrapper_Source_user_numpy() = default; +}; +} +} +#endif //WRAPPER_SOURCE_USER_NUMPY_HPP_ \ No newline at end of file From 5934ced2111959c1127bcbba437e1ce11ef4a48c Mon Sep 17 00:00:00 2001 From: Sciroccogti Date: Thu, 14 Mar 2024 01:10:19 +0800 Subject: [PATCH 2/8] add is_done for Source_user_numpy --- .../Module/Source/User/Source_user_numpy.cpp | 23 ++++++++++--------- .../Module/Source/User/Source_user_numpy.hpp | 7 +++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/template/src/Module/Source/User/Source_user_numpy.cpp b/template/src/Module/Source/User/Source_user_numpy.cpp index 0f6745f..9a6d3a4 100644 --- a/template/src/Module/Source/User/Source_user_numpy.cpp +++ b/template/src/Module/Source/User/Source_user_numpy.cpp @@ -3,7 +3,7 @@ * @author Sciroccogti (scirocco_gti@yeah.net) * @brief * @date 2024-03-13 15:12:01 - * @modified: 2024-03-13 20:19:13 + * @modified: 2024-03-14 00:33:56 */ #include "Module/Source/User/Source_user_numpy.hpp" @@ -13,9 +13,10 @@ using namespace aff3ct::module; template Source_user_numpy::Source_user_numpy(const int K, const std::vector>& input) - : Source(K) - , source(input) - , src_counter(0) + : Source(K), + source(input), + src_counter(0), + done(false) { const std::string name = "Source_user_numpy"; this->set_name(name); @@ -40,21 +41,21 @@ Source_user_numpy::Source_user_numpy(const int K, const std::vector -Source_user_numpy* Source_user_numpy::clone() const +bool Source_user_numpy::is_done() const { - auto m = new Source_user_numpy(*this); - m->deep_copy(*this); - return m; + return this->done; } template void Source_user_numpy::_generate(B* U_K, const size_t frame_id) { - if (this->src_counter == this->source.size()) - this->src_counter = 0; - std::copy(this->source[this->src_counter].begin(), this->source[this->src_counter].end(), U_K); this->src_counter++; + + if (this->src_counter == this->source.size()) { + this->src_counter = 0; + this->done = true; + } } // ==================================================================================== explicit template instantiation diff --git a/template/src/Module/Source/User/Source_user_numpy.hpp b/template/src/Module/Source/User/Source_user_numpy.hpp index 0ef52c7..733d66a 100644 --- a/template/src/Module/Source/User/Source_user_numpy.hpp +++ b/template/src/Module/Source/User/Source_user_numpy.hpp @@ -1,9 +1,9 @@ /** * @file Source_user_numpy.hpp * @author Sciroccogti (scirocco_gti@yeah.net) - * @brief + * @brief reference: lib/aff3ct/include/Module/Source/User/Source_user_binary.hpp * @date 2024-03-13 15:12:47 - * @modified: 2024-03-13 20:17:37 + * @modified: 2024-03-14 00:35:32 */ #ifndef SOURCE_USER_NUMPY_HPP_ #define SOURCE_USER_NUMPY_HPP_ @@ -19,11 +19,12 @@ namespace module { private: std::vector> source; size_t src_counter; + bool done; public: Source_user_numpy(const int K, const std::vector>& input); virtual ~Source_user_numpy() = default; - virtual Source_user_numpy* clone() const; + bool is_done() const; protected: void _generate(B* U_K, const size_t frame_id); From 2ae968b49f0963875b2c0b9857f013c3f6e19def Mon Sep 17 00:00:00 2001 From: Sciroccogti Date: Fri, 15 Mar 2024 10:42:27 +0800 Subject: [PATCH 3/8] Add Fetcher_numpy module --- template/py_aff3ct_template.cpp | 4 + template/py_aff3ct_template.hpp | 1 + template/src/Module/Fetcher/Fetcher_numpy.cpp | 131 ++++++++++++++++++ template/src/Module/Fetcher/Fetcher_numpy.hpp | 69 +++++++++ .../Module/Fetcher/Fetcher_numpy.cpp | 51 +++++++ .../Module/Fetcher/Fetcher_numpy.hpp | 40 ++++++ 6 files changed, 296 insertions(+) create mode 100644 template/src/Module/Fetcher/Fetcher_numpy.cpp create mode 100644 template/src/Module/Fetcher/Fetcher_numpy.hpp create mode 100644 template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp create mode 100644 template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp diff --git a/template/py_aff3ct_template.cpp b/template/py_aff3ct_template.cpp index 1314fc1..7a78268 100644 --- a/template/py_aff3ct_template.cpp +++ b/template/py_aff3ct_template.cpp @@ -137,6 +137,10 @@ R"pbdoc( wrappers.push_back(wrapper_interleaver_float .get()); wrappers.push_back(wrapper_interleaver_double.get()); + py::module_ mod_fetcher = m1.def_submodule("fetcher"); + std::unique_ptr wrapper_fetcher_numpy_int32(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "int32_t")); + wrappers.push_back(wrapper_fetcher_numpy_int32.get()); + {other_module_wrappers} std::unique_ptr wrapper_source_user_numpy(new aff3ct::wrapper::Wrapper_Source_user_numpy<>(mod_source)); diff --git a/template/py_aff3ct_template.hpp b/template/py_aff3ct_template.hpp index aedb376..007f28f 100644 --- a/template/py_aff3ct_template.hpp +++ b/template/py_aff3ct_template.hpp @@ -30,6 +30,7 @@ #include "Wrapper_py/Module/Monitor/Monitor_MI/Monitor_MI.hpp" #include "Wrapper_py/Module/Switcher/Switcher.hpp" #include "Wrapper_py/Module/Interleaver/Interleaver.hpp" +#include "Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp" {other_includes} #include "Wrapper_py/Module/Source/User/Source_user_numpy.hpp" diff --git a/template/src/Module/Fetcher/Fetcher_numpy.cpp b/template/src/Module/Fetcher/Fetcher_numpy.cpp new file mode 100644 index 0000000..461893e --- /dev/null +++ b/template/src/Module/Fetcher/Fetcher_numpy.cpp @@ -0,0 +1,131 @@ +/** + * @file Fetcher_numpy.cpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-13 18:00:38 + * @modified: 2024-03-15 10:37:58 + */ + +#include "Module/Fetcher/Fetcher_numpy.hpp" + +using namespace aff3ct; +using namespace aff3ct::module; + +template +Task& Fetcher_numpy::operator[](const ftr::tsk t) +{ + switch (t) { + case ftr::tsk::append: + return Module::operator[](static_cast(ftr::tsk::append)); + default: + break; + } + + std::stringstream message; + message << "Unknown task"; + throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); +} + +template +Socket& Fetcher_numpy::operator[](const ftr::sck::append s) +{ + return Module::operator[]((size_t)ftr::tsk::append)[(size_t)s]; + // return this->get_socket(static_cast(s)); +} + +template +Fetcher_numpy::Fetcher_numpy(const int K, const int N) + : Module() + , K(K) + , N(N) +{ + const std::string name = "Fetcher_numpy"; + this->set_name(name); + + if (K <= 0 || N <= 0) { + std::stringstream message; + message << "'K', and 'N' have to be greater than 0 ('K' = " << K + << ", 'N' = " << N << ")."; + throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); + } + + auto& p = this->create_task("append"); + auto p1s_U = this->template create_socket_in(p, "U_K", this->K); + + this->create_codelet(p, [p1s_U](Module& m, Task& t, const size_t frame_id) -> int { + auto& ftr = static_cast&>(m); + + ftr._append(static_cast(t[p1s_U].get_dataptr())); + + return status_t::SUCCESS; + }); +} + +template +Fetcher_numpy* Fetcher_numpy::clone() const +{ + auto m = new Fetcher_numpy(*this); + m->deep_copy(*this); + return m; +} + +template +int Fetcher_numpy::get_K() const +{ + return this->K; +} + +template +int Fetcher_numpy::get_N() const +{ + return this->N; +} + +template +void Fetcher_numpy::append(std::vector& U_K) +{ + this->data.push_back(U_K); +} + +template +std::vector> Fetcher_numpy::get_data() const +{ + return this->data; +} + +template +void Fetcher_numpy::_append(B* U_K) +{ + std::vector U_K_vec(U_K, U_K + this->K); + this->append(U_K_vec); +} + +template +void Fetcher_numpy::_get_data(B* data) const +{ + std::vector data_vec; + for (auto& U_K : this->data) { + std::copy(U_K.begin(), U_K.end(), data_vec.end()); + } + std::copy(data_vec.begin(), data_vec.end(), data); +} + +template +bool Fetcher_numpy::is_done() const +{ + return this->data.size() == this->N; +} + +template +void Fetcher_numpy::reset() +{ + this->data.clear(); +} + +#include "Tools/types.h" +template class aff3ct::module::Fetcher_numpy; +template class aff3ct::module::Fetcher_numpy; +template class aff3ct::module::Fetcher_numpy; +template class aff3ct::module::Fetcher_numpy; +template class aff3ct::module::Fetcher_numpy; +template class aff3ct::module::Fetcher_numpy; diff --git a/template/src/Module/Fetcher/Fetcher_numpy.hpp b/template/src/Module/Fetcher/Fetcher_numpy.hpp new file mode 100644 index 0000000..df9fa10 --- /dev/null +++ b/template/src/Module/Fetcher/Fetcher_numpy.hpp @@ -0,0 +1,69 @@ +/** + * @file Fetcher_numpy.hpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-13 18:00:30 + * @modified: 2024-03-15 10:19:29 + */ + +#ifndef FETCHER_NUMPY_HPP_ +#define FETCHER_NUMPY_HPP_ + +#include "Module/Module.hpp" +#include "Module/Socket.hpp" +#include "Module/Task.hpp" +#include "Tools/Interface/Interface_is_done.hpp" +#include "Tools/Interface/Interface_reset.hpp" + +namespace aff3ct { +namespace module { + namespace ftr { + enum class tsk : size_t { append, + SIZE }; + namespace sck { + enum class append : size_t { data, + SIZE }; + } + } + + template + class Fetcher_numpy : public Module, + public tools::Interface_is_done, + public tools::Interface_reset { + public: + inline Task& operator[](const ftr::tsk t); + inline Socket& operator[](const ftr::sck::append s); + + protected: + std::vector> data; + const int K; /*!< Number of information bits in one frame */ + const int N; /*!< Number of frames */ + + public: + Fetcher_numpy(const int K, const int N); + + ~Fetcher_numpy() = default; + + Fetcher_numpy* clone() const; + + int get_K() const; + + int get_N() const; + + void append(std::vector& U_K); + + std::vector> get_data() const; + + bool is_done() const; + + void reset(); + + private: + void _append(B* U_K); + + void _get_data(B* data) const; + }; +} +} + +#endif /* FETCHER_NUMPY_HPP_ */ diff --git a/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp b/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp new file mode 100644 index 0000000..46afa57 --- /dev/null +++ b/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp @@ -0,0 +1,51 @@ +/** + * @file Fetcher_numpy.cpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-14 14:58:53 + * @modified: 2024-03-15 10:39:06 + */ + +#include "Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp" + +namespace py = pybind11; +using namespace py::literals; +using namespace aff3ct; +using namespace aff3ct::module; +using namespace aff3ct::tools; +using namespace aff3ct::wrapper; + +template +Wrapper_Fetcher_numpy +::Wrapper_Fetcher_numpy(py::handle scope, const std::string& type) +: Wrapper_py(), + py::class_,aff3ct::module::Module>(scope, std::string("Fetcher_numpy_" + type).c_str()) +{ +} + +template +void Wrapper_Fetcher_numpy +::definitions() +{ + this->def(py::init(),"K"_a, "N"_a, R"pbdoc()pbdoc", py::return_value_policy::take_ownership); + this->def("get_K", &aff3ct::module::Fetcher_numpy::get_K, R"pbdoc()pbdoc"); + this->def("get_N", &aff3ct::module::Fetcher_numpy::get_N, R"pbdoc()pbdoc"); + this->def("append", &aff3ct::module::Fetcher_numpy::append, R"pbdoc()pbdoc"); + this->def("get_data", &aff3ct::module::Fetcher_numpy::get_data, R"pbdoc()pbdoc"); + this->def("is_done", &aff3ct::module::Fetcher_numpy::is_done, R"pbdoc()pbdoc"); + this->def("reset", &aff3ct::module::Fetcher_numpy::reset, R"pbdoc()pbdoc"); + this->def_property_readonly("tasks", [](Fetcher_numpy& self)-> std::vector> { return self.tasks; },R"pbdoc(List of tasks: +* **append**: Task method method appends a vector to the buffer. + + * U_K: a vector of bits to append. +)pbdoc"); + this->doc() = R"pbdoc(Fetches a message. + +Parameters: + + * B: type of the bits in the Fetcher. +)pbdoc"; +}; + +#include "Tools/types.h" +template class aff3ct::wrapper::Wrapper_Fetcher_numpy; diff --git a/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp b/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp new file mode 100644 index 0000000..ddcdff0 --- /dev/null +++ b/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp @@ -0,0 +1,40 @@ +/** + * @file Fetcher_numpy.hpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-14 14:59:01 + * @modified: 2024-03-14 16:53:32 + */ + +#ifndef WRAPPER_FETCHER_NUMPY_HPP_ +#define WRAPPER_FETCHER_NUMPY_HPP_ + +#include +#include +#include + +#include "Module/Fetcher/Fetcher_numpy.hpp" + +#include "Wrapper_py/Wrapper_py.hpp" + +namespace py = pybind11; +using namespace aff3ct; +using namespace aff3ct::module; +using namespace aff3ct::tools; + +namespace aff3ct +{ +namespace wrapper +{ +template +class Wrapper_Fetcher_numpy : public Wrapper_py, + public py::class_, aff3ct::module::Module> +{ + public: + Wrapper_Fetcher_numpy(py::handle scope, const std::string& type); + virtual void definitions(); + virtual ~Wrapper_Fetcher_numpy() = default; +}; +} +} +#endif //WRAPPER_FETCHER_NUMPY_HPP_ From 2d51e90dda6b6018f6895ce408e4215535d149d0 Mon Sep 17 00:00:00 2001 From: Sciroccogti Date: Fri, 15 Mar 2024 12:14:17 +0800 Subject: [PATCH 4/8] Add support for additional data types in Fetcher module --- template/py_aff3ct_template.cpp | 12 +++++++++++- .../src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp | 10 ++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/template/py_aff3ct_template.cpp b/template/py_aff3ct_template.cpp index 7a78268..93c5f6f 100644 --- a/template/py_aff3ct_template.cpp +++ b/template/py_aff3ct_template.cpp @@ -138,8 +138,18 @@ R"pbdoc( wrappers.push_back(wrapper_interleaver_double.get()); py::module_ mod_fetcher = m1.def_submodule("fetcher"); - std::unique_ptr wrapper_fetcher_numpy_int32(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "int32_t")); + std::unique_ptr wrapper_fetcher_numpy_int8(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "int8")); + std::unique_ptr wrapper_fetcher_numpy_int16(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "int16")); + std::unique_ptr wrapper_fetcher_numpy_int32(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "int32")); + std::unique_ptr wrapper_fetcher_numpy_int64(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "int64")); + std::unique_ptr wrapper_fetcher_numpy_float(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "float")); + std::unique_ptr wrapper_fetcher_numpy_double(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "double")); + wrappers.push_back(wrapper_fetcher_numpy_int8.get()); + wrappers.push_back(wrapper_fetcher_numpy_int16.get()); wrappers.push_back(wrapper_fetcher_numpy_int32.get()); + wrappers.push_back(wrapper_fetcher_numpy_int64.get()); + wrappers.push_back(wrapper_fetcher_numpy_float.get()); + wrappers.push_back(wrapper_fetcher_numpy_double.get()); {other_module_wrappers} diff --git a/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp b/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp index 46afa57..44c49bb 100644 --- a/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp +++ b/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp @@ -3,7 +3,7 @@ * @author Sciroccogti (scirocco_gti@yeah.net) * @brief * @date 2024-03-14 14:58:53 - * @modified: 2024-03-15 10:39:06 + * @modified: 2024-03-15 12:11:34 */ #include "Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp" @@ -48,4 +48,10 @@ ::definitions() }; #include "Tools/types.h" -template class aff3ct::wrapper::Wrapper_Fetcher_numpy; + +template class aff3ct::wrapper::Wrapper_Fetcher_numpy; +template class aff3ct::wrapper::Wrapper_Fetcher_numpy; +template class aff3ct::wrapper::Wrapper_Fetcher_numpy; +template class aff3ct::wrapper::Wrapper_Fetcher_numpy; +template class aff3ct::wrapper::Wrapper_Fetcher_numpy; +template class aff3ct::wrapper::Wrapper_Fetcher_numpy; From 67d790f7ef73e44c7deffed6118aff9ab2cedc07 Mon Sep 17 00:00:00 2001 From: Sciroccogti Date: Fri, 15 Mar 2024 16:09:09 +0800 Subject: [PATCH 5/8] remove Source_user_numpy, rename Fetcher to Tunnel --- template/py_aff3ct_template.cpp | 29 ++- template/py_aff3ct_template.hpp | 3 +- template/src/Module/Fetcher/Fetcher_numpy.cpp | 131 ------------- template/src/Module/Fetcher/Fetcher_numpy.hpp | 69 ------- .../Module/Source/User/Source_user_numpy.cpp | 71 ------- .../Module/Source/User/Source_user_numpy.hpp | 36 ---- .../Module/Source/User/Source_user_numpy.hxx | 31 --- template/src/Module/Tunnel/Tunnel_numpy.cpp | 181 ++++++++++++++++++ template/src/Module/Tunnel/Tunnel_numpy.hpp | 92 +++++++++ .../Module/Fetcher/Fetcher_numpy.cpp | 57 ------ .../Module/Fetcher/Fetcher_numpy.hpp | 40 ---- .../Module/Source/User/Source_user_numpy.cpp | 33 ---- .../Module/Source/User/Source_user_numpy.hpp | 41 ---- .../Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp | 61 ++++++ .../Wrapper_py/Module/Tunnel/Tunnel_numpy.hpp | 40 ++++ 15 files changed, 388 insertions(+), 527 deletions(-) delete mode 100644 template/src/Module/Fetcher/Fetcher_numpy.cpp delete mode 100644 template/src/Module/Fetcher/Fetcher_numpy.hpp delete mode 100644 template/src/Module/Source/User/Source_user_numpy.cpp delete mode 100644 template/src/Module/Source/User/Source_user_numpy.hpp delete mode 100644 template/src/Module/Source/User/Source_user_numpy.hxx create mode 100644 template/src/Module/Tunnel/Tunnel_numpy.cpp create mode 100644 template/src/Module/Tunnel/Tunnel_numpy.hpp delete mode 100644 template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp delete mode 100644 template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp delete mode 100644 template/src/Wrapper_py/Module/Source/User/Source_user_numpy.cpp delete mode 100644 template/src/Wrapper_py/Module/Source/User/Source_user_numpy.hpp create mode 100644 template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp create mode 100644 template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.hpp diff --git a/template/py_aff3ct_template.cpp b/template/py_aff3ct_template.cpp index 93c5f6f..c118f6c 100644 --- a/template/py_aff3ct_template.cpp +++ b/template/py_aff3ct_template.cpp @@ -137,25 +137,22 @@ R"pbdoc( wrappers.push_back(wrapper_interleaver_float .get()); wrappers.push_back(wrapper_interleaver_double.get()); - py::module_ mod_fetcher = m1.def_submodule("fetcher"); - std::unique_ptr wrapper_fetcher_numpy_int8(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "int8")); - std::unique_ptr wrapper_fetcher_numpy_int16(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "int16")); - std::unique_ptr wrapper_fetcher_numpy_int32(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "int32")); - std::unique_ptr wrapper_fetcher_numpy_int64(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "int64")); - std::unique_ptr wrapper_fetcher_numpy_float(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "float")); - std::unique_ptr wrapper_fetcher_numpy_double(new aff3ct::wrapper::Wrapper_Fetcher_numpy(mod_fetcher, "double")); - wrappers.push_back(wrapper_fetcher_numpy_int8.get()); - wrappers.push_back(wrapper_fetcher_numpy_int16.get()); - wrappers.push_back(wrapper_fetcher_numpy_int32.get()); - wrappers.push_back(wrapper_fetcher_numpy_int64.get()); - wrappers.push_back(wrapper_fetcher_numpy_float.get()); - wrappers.push_back(wrapper_fetcher_numpy_double.get()); + py::module_ mod_tunnel = m1.def_submodule("tunnel"); + std::unique_ptr wrapper_tunnel_numpy_int8(new aff3ct::wrapper::Wrapper_Tunnel_numpy(mod_tunnel, "int8")); + std::unique_ptr wrapper_tunnel_numpy_int16(new aff3ct::wrapper::Wrapper_Tunnel_numpy(mod_tunnel, "int16")); + std::unique_ptr wrapper_tunnel_numpy_int32(new aff3ct::wrapper::Wrapper_Tunnel_numpy(mod_tunnel, "int32")); + std::unique_ptr wrapper_tunnel_numpy_int64(new aff3ct::wrapper::Wrapper_Tunnel_numpy(mod_tunnel, "int64")); + std::unique_ptr wrapper_tunnel_numpy_float(new aff3ct::wrapper::Wrapper_Tunnel_numpy(mod_tunnel, "float")); + std::unique_ptr wrapper_tunnel_numpy_double(new aff3ct::wrapper::Wrapper_Tunnel_numpy(mod_tunnel, "double")); + wrappers.push_back(wrapper_tunnel_numpy_int8.get()); + wrappers.push_back(wrapper_tunnel_numpy_int16.get()); + wrappers.push_back(wrapper_tunnel_numpy_int32.get()); + wrappers.push_back(wrapper_tunnel_numpy_int64.get()); + wrappers.push_back(wrapper_tunnel_numpy_float.get()); + wrappers.push_back(wrapper_tunnel_numpy_double.get()); {other_module_wrappers} - std::unique_ptr wrapper_source_user_numpy(new aff3ct::wrapper::Wrapper_Source_user_numpy<>(mod_source)); - wrappers.push_back(wrapper_source_user_numpy.get()); - m1.doc() = doc_m1.c_str(); for (size_t i = 0; i < wrappers.size(); i++) wrappers[i]->definitions(); diff --git a/template/py_aff3ct_template.hpp b/template/py_aff3ct_template.hpp index 007f28f..451a740 100644 --- a/template/py_aff3ct_template.hpp +++ b/template/py_aff3ct_template.hpp @@ -30,9 +30,8 @@ #include "Wrapper_py/Module/Monitor/Monitor_MI/Monitor_MI.hpp" #include "Wrapper_py/Module/Switcher/Switcher.hpp" #include "Wrapper_py/Module/Interleaver/Interleaver.hpp" -#include "Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp" +#include "Wrapper_py/Module/Tunnel/Tunnel_numpy.hpp" {other_includes} -#include "Wrapper_py/Module/Source/User/Source_user_numpy.hpp" #endif //PY_AFF3CT_HPP_ \ No newline at end of file diff --git a/template/src/Module/Fetcher/Fetcher_numpy.cpp b/template/src/Module/Fetcher/Fetcher_numpy.cpp deleted file mode 100644 index 461893e..0000000 --- a/template/src/Module/Fetcher/Fetcher_numpy.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/** - * @file Fetcher_numpy.cpp - * @author Sciroccogti (scirocco_gti@yeah.net) - * @brief - * @date 2024-03-13 18:00:38 - * @modified: 2024-03-15 10:37:58 - */ - -#include "Module/Fetcher/Fetcher_numpy.hpp" - -using namespace aff3ct; -using namespace aff3ct::module; - -template -Task& Fetcher_numpy::operator[](const ftr::tsk t) -{ - switch (t) { - case ftr::tsk::append: - return Module::operator[](static_cast(ftr::tsk::append)); - default: - break; - } - - std::stringstream message; - message << "Unknown task"; - throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); -} - -template -Socket& Fetcher_numpy::operator[](const ftr::sck::append s) -{ - return Module::operator[]((size_t)ftr::tsk::append)[(size_t)s]; - // return this->get_socket(static_cast(s)); -} - -template -Fetcher_numpy::Fetcher_numpy(const int K, const int N) - : Module() - , K(K) - , N(N) -{ - const std::string name = "Fetcher_numpy"; - this->set_name(name); - - if (K <= 0 || N <= 0) { - std::stringstream message; - message << "'K', and 'N' have to be greater than 0 ('K' = " << K - << ", 'N' = " << N << ")."; - throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); - } - - auto& p = this->create_task("append"); - auto p1s_U = this->template create_socket_in(p, "U_K", this->K); - - this->create_codelet(p, [p1s_U](Module& m, Task& t, const size_t frame_id) -> int { - auto& ftr = static_cast&>(m); - - ftr._append(static_cast(t[p1s_U].get_dataptr())); - - return status_t::SUCCESS; - }); -} - -template -Fetcher_numpy* Fetcher_numpy::clone() const -{ - auto m = new Fetcher_numpy(*this); - m->deep_copy(*this); - return m; -} - -template -int Fetcher_numpy::get_K() const -{ - return this->K; -} - -template -int Fetcher_numpy::get_N() const -{ - return this->N; -} - -template -void Fetcher_numpy::append(std::vector& U_K) -{ - this->data.push_back(U_K); -} - -template -std::vector> Fetcher_numpy::get_data() const -{ - return this->data; -} - -template -void Fetcher_numpy::_append(B* U_K) -{ - std::vector U_K_vec(U_K, U_K + this->K); - this->append(U_K_vec); -} - -template -void Fetcher_numpy::_get_data(B* data) const -{ - std::vector data_vec; - for (auto& U_K : this->data) { - std::copy(U_K.begin(), U_K.end(), data_vec.end()); - } - std::copy(data_vec.begin(), data_vec.end(), data); -} - -template -bool Fetcher_numpy::is_done() const -{ - return this->data.size() == this->N; -} - -template -void Fetcher_numpy::reset() -{ - this->data.clear(); -} - -#include "Tools/types.h" -template class aff3ct::module::Fetcher_numpy; -template class aff3ct::module::Fetcher_numpy; -template class aff3ct::module::Fetcher_numpy; -template class aff3ct::module::Fetcher_numpy; -template class aff3ct::module::Fetcher_numpy; -template class aff3ct::module::Fetcher_numpy; diff --git a/template/src/Module/Fetcher/Fetcher_numpy.hpp b/template/src/Module/Fetcher/Fetcher_numpy.hpp deleted file mode 100644 index df9fa10..0000000 --- a/template/src/Module/Fetcher/Fetcher_numpy.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/** - * @file Fetcher_numpy.hpp - * @author Sciroccogti (scirocco_gti@yeah.net) - * @brief - * @date 2024-03-13 18:00:30 - * @modified: 2024-03-15 10:19:29 - */ - -#ifndef FETCHER_NUMPY_HPP_ -#define FETCHER_NUMPY_HPP_ - -#include "Module/Module.hpp" -#include "Module/Socket.hpp" -#include "Module/Task.hpp" -#include "Tools/Interface/Interface_is_done.hpp" -#include "Tools/Interface/Interface_reset.hpp" - -namespace aff3ct { -namespace module { - namespace ftr { - enum class tsk : size_t { append, - SIZE }; - namespace sck { - enum class append : size_t { data, - SIZE }; - } - } - - template - class Fetcher_numpy : public Module, - public tools::Interface_is_done, - public tools::Interface_reset { - public: - inline Task& operator[](const ftr::tsk t); - inline Socket& operator[](const ftr::sck::append s); - - protected: - std::vector> data; - const int K; /*!< Number of information bits in one frame */ - const int N; /*!< Number of frames */ - - public: - Fetcher_numpy(const int K, const int N); - - ~Fetcher_numpy() = default; - - Fetcher_numpy* clone() const; - - int get_K() const; - - int get_N() const; - - void append(std::vector& U_K); - - std::vector> get_data() const; - - bool is_done() const; - - void reset(); - - private: - void _append(B* U_K); - - void _get_data(B* data) const; - }; -} -} - -#endif /* FETCHER_NUMPY_HPP_ */ diff --git a/template/src/Module/Source/User/Source_user_numpy.cpp b/template/src/Module/Source/User/Source_user_numpy.cpp deleted file mode 100644 index 9a6d3a4..0000000 --- a/template/src/Module/Source/User/Source_user_numpy.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/** - * @file Source_user_numpy.cpp - * @author Sciroccogti (scirocco_gti@yeah.net) - * @brief - * @date 2024-03-13 15:12:01 - * @modified: 2024-03-14 00:33:56 - */ - -#include "Module/Source/User/Source_user_numpy.hpp" - -using namespace aff3ct; -using namespace aff3ct::module; - -template -Source_user_numpy::Source_user_numpy(const int K, const std::vector>& input) - : Source(K), - source(input), - src_counter(0), - done(false) -{ - const std::string name = "Source_user_numpy"; - this->set_name(name); - - int n_src = input.size(); - int src_size = input[0].size(); - - if (n_src <= 0 || src_size <= 0) { - std::stringstream message; - message << "'n_src', and 'src_size' have to be greater than 0 ('n_src' = " << n_src - << ", 'src_size' = " << src_size << ")."; - throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); - } - - if (src_size == this->K) { - this->source = input; - } else { - std::stringstream message; - message << "The size is wrong (read: " << src_size << ", expected: " << this->K << ")."; - throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); - } -} - -template -bool Source_user_numpy::is_done() const -{ - return this->done; -} - -template -void Source_user_numpy::_generate(B* U_K, const size_t frame_id) -{ - std::copy(this->source[this->src_counter].begin(), this->source[this->src_counter].end(), U_K); - this->src_counter++; - - if (this->src_counter == this->source.size()) { - this->src_counter = 0; - this->done = true; - } -} - -// ==================================================================================== explicit template instantiation -#include "Tools/types.h" -#ifdef AFF3CT_MULTI_PREC -template class aff3ct::module::Source_user_numpy; -template class aff3ct::module::Source_user_numpy; -template class aff3ct::module::Source_user_numpy; -template class aff3ct::module::Source_user_numpy; -#else -template class aff3ct::module::Source_user; -#endif -// ==================================================================================== explicit template instantiation diff --git a/template/src/Module/Source/User/Source_user_numpy.hpp b/template/src/Module/Source/User/Source_user_numpy.hpp deleted file mode 100644 index 733d66a..0000000 --- a/template/src/Module/Source/User/Source_user_numpy.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file Source_user_numpy.hpp - * @author Sciroccogti (scirocco_gti@yeah.net) - * @brief reference: lib/aff3ct/include/Module/Source/User/Source_user_binary.hpp - * @date 2024-03-13 15:12:47 - * @modified: 2024-03-14 00:35:32 - */ -#ifndef SOURCE_USER_NUMPY_HPP_ -#define SOURCE_USER_NUMPY_HPP_ - -#include - -#include "Module/Source/Source.hpp" - -namespace aff3ct { -namespace module { - template - class Source_user_numpy : public Source { - private: - std::vector> source; - size_t src_counter; - bool done; - - public: - Source_user_numpy(const int K, const std::vector>& input); - virtual ~Source_user_numpy() = default; - bool is_done() const; - - protected: - void _generate(B* U_K, const size_t frame_id); - }; - -} -} - -#endif /* SOURCE_USER_NUMPY_HPP_ */ diff --git a/template/src/Module/Source/User/Source_user_numpy.hxx b/template/src/Module/Source/User/Source_user_numpy.hxx deleted file mode 100644 index 0e8ebb7..0000000 --- a/template/src/Module/Source/User/Source_user_numpy.hxx +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @file Source_user_numpy.hxx - * @author Sciroccogti (scirocco_gti@yeah.net) - * @brief - * @date 2024-03-13 21:27:20 - * @modified: 2024-03-13 21:30:08 - */ - -#include "Module/Module.hpp" -#include "Module/Source/User/Source_user_numpy.hpp" - -namespace aff3ct -{ -namespace module -{ - template - Task& Source_user_numpy::operator[](const src::tsk t) - { - switch (t) { - case src::tsk::generate: - return Module::operator[](static_cast(src::tsk::generate)); - default: - break; - } - - std::stringstream message; - message << "Unknown task"; - throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); - } -} -} \ No newline at end of file diff --git a/template/src/Module/Tunnel/Tunnel_numpy.cpp b/template/src/Module/Tunnel/Tunnel_numpy.cpp new file mode 100644 index 0000000..b30f7bb --- /dev/null +++ b/template/src/Module/Tunnel/Tunnel_numpy.cpp @@ -0,0 +1,181 @@ +/** + * @file Tunnel_numpy.cpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-13 18:00:38 + * @modified: 2024-03-15 15:53:44 + */ + +#include "Module/Tunnel/Tunnel_numpy.hpp" + +using namespace aff3ct; +using namespace aff3ct::module; + +template +Task& Tunnel_numpy::operator[](const ftr::tsk t) +{ + switch (t) { + case ftr::tsk::append: + return Module::operator[](static_cast(ftr::tsk::append)); + default: + break; + } + + std::stringstream message; + message << "Unknown task"; + throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); +} + +template +Socket& Tunnel_numpy::operator[](const ftr::sck::append s) +{ + return Module::operator[]((size_t)ftr::tsk::append)[(size_t)s]; +} + +template +Socket& Tunnel_numpy::operator[](const ftr::sck::get s) +{ + return Module::operator[]((size_t)ftr::tsk::get)[(size_t)s]; +} + +template +Tunnel_numpy::Tunnel_numpy(const int K, const int N) + : Module() + , K(K) + , N(N) +{ + const std::string name = "Tunnel_numpy"; + this->set_name(name); + + if (K <= 0 || N <= 0) { + std::stringstream message; + message << "'K', and 'N' have to be greater than 0 ('K' = " << K + << ", 'N' = " << N << ")."; + throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); + } + + auto& p1 = this->create_task("append"); + auto p1s_U = this->template create_socket_in(p1, "U_K", this->K); + // auto p1s_data = this->template create_socket_out(p1, "data", this->K * this->N); + this->create_codelet(p1, [p1s_U](Module& m, Task& t, const size_t frame_id) -> int { + auto& ftr = static_cast&>(m); + + ftr._append(static_cast(t[p1s_U].get_dataptr())); + + return status_t::SUCCESS; + }); + + auto& p2 = this->create_task("get"); + auto p2s_U = this->template create_socket_out(p2, "U_K", this->K); + this->create_codelet(p2, [p2s_U](Module& m, Task& t, const size_t frame_id) -> int { + auto& ftr = static_cast&>(m); + + ftr._get(static_cast(t[p2s_U].get_dataptr())); + + return status_t::SUCCESS; + }); +} + +template +Tunnel_numpy* Tunnel_numpy::clone() const +{ + auto m = new Tunnel_numpy(*this); + m->deep_copy(*this); + return m; +} + +template +int Tunnel_numpy::get_K() const +{ + return this->K; +} + +template +int Tunnel_numpy::get_N() const +{ + return this->N; +} + +template +void Tunnel_numpy::append(std::vector& U_K) +{ + (*this)[ftr::sck::append::U_K].bind(U_K.data()); + (*this)[ftr::tsk::append].exec(); +} + +template +void Tunnel_numpy::get(std::vector& U_K) +{ + (*this)[ftr::sck::get::U_K].bind(U_K.data()); + (*this)[ftr::tsk::get].exec(); +} + +template +void Tunnel_numpy::set_data(const std::vector>& data) +{ + this->data = data; +} + +template +std::vector> Tunnel_numpy::get_data() const +{ + return this->data; +} + +template +void Tunnel_numpy::_append(B* U_K) +{ + std::vector U_K_vec(U_K, U_K + this->K); + this->data.push_back(U_K_vec); + if (this->data.size() == this->N) { + this->append_done = true; + } +} + +template +void Tunnel_numpy::_get(B* U_K) +{ + std::copy(this->data[this->counter].begin(), this->data[this->counter].end(), U_K); + this->counter++; + + if (this->counter == this->data.size()) { + this->counter = 0; + this->get_done = true; + } +} + +// template +// void Tunnel_numpy::_get_data(B* data) const +// { +// std::vector data_vec; +// for (auto& U_K : this->data) { +// std::copy(U_K.begin(), U_K.end(), data_vec.end()); +// } +// std::copy(data_vec.begin(), data_vec.end(), data); +// } + +template +bool Tunnel_numpy::is_append_done() const +{ + return this->append_done; +} + +template +bool Tunnel_numpy::is_get_done() const +{ + return this->get_done; +} + +template +void Tunnel_numpy::reset() +{ + this->data.clear(); +} + +#include "Tools/types.h" +template class aff3ct::module::Tunnel_numpy; +template class aff3ct::module::Tunnel_numpy; +template class aff3ct::module::Tunnel_numpy; +template class aff3ct::module::Tunnel_numpy; +template class aff3ct::module::Tunnel_numpy; +template class aff3ct::module::Tunnel_numpy; diff --git a/template/src/Module/Tunnel/Tunnel_numpy.hpp b/template/src/Module/Tunnel/Tunnel_numpy.hpp new file mode 100644 index 0000000..12c08e5 --- /dev/null +++ b/template/src/Module/Tunnel/Tunnel_numpy.hpp @@ -0,0 +1,92 @@ +/** + * @file Tunnel_numpy.hpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-13 18:00:30 + * @modified: 2024-03-15 15:55:06 + */ + +#ifndef TUNNEL_NUMPY_HPP_ +#define TUNNEL_NUMPY_HPP_ + +#include "Module/Module.hpp" +#include "Module/Socket.hpp" +#include "Module/Task.hpp" +#include "Tools/Interface/Interface_is_done.hpp" +#include "Tools/Interface/Interface_reset.hpp" + +namespace aff3ct { +namespace module { + namespace ftr { + enum class tsk : size_t { + append, + get, + SIZE + }; + namespace sck { + enum class append : size_t { + U_K, + data, + SIZE + }; + enum class get : size_t { + U_K, + data, + SIZE + }; + } + } + + template + class Tunnel_numpy : public Module, + // public tools::Interface_is_done, + public tools::Interface_reset { + public: + inline Task& operator[](const ftr::tsk t); + inline Socket& operator[](const ftr::sck::append s); + inline Socket& operator[](const ftr::sck::get s); + + protected: + std::vector> data; + const size_t K; /*!< Number of information bits in one frame */ + const size_t N; /*!< Number of frames */ + size_t counter; + bool append_done; + bool get_done; + + public: + Tunnel_numpy(const int K, const int N); + + ~Tunnel_numpy() = default; + + Tunnel_numpy* clone() const; + + int get_K() const; + + int get_N() const; + + void append(std::vector& U_K); + + void get(std::vector& U_K); + + void set_data(const std::vector>& data); + + std::vector> get_data() const; + + bool is_append_done() const; + + bool is_get_done() const; + + void reset(); + + private: + void _append(B* U_K); + + void _get(B* U_K); + + // void _get_data(B* data) const; + }; +} +} + +#endif /* TUNNEL_NUMPY_HPP_ */ diff --git a/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp b/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp deleted file mode 100644 index 44c49bb..0000000 --- a/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file Fetcher_numpy.cpp - * @author Sciroccogti (scirocco_gti@yeah.net) - * @brief - * @date 2024-03-14 14:58:53 - * @modified: 2024-03-15 12:11:34 - */ - -#include "Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp" - -namespace py = pybind11; -using namespace py::literals; -using namespace aff3ct; -using namespace aff3ct::module; -using namespace aff3ct::tools; -using namespace aff3ct::wrapper; - -template -Wrapper_Fetcher_numpy -::Wrapper_Fetcher_numpy(py::handle scope, const std::string& type) -: Wrapper_py(), - py::class_,aff3ct::module::Module>(scope, std::string("Fetcher_numpy_" + type).c_str()) -{ -} - -template -void Wrapper_Fetcher_numpy -::definitions() -{ - this->def(py::init(),"K"_a, "N"_a, R"pbdoc()pbdoc", py::return_value_policy::take_ownership); - this->def("get_K", &aff3ct::module::Fetcher_numpy::get_K, R"pbdoc()pbdoc"); - this->def("get_N", &aff3ct::module::Fetcher_numpy::get_N, R"pbdoc()pbdoc"); - this->def("append", &aff3ct::module::Fetcher_numpy::append, R"pbdoc()pbdoc"); - this->def("get_data", &aff3ct::module::Fetcher_numpy::get_data, R"pbdoc()pbdoc"); - this->def("is_done", &aff3ct::module::Fetcher_numpy::is_done, R"pbdoc()pbdoc"); - this->def("reset", &aff3ct::module::Fetcher_numpy::reset, R"pbdoc()pbdoc"); - this->def_property_readonly("tasks", [](Fetcher_numpy& self)-> std::vector> { return self.tasks; },R"pbdoc(List of tasks: -* **append**: Task method method appends a vector to the buffer. - - * U_K: a vector of bits to append. -)pbdoc"); - this->doc() = R"pbdoc(Fetches a message. - -Parameters: - - * B: type of the bits in the Fetcher. -)pbdoc"; -}; - -#include "Tools/types.h" - -template class aff3ct::wrapper::Wrapper_Fetcher_numpy; -template class aff3ct::wrapper::Wrapper_Fetcher_numpy; -template class aff3ct::wrapper::Wrapper_Fetcher_numpy; -template class aff3ct::wrapper::Wrapper_Fetcher_numpy; -template class aff3ct::wrapper::Wrapper_Fetcher_numpy; -template class aff3ct::wrapper::Wrapper_Fetcher_numpy; diff --git a/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp b/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp deleted file mode 100644 index ddcdff0..0000000 --- a/template/src/Wrapper_py/Module/Fetcher/Fetcher_numpy.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file Fetcher_numpy.hpp - * @author Sciroccogti (scirocco_gti@yeah.net) - * @brief - * @date 2024-03-14 14:59:01 - * @modified: 2024-03-14 16:53:32 - */ - -#ifndef WRAPPER_FETCHER_NUMPY_HPP_ -#define WRAPPER_FETCHER_NUMPY_HPP_ - -#include -#include -#include - -#include "Module/Fetcher/Fetcher_numpy.hpp" - -#include "Wrapper_py/Wrapper_py.hpp" - -namespace py = pybind11; -using namespace aff3ct; -using namespace aff3ct::module; -using namespace aff3ct::tools; - -namespace aff3ct -{ -namespace wrapper -{ -template -class Wrapper_Fetcher_numpy : public Wrapper_py, - public py::class_, aff3ct::module::Module> -{ - public: - Wrapper_Fetcher_numpy(py::handle scope, const std::string& type); - virtual void definitions(); - virtual ~Wrapper_Fetcher_numpy() = default; -}; -} -} -#endif //WRAPPER_FETCHER_NUMPY_HPP_ diff --git a/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.cpp b/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.cpp deleted file mode 100644 index e0f517d..0000000 --- a/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/** - * @file Source_user_numpy.cpp - * @author Sciroccogti (scirocco_gti@yeah.net) - * @brief - * @date 2024-03-13 20:04:08 - * @modified: 2024-03-13 21:13:55 - */ -#include "Wrapper_py/Module/Source/User/Source_user_numpy.hpp" - -namespace py = pybind11; -using namespace py::literals; -using namespace aff3ct; -using namespace aff3ct::module; -using namespace aff3ct::tools; -using namespace aff3ct::wrapper; - -template -Wrapper_Source_user_numpy -::Wrapper_Source_user_numpy(py::handle scope) -: Wrapper_py(), - py::class_,aff3ct::module::Source>(scope, "Source_user_numpy") -{ -} - -template -void Wrapper_Source_user_numpy -::definitions() -{ - this->def(py::init> &>(),"K"_a, "input"_a, R"pbdoc()pbdoc", py::return_value_policy::take_ownership); -}; - -#include "Tools/types.h" -template class aff3ct::wrapper::Wrapper_Source_user_numpy; \ No newline at end of file diff --git a/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.hpp b/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.hpp deleted file mode 100644 index 317c363..0000000 --- a/template/src/Wrapper_py/Module/Source/User/Source_user_numpy.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @file Source_user_numpy.hpp - * @author Sciroccogti (scirocco_gti@yeah.net) - * @brief - * @date 2024-03-13 20:04:16 - * @modified: 2024-03-13 21:32:45 - */ - -#ifndef WRAPPER_SOURCE_USER_NUMPY_HPP_ -#define WRAPPER_SOURCE_USER_NUMPY_HPP_ - - -#include -#include -#include - -#include "Module/Source/User/Source_user_numpy.hpp" - -#include "Wrapper_py/Wrapper_py.hpp" - -namespace py = pybind11; -using namespace aff3ct; -using namespace aff3ct::module; -using namespace aff3ct::tools; - -namespace aff3ct -{ -namespace wrapper -{ -template -class Wrapper_Source_user_numpy : public Wrapper_py, - public py::class_, aff3ct::module::Source> -{ - public: - Wrapper_Source_user_numpy(py::handle scope); - virtual void definitions(); - virtual ~Wrapper_Source_user_numpy() = default; -}; -} -} -#endif //WRAPPER_SOURCE_USER_NUMPY_HPP_ \ No newline at end of file diff --git a/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp b/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp new file mode 100644 index 0000000..7a78fec --- /dev/null +++ b/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp @@ -0,0 +1,61 @@ +/** + * @file Tunnel_numpy.cpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-14 14:58:53 + * @modified: 2024-03-15 15:54:01 + */ + +#include "Wrapper_py/Module/Tunnel/Tunnel_numpy.hpp" + +namespace py = pybind11; +using namespace py::literals; +using namespace aff3ct; +using namespace aff3ct::module; +using namespace aff3ct::tools; +using namespace aff3ct::wrapper; + +template +Wrapper_Tunnel_numpy +::Wrapper_Tunnel_numpy(py::handle scope, const std::string& type) +: Wrapper_py(), + py::class_,aff3ct::module::Module>(scope, std::string("Tunnel_numpy_" + type).c_str()) +{ +} + +template +void Wrapper_Tunnel_numpy +::definitions() +{ + this->def(py::init(),"K"_a, "N"_a, R"pbdoc()pbdoc", py::return_value_policy::take_ownership); + this->def("get_K", &aff3ct::module::Tunnel_numpy::get_K, R"pbdoc()pbdoc"); + this->def("get_N", &aff3ct::module::Tunnel_numpy::get_N, R"pbdoc()pbdoc"); + this->def("append", &aff3ct::module::Tunnel_numpy::append, R"pbdoc()pbdoc"); + this->def("get", &aff3ct::module::Tunnel_numpy::get, R"pbdoc()pbdoc"); + this->def("set_data", &aff3ct::module::Tunnel_numpy::set_data, R"pbdoc()pbdoc"); + this->def("get_data", &aff3ct::module::Tunnel_numpy::get_data, R"pbdoc()pbdoc"); + this->def("is_append_done", &aff3ct::module::Tunnel_numpy::is_append_done, R"pbdoc()pbdoc"); + this->def("is_get_done", &aff3ct::module::Tunnel_numpy::is_get_done, R"pbdoc()pbdoc"); + this->def("reset", &aff3ct::module::Tunnel_numpy::reset, R"pbdoc()pbdoc"); + this->def_property_readonly("tasks", [](Tunnel_numpy& self)-> std::vector> { return self.tasks; },R"pbdoc(List of tasks: +* **append**: Task method method appends a vector to the buffer. +* **get**: Task method method gets a vector from the buffer. + + * U_K: a vector of bits to append. +)pbdoc"); + this->doc() = R"pbdoc(Fetches a message. + +Parameters: + + * B: type of the bits in the Tunnel. +)pbdoc"; +}; + +#include "Tools/types.h" + +template class aff3ct::wrapper::Wrapper_Tunnel_numpy; +template class aff3ct::wrapper::Wrapper_Tunnel_numpy; +template class aff3ct::wrapper::Wrapper_Tunnel_numpy; +template class aff3ct::wrapper::Wrapper_Tunnel_numpy; +template class aff3ct::wrapper::Wrapper_Tunnel_numpy; +template class aff3ct::wrapper::Wrapper_Tunnel_numpy; diff --git a/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.hpp b/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.hpp new file mode 100644 index 0000000..8366d03 --- /dev/null +++ b/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.hpp @@ -0,0 +1,40 @@ +/** + * @file Tunnel_numpy.hpp + * @author Sciroccogti (scirocco_gti@yeah.net) + * @brief + * @date 2024-03-14 14:59:01 + * @modified: 2024-03-15 15:55:05 + */ + +#ifndef WRAPPER_TUNNEL_NUMPY_HPP_ +#define WRAPPER_TUNNEL_NUMPY_HPP_ + +#include +#include +#include + +#include "Module/Tunnel/Tunnel_numpy.hpp" + +#include "Wrapper_py/Wrapper_py.hpp" + +namespace py = pybind11; +using namespace aff3ct; +using namespace aff3ct::module; +using namespace aff3ct::tools; + +namespace aff3ct +{ +namespace wrapper +{ +template +class Wrapper_Tunnel_numpy : public Wrapper_py, + public py::class_, aff3ct::module::Module> +{ + public: + Wrapper_Tunnel_numpy(py::handle scope, const std::string& type); + virtual void definitions(); + virtual ~Wrapper_Tunnel_numpy() = default; +}; +} +} +#endif //WRAPPER_TUNNEL_NUMPY_HPP_ From a22fbec94cd145dfd614cfd3f0d5624b34c03e25 Mon Sep 17 00:00:00 2001 From: Sciroccogti Date: Fri, 15 Mar 2024 16:55:22 +0800 Subject: [PATCH 6/8] add is_done for Tunnel_numpy --- template/src/Module/Tunnel/Tunnel_numpy.cpp | 43 ++++++++++--------- template/src/Module/Tunnel/Tunnel_numpy.hpp | 13 +++--- .../Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp | 7 ++- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/template/src/Module/Tunnel/Tunnel_numpy.cpp b/template/src/Module/Tunnel/Tunnel_numpy.cpp index b30f7bb..56d2830 100644 --- a/template/src/Module/Tunnel/Tunnel_numpy.cpp +++ b/template/src/Module/Tunnel/Tunnel_numpy.cpp @@ -3,7 +3,7 @@ * @author Sciroccogti (scirocco_gti@yeah.net) * @brief * @date 2024-03-13 18:00:38 - * @modified: 2024-03-15 15:53:44 + * @modified: 2024-03-15 16:32:18 */ #include "Module/Tunnel/Tunnel_numpy.hpp" @@ -39,14 +39,19 @@ Socket& Tunnel_numpy::operator[](const ftr::sck::get s) } template -Tunnel_numpy::Tunnel_numpy(const int K, const int N) +Tunnel_numpy::Tunnel_numpy(const int K, const int N, const bool is_out) : Module() , K(K) , N(N) + , is_out(is_out) { const std::string name = "Tunnel_numpy"; this->set_name(name); + this->append_done = false; + this->get_done = false; + this->counter = 0; + if (K <= 0 || N <= 0) { std::stringstream message; message << "'K', and 'N' have to be greater than 0 ('K' = " << K @@ -99,6 +104,11 @@ int Tunnel_numpy::get_N() const template void Tunnel_numpy::append(std::vector& U_K) { + if (this->is_out) { + std::stringstream message; + message << "The tunnel is an output tunnel, you can't append data to it."; + throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); + } (*this)[ftr::sck::append::U_K].bind(U_K.data()); (*this)[ftr::tsk::append].exec(); } @@ -106,6 +116,11 @@ void Tunnel_numpy::append(std::vector& U_K) template void Tunnel_numpy::get(std::vector& U_K) { + if (!this->is_out) { + std::stringstream message; + message << "The tunnel is an input tunnel, you can't get data from it."; + throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); + } (*this)[ftr::sck::get::U_K].bind(U_K.data()); (*this)[ftr::tsk::get].exec(); } @@ -144,26 +159,14 @@ void Tunnel_numpy::_get(B* U_K) } } -// template -// void Tunnel_numpy::_get_data(B* data) const -// { -// std::vector data_vec; -// for (auto& U_K : this->data) { -// std::copy(U_K.begin(), U_K.end(), data_vec.end()); -// } -// std::copy(data_vec.begin(), data_vec.end(), data); -// } - -template -bool Tunnel_numpy::is_append_done() const -{ - return this->append_done; -} - template -bool Tunnel_numpy::is_get_done() const +bool Tunnel_numpy::is_done() const { - return this->get_done; + if (this->is_out) { + return this->get_done; + } else { + return this->append_done; + } } template diff --git a/template/src/Module/Tunnel/Tunnel_numpy.hpp b/template/src/Module/Tunnel/Tunnel_numpy.hpp index 12c08e5..125ef59 100644 --- a/template/src/Module/Tunnel/Tunnel_numpy.hpp +++ b/template/src/Module/Tunnel/Tunnel_numpy.hpp @@ -3,7 +3,7 @@ * @author Sciroccogti (scirocco_gti@yeah.net) * @brief * @date 2024-03-13 18:00:30 - * @modified: 2024-03-15 15:55:06 + * @modified: 2024-03-15 16:31:41 */ #ifndef TUNNEL_NUMPY_HPP_ @@ -39,7 +39,7 @@ namespace module { template class Tunnel_numpy : public Module, - // public tools::Interface_is_done, + public tools::Interface_is_done, public tools::Interface_reset { public: inline Task& operator[](const ftr::tsk t); @@ -51,11 +51,12 @@ namespace module { const size_t K; /*!< Number of information bits in one frame */ const size_t N; /*!< Number of frames */ size_t counter; + bool is_out; bool append_done; bool get_done; public: - Tunnel_numpy(const int K, const int N); + Tunnel_numpy(const int K, const int N, const bool is_out); ~Tunnel_numpy() = default; @@ -73,9 +74,7 @@ namespace module { std::vector> get_data() const; - bool is_append_done() const; - - bool is_get_done() const; + bool is_done() const; void reset(); @@ -83,8 +82,6 @@ namespace module { void _append(B* U_K); void _get(B* U_K); - - // void _get_data(B* data) const; }; } } diff --git a/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp b/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp index 7a78fec..e0a61f2 100644 --- a/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp +++ b/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp @@ -3,7 +3,7 @@ * @author Sciroccogti (scirocco_gti@yeah.net) * @brief * @date 2024-03-14 14:58:53 - * @modified: 2024-03-15 15:54:01 + * @modified: 2024-03-15 16:34:14 */ #include "Wrapper_py/Module/Tunnel/Tunnel_numpy.hpp" @@ -27,15 +27,14 @@ template void Wrapper_Tunnel_numpy ::definitions() { - this->def(py::init(),"K"_a, "N"_a, R"pbdoc()pbdoc", py::return_value_policy::take_ownership); + this->def(py::init(),"K"_a, "N"_a, "is_out"_a, R"pbdoc()pbdoc", py::return_value_policy::take_ownership); this->def("get_K", &aff3ct::module::Tunnel_numpy::get_K, R"pbdoc()pbdoc"); this->def("get_N", &aff3ct::module::Tunnel_numpy::get_N, R"pbdoc()pbdoc"); this->def("append", &aff3ct::module::Tunnel_numpy::append, R"pbdoc()pbdoc"); this->def("get", &aff3ct::module::Tunnel_numpy::get, R"pbdoc()pbdoc"); this->def("set_data", &aff3ct::module::Tunnel_numpy::set_data, R"pbdoc()pbdoc"); this->def("get_data", &aff3ct::module::Tunnel_numpy::get_data, R"pbdoc()pbdoc"); - this->def("is_append_done", &aff3ct::module::Tunnel_numpy::is_append_done, R"pbdoc()pbdoc"); - this->def("is_get_done", &aff3ct::module::Tunnel_numpy::is_get_done, R"pbdoc()pbdoc"); + this->def("is_done", &aff3ct::module::Tunnel_numpy::is_done, R"pbdoc()pbdoc"); this->def("reset", &aff3ct::module::Tunnel_numpy::reset, R"pbdoc()pbdoc"); this->def_property_readonly("tasks", [](Tunnel_numpy& self)-> std::vector> { return self.tasks; },R"pbdoc(List of tasks: * **append**: Task method method appends a vector to the buffer. From 9d63eacd7f0d50f9c89318bb082dd177bc5f1fb2 Mon Sep 17 00:00:00 2001 From: Sciroccogti Date: Fri, 15 Mar 2024 20:05:17 +0800 Subject: [PATCH 7/8] implement Tunnel_numpy.reset --- template/src/Module/Tunnel/Tunnel_numpy.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/template/src/Module/Tunnel/Tunnel_numpy.cpp b/template/src/Module/Tunnel/Tunnel_numpy.cpp index 56d2830..de68dc2 100644 --- a/template/src/Module/Tunnel/Tunnel_numpy.cpp +++ b/template/src/Module/Tunnel/Tunnel_numpy.cpp @@ -3,7 +3,7 @@ * @author Sciroccogti (scirocco_gti@yeah.net) * @brief * @date 2024-03-13 18:00:38 - * @modified: 2024-03-15 16:32:18 + * @modified: 2024-03-15 20:03:58 */ #include "Module/Tunnel/Tunnel_numpy.hpp" @@ -173,6 +173,9 @@ template void Tunnel_numpy::reset() { this->data.clear(); + this->get_done = false; + this->append_done = false; + this->counter = 0; } #include "Tools/types.h" From a9655c461d2640e71de25527cf769b8c8cf3eb4a Mon Sep 17 00:00:00 2001 From: Sciroccogti Date: Fri, 15 Mar 2024 20:15:23 +0800 Subject: [PATCH 8/8] add set_N for Tunnel_numpy --- template/src/Module/Tunnel/Tunnel_numpy.cpp | 8 +++++++- template/src/Module/Tunnel/Tunnel_numpy.hpp | 18 ++++++++++-------- .../Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp | 3 ++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/template/src/Module/Tunnel/Tunnel_numpy.cpp b/template/src/Module/Tunnel/Tunnel_numpy.cpp index de68dc2..f920f83 100644 --- a/template/src/Module/Tunnel/Tunnel_numpy.cpp +++ b/template/src/Module/Tunnel/Tunnel_numpy.cpp @@ -3,7 +3,7 @@ * @author Sciroccogti (scirocco_gti@yeah.net) * @brief * @date 2024-03-13 18:00:38 - * @modified: 2024-03-15 20:03:58 + * @modified: 2024-03-15 20:14:20 */ #include "Module/Tunnel/Tunnel_numpy.hpp" @@ -137,6 +137,12 @@ std::vector> Tunnel_numpy::get_data() const return this->data; } +template +void Tunnel_numpy::set_N(const int N) +{ + this->N = (size_t)N; +} + template void Tunnel_numpy::_append(B* U_K) { diff --git a/template/src/Module/Tunnel/Tunnel_numpy.hpp b/template/src/Module/Tunnel/Tunnel_numpy.hpp index 125ef59..64f346e 100644 --- a/template/src/Module/Tunnel/Tunnel_numpy.hpp +++ b/template/src/Module/Tunnel/Tunnel_numpy.hpp @@ -3,7 +3,7 @@ * @author Sciroccogti (scirocco_gti@yeah.net) * @brief * @date 2024-03-13 18:00:30 - * @modified: 2024-03-15 16:31:41 + * @modified: 2024-03-15 20:14:08 */ #ifndef TUNNEL_NUMPY_HPP_ @@ -39,8 +39,8 @@ namespace module { template class Tunnel_numpy : public Module, - public tools::Interface_is_done, - public tools::Interface_reset { + public tools::Interface_is_done, + public tools::Interface_reset { public: inline Task& operator[](const ftr::tsk t); inline Socket& operator[](const ftr::sck::append s); @@ -49,7 +49,7 @@ namespace module { protected: std::vector> data; const size_t K; /*!< Number of information bits in one frame */ - const size_t N; /*!< Number of frames */ + size_t N; /*!< Number of frames */ size_t counter; bool is_out; bool append_done; @@ -62,10 +62,6 @@ namespace module { Tunnel_numpy* clone() const; - int get_K() const; - - int get_N() const; - void append(std::vector& U_K); void get(std::vector& U_K); @@ -74,6 +70,12 @@ namespace module { std::vector> get_data() const; + void set_N(const int N); + + int get_K() const; + + int get_N() const; + bool is_done() const; void reset(); diff --git a/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp b/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp index e0a61f2..bada2c6 100644 --- a/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp +++ b/template/src/Wrapper_py/Module/Tunnel/Tunnel_numpy.cpp @@ -3,7 +3,7 @@ * @author Sciroccogti (scirocco_gti@yeah.net) * @brief * @date 2024-03-14 14:58:53 - * @modified: 2024-03-15 16:34:14 + * @modified: 2024-03-15 20:13:41 */ #include "Wrapper_py/Module/Tunnel/Tunnel_numpy.hpp" @@ -34,6 +34,7 @@ ::definitions() this->def("get", &aff3ct::module::Tunnel_numpy::get, R"pbdoc()pbdoc"); this->def("set_data", &aff3ct::module::Tunnel_numpy::set_data, R"pbdoc()pbdoc"); this->def("get_data", &aff3ct::module::Tunnel_numpy::get_data, R"pbdoc()pbdoc"); + this->def("set_N", &aff3ct::module::Tunnel_numpy::set_N, R"pbdoc()pbdoc"); this->def("is_done", &aff3ct::module::Tunnel_numpy::is_done, R"pbdoc()pbdoc"); this->def("reset", &aff3ct::module::Tunnel_numpy::reset, R"pbdoc()pbdoc"); this->def_property_readonly("tasks", [](Tunnel_numpy& self)-> std::vector> { return self.tasks; },R"pbdoc(List of tasks: