# Blocks handling vectors

**URL:** <https://www.ruby-forum.com/t/blocks-handling-vectors/242856>\
**Category:** GNU Radio\
**Created:** [August 3, 2015, 9:19am UTC](https://www.ruby-forum.com/t/blocks-handling-vectors/242856 "2015-08-03T09:19:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [August 3, 2015, 9:19am UTC](https://www.ruby-forum.com/t/blocks-handling-vectors/242856/1 "2015-08-03T09:19:14Z")

</div>

Hi, I have been struggling a bit trying to code a block that accept for  
example vectors of sync\_len\*sizeof(float) as input signature and outputs  
vectors of (sync\_len+pkt\_len)\*sizeof(float) as output signature.

To understand how blocks handling vectors work, I tried to make the same  
block I did using single element items, which consists of a block that  
adds a preamble of sync\_len at the beginning of the sequence. It worked  
using single element items, instead of vectors but in the receiving  
part, should be a block that basically removes that preamble. In this  
case, it was so difficult the coding and did not get it, that is why I  
decided to try with vectors.

Now some doubts came to my mind. In the tutorials there is a gap  
concerning vectors or I haven’t found any processing block in the  
tutorial examples that explains a bit how vectors are processed.

- The io signatures would be defined like this:  
gr::io\_signature::make(1, 1, pkt\_len\*sizeof(float)),  
gr::io\_signature::make(1, 1, sizeof(float) \* (sync\_word\_len +  
pkt\_len)))  
To clarify a bit what I want is to add a predefined preamble of length  
sync\_word, which I define in the constructor and cannot be accessible.  
Now, one of my questions was, is the most suitable block that I have to  
use a general one? or is it possible to use a decimator?

- In my first implementation I used a general block:

void  
add\_sync\_impl::forecast (int noutput\_items, gr\_vector\_int  
&ninput\_items\_required)  
{  
ninput\_items\_required[0] = noutput\_items \* d\_pkt\_len;  
}

int  
add\_sync\_impl::general\_work (int noutput\_items,  
gr\_vector\_int &ninput\_items,  
gr\_vector\_const\_void\_star &input\_items,  
gr\_vector\_void\_star &output\_items)  
{  
const float \*in = (const float \*) input\_items[0];  
float \*out = (float \*) output\_items[0];

```
    // Do <+signal processing+>
    for (int i = 0; i < noutput_items; i++) {
        std::memcpy(&out[0], &d_sync_word[0], sizeof(float) * 

```

d\_sync\_word\_len);  
std::memcpy(&out[d\_sync\_word\_len], &in[0], sizeof(float) \*  
d\_pkt\_len);  
}  
// Tell runtime system how many input items we consumed on  
// each input stream.  
consume\_each (d\_pkt\_len);

```
    // Tell runtime system how many output items we produced.
    return noutput_items;
}

```

But when I try to connect the blocks to test them with python it gives  
me error:  
File “”, line 1, in   
File  
“/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier\_block2.py”,  
line 48, in wrapped  
raise ValueError(“Unable to coerce endpoint”)  
ValueError: Unable to coerce endpoint

I am doing something wrong, like copying the info into output wrongly,  
or I coded forecast wrongly or I am indicating wrongly the consumed  
items. I would thanks any kind of help or explanation about how block  
handles vectors.

As example: d\_sync\_word\_len = 3  
d\_sync\_word = {0, 0, 0}  
d\_pkt\_len = 5

Result(passed from vector to stream with a vector to stream block):  
input = (1, 1, 1, 1, 1, 1, 1, 1, 1, 1)  
output = (0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1)

I know that there are some blocks that already do this, but I was mostly  
interested in knowing how blocks handle vectors. Or also I would be  
interested to know the inverse block of vector\_insert (in python).  
Thanks before hand.

Gabriele Galiero

---

<div class="post-metadata">

**Author:** ![gabri187](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e9bcb4/32.png) [@gabri187](https://www.ruby-forum.com/u/gabri187)\
**Post date:** [August 3, 2015, 6:38pm UTC](https://www.ruby-forum.com/t/blocks-handling-vectors/242856/2 "2015-08-03T18:38:55Z")

</div>

On 03.08.2015 00:18, Galiero Casay Gabriele wrote:

> - The io signatures would be defined like this:  
> gr::io\_signature::make(1, 1, pkt\_len\*sizeof(float)),  
> gr::io\_signature::make(1, 1, sizeof(float) \* (sync\_word\_len +  
> pkt\_len)))  
> To clarify a bit what I want is to add a predefined preamble of length  
> sync\_word, which I define in the constructor and cannot be accessible.  
> Now, one of my questions was, is the most suitable block that I have to  
> use a general one? or is it possible to use a decimator?\

In this case, you can use a sync block, because you have 1 output items  
per 1 input item. However, you’re packaging entire packets as vectors –  
not sure if that’s your intention.

If you want to handle this on an item-by-item basis, you need a general  
block, because the relative rate is (sync\_len+pkt\_len)/pkt\_len, and  
that’s (most likely) non-integer. This approach can be convenient if  
your packets are very large, or if your packet length (with or without  
sync word) is an annoying size and doesn’t fit into page boundaries.

> ```
> for (int i = 0; i < noutput_items; i++) {
> std::memcpy(&out[0], &d_sync_word[0], sizeof(float) *
> 
> ```
> 
> d\_sync\_word\_len);  
> std::memcpy(&out[d\_sync\_word\_len], &in[0], sizeof(float) \*  
> d\_pkt\_len);  
> }  
> // Tell runtime system how many input items we consumed on  
> // each input stream.  
> consume\_each (d\_pkt\_len);

Nope, you’ve consumed noutput\_items.

> ```
> raise ValueError("Unable to coerce endpoint")
> 
> ```
> 
> ValueError: Unable to coerce endpoint

Well, we can’t see what you’re connecting this too, but it probably  
doesn’t have pkt\_len or pkt\_len+sync\_word vector lengths.

M
