LCOV - code coverage report
Current view: top level - src/Module/Delayer - Delayer.cpp (source / functions) Hit Total Coverage
Test: streampu_clean.info Lines: 0 57 0.0 %
Date: 2024-06-12 12:04:18 Functions: 0 100 0.0 %

          Line data    Source code
       1             : #include <complex>
       2             : #include <sstream>
       3             : 
       4             : #include "Module/Delayer/Delayer.hpp"
       5             : 
       6             : using namespace spu;
       7             : using namespace spu::module;
       8             : 
       9             : template<typename D>
      10           0 : Delayer<D>::Delayer(const size_t size, const D init_val)
      11             :   : Module()
      12           0 :   , size(size)
      13           0 :   , init_val(init_val)
      14           0 :   , data(this->size * this->n_frames, init_val)
      15             : {
      16           0 :     const std::string name = "Delayer";
      17           0 :     this->set_name(name);
      18           0 :     this->set_short_name(name);
      19             : 
      20           0 :     if (size <= 0)
      21             :     {
      22           0 :         std::stringstream message;
      23           0 :         message << "'size' has to be greater than 0 ('size' = " << size << ").";
      24           0 :         throw spu::tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
      25           0 :     }
      26             : 
      27           0 :     auto& p1 = this->create_task("memorize");
      28           0 :     auto p1s_in = this->template create_socket_in<D>(p1, "in", this->size);
      29           0 :     this->create_codelet(p1,
      30           0 :                          [p1s_in](module::Module& m, runtime::Task& t, const size_t frame_id) -> int
      31             :                          {
      32           0 :                              static_cast<Delayer<D>&>(m)._memorize(t[p1s_in].template get_dataptr<const D>(), frame_id);
      33           0 :                              return runtime::status_t::SUCCESS;
      34             :                          });
      35             : 
      36           0 :     auto& p2 = this->create_task("produce");
      37           0 :     auto p2s_out = this->template create_socket_out<D>(p2, "out", this->size);
      38           0 :     this->create_codelet(p2,
      39           0 :                          [p2s_out](module::Module& m, runtime::Task& t, const size_t frame_id) -> int
      40             :                          {
      41           0 :                              static_cast<Delayer<D>&>(m)._produce(t[p2s_out].template get_dataptr<D>(), frame_id);
      42           0 :                              return runtime::status_t::SUCCESS;
      43             :                          });
      44           0 : }
      45             : 
      46             : template<typename D>
      47             : Delayer<D>*
      48           0 : Delayer<D>::clone() const
      49             : {
      50           0 :     auto m = new Delayer(*this);
      51           0 :     m->deep_copy(*this);
      52           0 :     return m;
      53             : }
      54             : 
      55             : template<typename D>
      56             : size_t
      57           0 : Delayer<D>::get_size() const
      58             : {
      59           0 :     return size;
      60             : }
      61             : 
      62             : template<typename D>
      63             : void
      64           0 : Delayer<D>::_memorize(const D* in, const size_t frame_id)
      65             : {
      66           0 :     std::copy(in, in + this->size, this->data.data() + this->size * frame_id);
      67           0 : }
      68             : 
      69             : template<typename D>
      70             : void
      71           0 : Delayer<D>::_produce(D* out, const size_t frame_id)
      72             : {
      73           0 :     std::copy(this->data.data() + this->size * (frame_id + 0), this->data.data() + this->size * (frame_id + 1), out);
      74           0 : }
      75             : 
      76             : template<typename D>
      77             : void
      78           0 : Delayer<D>::set_n_frames(const size_t n_frames)
      79             : {
      80           0 :     const auto old_n_frames = this->get_n_frames();
      81           0 :     if (old_n_frames != n_frames)
      82             :     {
      83           0 :         Module::set_n_frames(n_frames);
      84             : 
      85           0 :         const auto old_data_size = this->data.size();
      86           0 :         const auto new_data_size = (old_data_size / old_n_frames) * n_frames;
      87           0 :         this->data.resize(new_data_size, this->init_val);
      88             :     }
      89           0 : }
      90             : 
      91             : template<typename D>
      92             : void
      93           0 : Delayer<D>::set_data(const std::vector<D>& init)
      94             : {
      95           0 :     if (init.size() < this->data.size())
      96             :     {
      97           0 :         std::stringstream message;
      98           0 :         message << "'init.size()' has to be greater than data.size() ('init.size(' = " << init.size()
      99           0 :                 << ", 'data.size()' = " << this->data.size() << ").";
     100           0 :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
     101           0 :     }
     102           0 :     std::copy(init.begin(), init.begin() + this->data.size(), this->data.begin());
     103           0 : }
     104             : 
     105             : template<typename D>
     106             : void
     107           0 : Delayer<D>::set_data(const D* init)
     108             : {
     109           0 :     std::copy(init, init + this->data.size(), this->data.begin());
     110           0 : }
     111             : 
     112             : // ==================================================================================== explicit template instantiation
     113             : template class spu::module::Delayer<int8_t>;
     114             : template class spu::module::Delayer<uint8_t>;
     115             : template class spu::module::Delayer<int16_t>;
     116             : template class spu::module::Delayer<uint16_t>;
     117             : template class spu::module::Delayer<int32_t>;
     118             : template class spu::module::Delayer<uint32_t>;
     119             : template class spu::module::Delayer<int64_t>;
     120             : template class spu::module::Delayer<uint64_t>;
     121             : template class spu::module::Delayer<float>;
     122             : template class spu::module::Delayer<double>;
     123             : // ==================================================================================== explicit template instantiation

Generated by: LCOV version 1.14