The use of vectors has been explained in example with vector operations and focusing on float32_t.
The vector template is defined as:
P is the datatype of vector elementsL is the static length of the vector (length known at build time). L<0 when the length is dynamic and not known at build time. It is the default value.Allocator is the memory allocator. By default it is TMP_ALLOC that you can redefine since it is a macroVector_Base<P> is providing the storage. A vector owns its storage buffer.Example with Q15 is very similar:
The vectors are defined:
They are initialized:
Here, the Q15 value is initialized from the int value i and thus represents \( i/2^{15} \)
Some computation is done
The result is displayed:
A vector view is a virtual vector : a view of a vector.
One can define a VectorView with:
This is creating a virtual vector starting at index 2 (3rd element) of vector d.
You can then operate with this virtual vector:
If you display the vector d, you'll see that 2.0f has been added to all elements starting from the 2nd one.
VectorView do not own their memory. It is owned by the original vector.
If you write:
and x and y are VectorView, no copy will occur. x will just reference the same data as y. If you want to copy you have to be explicit and write:
It is advised to always use the copy operator (even with normal vectors).
Virtual vectors can have a stride:
This line sets the odd elements of the vector to 0.0f. It is creating a virtual vector with stride 2 and starting at index 1 of first vector.
Then, all elements of this virtual vector are set to 0.0f.
The sub API is:
You can define:
S : statically known and by default 1.0 by default)L by default : the length known at build time). Note that it is the first index after the end of the vector.