Ticket #39681: patch-vector-map.diff

File patch-vector-map.diff, 6.9 KB (added by michaelld (Michael Dickens), 11 years ago)
  • gr-blocks/include/gnuradio/blocks/vector_map.h

    diff --git a/gr-blocks/include/gnuradio/blocks/vector_map.h b/gr-blocks/include/gnuradio/blocks/vector_map.h
    index bd0e74c..587c642 100644
    a b namespace gr { 
    5050    public:
    5151      // gr::blocks::vector_map::sptr
    5252      typedef boost::shared_ptr<vector_map> sptr;
     53      typedef unsigned int vmap_t;
    5354
    5455      /*!
    5556       * Build a vector map block.
    namespace gr { 
    6061       * \param mapping (vector of vectors of vectors of integers) how to
    6162       *                map elements from input to output vectors
    6263       */
    63       static sptr make(size_t item_size, std::vector<size_t> in_vlens,
    64                        std::vector< std::vector< std::vector<size_t> > > mapping);
     64      static sptr make(size_t item_size, const std::vector<vmap_t>& in_vlens,
     65                       const std::vector< std::vector< std::vector<vmap_t> > >& mapping);
    6566
    66       virtual void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) = 0;
     67      virtual void set_mapping(const std::vector< std::vector< std::vector<vmap_t> > >& mapping) = 0;
    6768    };
    6869
    6970  } /* namespace blocks */
  • gr-blocks/lib/vector_map_impl.cc

    diff --git a/gr-blocks/lib/vector_map_impl.cc b/gr-blocks/lib/vector_map_impl.cc
    index d50dcb5..eae26c6 100644
    a b  
    3131namespace gr {
    3232  namespace blocks {
    3333
    34     std::vector<int>
    35     get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens)
     34    static std::vector<int>
     35    get_in_sizeofs(size_t item_size, const std::vector<vector_map::vmap_t> &in_vlens)
    3636    {
    3737      std::vector<int> in_sizeofs;
    38       for(unsigned int i = 0; i < in_vlens.size(); i++) {
     38      for(size_t i = 0; i < in_vlens.size(); i++) {
    3939        in_sizeofs.push_back(in_vlens[i]*item_size);
    4040      }
    4141      return in_sizeofs;
    4242    }
    4343
    44     std::vector<int>
     44    static std::vector<int>
    4545    get_out_sizeofs(size_t item_size,
    46                     std::vector< std::vector< std::vector<size_t> > > mapping)
     46                    const std::vector< std::vector< std::vector<vector_map::vmap_t> > > &mapping)
    4747    {
    4848      std::vector<int> out_sizeofs;
    49       for(unsigned int i = 0; i < mapping.size(); i++) {
     49      for(size_t i = 0; i < mapping.size(); i++) {
    5050        out_sizeofs.push_back(mapping[i].size()*item_size);
    5151      }
    5252      return out_sizeofs;
    53     } 
     53    }
    5454
    5555    vector_map::sptr
    56     vector_map::make(size_t item_size, std::vector<size_t> in_vlens,
    57                      std::vector< std::vector< std::vector<size_t> > > mapping)
     56    vector_map::make(size_t item_size, const std::vector<vector_map::vmap_t> &in_vlens,
     57                     const std::vector< std::vector< std::vector<vector_map::vmap_t> > > &mapping)
    5858    {
    5959      return gnuradio::get_initial_sptr
    6060        (new vector_map_impl(item_size, in_vlens, mapping));
    6161    }
    6262
    63     vector_map_impl::vector_map_impl(size_t item_size, std::vector<size_t> in_vlens,
    64                                      std::vector< std::vector< std::vector<size_t> > > mapping)
     63    vector_map_impl::vector_map_impl(size_t item_size, const std::vector<vector_map::vmap_t> &in_vlens,
     64                                     const std::vector< std::vector< std::vector<vector_map::vmap_t> > > &mapping)
    6565      : sync_block("vector_map",
    6666                      io_signature::makev(in_vlens.size(), in_vlens.size(),
    6767                                            get_in_sizeofs(item_size, in_vlens)),
    namespace gr { 
    7777    }
    7878
    7979    void
    80     vector_map_impl::set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping)
     80    vector_map_impl::set_mapping(const std::vector< std::vector< std::vector<vector_map::vmap_t> > > &mapping)
    8181    {
    8282      // Make sure the contents of the mapping vectors are possible.
    83       for(unsigned int i=0; i<mapping.size(); i++) {
    84         for(unsigned int j=0; j<mapping[i].size(); j++) {
     83      for(size_t i=0; i<mapping.size(); i++) {
     84        for(size_t j=0; j<mapping[i].size(); j++) {
    8585          if(mapping[i][j].size() != 2) {
    8686            throw std::runtime_error("Mapping must be of the form (out_mapping_stream1, out_mapping_stream2, ...), where out_mapping_stream1 is of the form (mapping_element1, mapping_element2, ...), where mapping_element1 is of the form (input_stream, input_element).  This error is raised because a mapping_element vector does not contain exactly 2 items.");
    8787          }
    88           unsigned int s = mapping[i][j][0];
    89           unsigned int index = mapping[i][j][1];
     88          vector_map::vmap_t s = mapping[i][j][0];
     89          vector_map::vmap_t index = mapping[i][j][1];
    9090          if(s >= d_in_vlens.size()) {
    9191            throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams.");
    9292          }
    namespace gr { 
    107107      const char **inv = (const char**)&input_items[0];
    108108      char **outv = (char**)&output_items[0];
    109109
    110       for(unsigned int n = 0; n < (unsigned int)(noutput_items); n++) {
    111         for(unsigned int i = 0; i < d_mapping.size(); i++) {
    112           unsigned int out_vlen = d_mapping[i].size();
    113           for(unsigned int j = 0; j < out_vlen; j++) {
    114             unsigned int s = d_mapping[i][j][0];
    115             unsigned int k = d_mapping[i][j][1];
     110      for(size_t n = 0; n < (size_t)(noutput_items); n++) {
     111        for(size_t i = 0; i < d_mapping.size(); i++) {
     112          size_t out_vlen = d_mapping[i].size();
     113          for(size_t j = 0; j < out_vlen; j++) {
     114            vector_map::vmap_t s = d_mapping[i][j][0];
     115            vector_map::vmap_t k = d_mapping[i][j][1];
    116116            memcpy(outv[i] + out_vlen*d_item_size*n +
    117117                   d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n +
    118118                   k*d_item_size, d_item_size);
  • gr-blocks/lib/vector_map_impl.h

    diff --git a/gr-blocks/lib/vector_map_impl.h b/gr-blocks/lib/vector_map_impl.h
    index 64f5e09..c0565da 100644
    a b namespace gr { 
    3333    {
    3434    private:
    3535      size_t d_item_size;
    36       std::vector<size_t> d_in_vlens;
    37       std::vector< std::vector< std::vector<size_t> > > d_mapping;
     36      std::vector<vmap_t> d_in_vlens;
     37      std::vector< std::vector< std::vector<vmap_t> > > d_mapping;
    3838      gr::thread::mutex d_mutex; // mutex to protect set/work access
    3939
    4040    public:
    41       vector_map_impl(size_t item_size, std::vector<size_t> in_vlens,
    42                       std::vector< std::vector< std::vector<size_t> > > mapping);
     41      vector_map_impl(size_t item_size, const std::vector<vmap_t> &in_vlens,
     42                      const std::vector< std::vector< std::vector<vmap_t> > > &mapping);
    4343      ~vector_map_impl();
    4444
    45       void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping);
     45      void set_mapping(const std::vector< std::vector< std::vector<vmap_t> > > &mapping);
    4646
    4747      int work(int noutput_items,
    4848               gr_vector_const_void_star &input_items,