3.3. Vector Operations

VSIPL++ Vector objects represent one-dimensional sets of data. The type of values stored in the vector is given by the first template argument.

3.3.1. Vector Generation Functions

A = 0
Clears vector to value 0.
A = value
Fills vector with scalar value value.
A = ramp(init, step, size)
Fills vector with ramp function. The nth of element of A is set to init + n * step.

3.3.2. Vector Copy

Z = A
Copies value from vector A into vector Z.

3.3.3. Vector Arithmetic Elementwise Unary Operations and Functions

The following elementwise unary operations can be performed on vectors, producing a vector result:

acos(A)
Trigonometric arc cosine (section 4.2.1)
arg(A)
Phase angle of complex (section 4.2.4)
asin(A)
Trigonometric arc sine (section 4.2.5)
atan(A)
Trigonometric arc tangent (section 4.2.6)
bnot(A)
Boolean not (section 4.2.35)
ceil(A)
Round floating-point value up to next integral value (section 4.2.12)
conj(A)
Complex conjugate (section 4.2.13)
cos(A)
Trigonometric cosine (section 4.2.14)
cosh(A)
Hyperbolic cosine (section 4.2.15)
euler(A)
Rotate complex unit vector by angle (section 4.2.18)
exp(A)
Natural exponential (section 4.2.19)
exp10(A)
Base-10 exponential (section 4.2.20)
floor(A)
Round floating-point value down to next integral value (section 4.2.22)
imag(A)
Imaginary part of complex (section 4.2.27)
is_finite(A)
Is floating-point value finite (section 4.2.29)
is_nan(A)
Is floating-point value not a number (NaN) (section 4.2.29)
is_normal(A)
Is floating-point value normal (section 4.2.30)
lnot(A)
Logical not (section 4.2.35)
log(A)
Base-e logarithm (section 4.2.36)
log10(A)
Base-10 logarithm (section 4.2.37)
mag(A)
Magnitude (section 4.2.42)
magsq(A)
Magnitude squared (section 4.2.43)
neg(A)
Negation (section 4.2.53)
real(A)
Real part of complex (section 4.2.55)
recip(A)
Recipricol (section 4.2.56)
rsqrt(A)
Recipricol square root (section 4.2.57)
sin(A)
Trigonometric sine (section 4.2.59)
sinh(A)
Hyperbolic sine (section 4.2.60)
sq(A)
Square (section 4.2.61)
sqrt(A)
Square root (section 4.2.62)
tan(A)
Trigonometric tangent (section 4.2.64)
tanh(A)
Hyperbolic tangent (section 4.2.65)

3.3.4. Vector Arithmetic Elementwise Binary Operations and Functions

The following elementwise binary operations can be performed on vectors, producing a vector result:

add(A)
Addition (section 4.2.2)
atan2(A)
Arc tangent of quotient (section 4.2.7)
band(A)
Bitwise and (section 4.2.8)
bor(A)
Bitwise or (section 4.2.9)
bxor(A)
Bitwise exclusive or (section 4.2.11)
div(A)
Division (section 4.2.16)
eq(A)
Equality comparison (section 4.2.17)
fmod(A)
Floating-point modulo (remainder after division) (section 4.2.23)
ge(A)
Greater-than or equal comparison (section 4.2.24)
gt(A)
Greater-than comparison (section 4.2.25)
hypot(A)
Hypotenuse of right triangle (section 4.2.26)
jmul(A)
Conjugate multiply (section 4.2.32)
land(A)
Logical and (section 4.2.33)
le(A)
Less-than or equal comparison (section 4.2.34)
lor(A)
Logical or (section 4.2.38)
lt(A)
Less-than comparison (section 4.2.39)
lxor(A)
Logical exclusive or (section 4.2.40)
max(A)
Maxima (section 4.2.44)
maxmg(A)
Magnitude maxima (section 4.2.45)
maxmgsq(A)
Magnitude squared maxima (section 4.2.46)
min(A)
Minima (section 4.2.47)
minmg(A)
Magnitude minima (section 4.2.48)
minmgsq(A)
Magnitude squared minima (section 4.2.49)
mul(A)
Multiplication (section 4.2.51)
ne(A)
Not equal comparison (section 4.2.52)
pow(A)
Raise to power (section 4.2.54)
sub(A)
Subtract (section 4.2.63)

3.3.5. Vector Arithmetic Elementwise Ternary Operations and Functions

The following elementwise ternary operations can be performed on vectors, producing a vector result:

am(A)
Fused addition-multiplication (section 4.2.3)
expoavg(A)
Exponential average (section 4.2.21)
ite(A)
Addition (section 4.2.31)
ma(A)
Fused multiplication-addition (section 4.2.41)
msb(A)
Fused multiplication-subtraction (section 4.2.50)
sbm(A)
Fused subtraction-multiplication (section 4.2.58)

3.3.6. Vector Type Conversions

A vector with one type of values can be converted a vector with another type of values using view_cast.

For example, to convert a vector of floats A into a vector of ints Z:

Vector<float> A(size);
Vector<int>   Z(size);
Z = view_cast<int>(A)

3.3.7. Vector Arithmetic Elementwise Binary Operations and Functions

The following arithmetic elementwise binary operations and functions are available on vectors:

Z = add(A, B)
Addition, Z(n) = A(n) + B(n)(section 4.2.2)
Z = div(A, B)
Division, Z(n) = A(n) / B(n)(section 4.2.16)
Z = max(A, B)
Maximum of A(n) and B(n)
Z = min(A, B)
Minimum of A(n) and B(n)
Z = mul(A, B)
Multiplication, Z(n) = A(n) * B(n)(section 4.2.51)
Z = sub(A, B)
Subtraction, Z(n) = A(n) - B(n)(section 4.2.63)

Addition, subtraction, multiplication, and division can also be written in operator form:

Z = A + B
equivalent to Z = add(A, B)
Z = A - B
equivalent to Z = sub(A, B)
Z = A * B
equivalent to Z = mul(A, B)
Z = A / B
equivalent to Z = div(A, B)

In all the preceding functions and operations, either of the vector operands can be replaced with scalar operands.

For example, to perform a scalar-vector multiply:

Z = a * B;

or

Z = mul(a, B);

3.3.8. Vector Logical Elementwise Binary Operations and Functions

Z = eq(A, B)
Z(n) = A(n) == B(n)
Z = gt(A, B)
Z(n) = A(n) > B(n)
Z = gte(A, B)
Z(n) = A(n) >= B(n)
Z = lt(A, B)
Z(n) = A(n) < B(n)
Z = lte(A, B)
Z(n) = A(n) <= B(n)
Z = ne(A, B)
Z(n) = A(n) != B(n)

3.3.9. Vector Arithmetic Elementwise Ternary Operations and Functions

The following arithmetic elementwise ternary operations and functions are available on vectors:

Z = ma(A, B, C)
Multiply-add, Z(n) = A(n) * B(n) + C(n)
Z = am(A, B, C)
Add-multiply, Z(n) = A(n) + B(n) * C(n)

In all the preceding functions and operations, one or more of the vector operands can be replaced with scalar operands.

For example, to scale a vector, then apply an offset:

Z = scale * A + offset;

or

Z = ma(scale, A, offset);

(where scale and offset are scalar values)

3.3.10. Vector Non-Arithmetic Elementwise Ternary Operations and Functions

Z = ite(bool_vector, A, B)
For the nth element of Z, sets value to nth element ofA if nth element of bool_vector is true, otherwise sets value to the nth element of B.Notionally equivalent to C ?: operator.(Foreach n) Z[n] = bool_vector[n] ? A[n] : B[n]

In all the preceding functions and operations, one or more of the vector operands can be replaced with scalar operands.

For example, the apply a scalar threshold b to a vector:

Z = ite(A > b, A, b);

3.3.11. Vector Reductions

The following functions reduce a vector to a single value:

z = alltrue(A)
When the element type of A is bool, the function returns true if all the elements are true; otherwise false. When the element type is something else, see (section 4.3.1) for more information.
z = anytrue(A)
When the element type of A is bool, the function returns true if any elements are true; otherwise false. When the element type is something else, see (section 4.3.2) for more information.
z = sumval(A)
Return the sum of A's values.
z = sumsqval(A)
Return the sum of the squares of A's values.
z = meanval(A)
Return the mean of A's values.
z = meansqval(A)
Return the mean of squares of A's values.

The following functions reduce a vector to a single value that corresponds to an element within the vector.

z = maxval(A, idx)
return the maximum value of A. Set idx to the index of this element (A.get(idx) == z).
z = maxmgval(A, idx)
return the maximum value of the magnitude of A. Set idx to the index of this element (mag(A.get(idx)) == z).
z = maxmgsqval(A, idx)
return the maximum value of the magnitude squared of A. Set idx to the index of this element (magsq(A.get(idx)) == z).
z = minval(A, idx)
return the minimum value of A. Set idx to the index of this element (A.get(idx) == z).
z = minmgval(A, idx)
return the minimum value of the magnitude of A. Set idx to the index of this element (mag(A.get(idx)) == z).
z = minmgsqval(A, idx)
return the minimum value of the magnitude squared of A. Set idx to the index of this element (magsq(A.get(idx)) == z).

3.3.12. Vector Linear Algebra

z = cvjdot(A, B)
conjugate dot-product (section 4.4.2)
Z = kron(A, B)
kronecker-product (section 4.4.7)
z = dot(A, B)
dot-product (section 4.4.3)
Z = outer(A, B)
outer-product (section 4.4.9)

3.3.13. Vector Window Functions

Z = blackman(len)
Construct and return a vector containing a Blackman window of length len. (section 4.7.1)
Z = cheby(len, ripple)
Construct and return a vector containing Dolph-Chebyshev window weights with user-specified ripple and having length len. (section 4.7.2)
Z = hanning(len)
Construct and return a vector containing a Hanning window of length len. (section 4.7.4)
Z = kaiser(len, beta)
Construct and return a vector containing Kaiser window weights with transition width beta and having length len. (section 4.7.5)

3.3.14. Vector Convolution

VSIPL++ provides facilities to perform convolutions on vectors through the class template Convolution (section 4.8.1). Once constructed with compile-time selections, a convolution object can be applied to an input vector to produce results in an output vector.

3.3.15. Vector Correlation

VSIPL++ provides facilities to perform correlations on vectors through the class template Correlation (section 4.8.2). Once constructed with compile-time selections, a correlation object can be applied to an input vector and a kernel vector to produce results in an output vector.

3.3.16. Vector FIR Filter

VSIPL++ provides facilities to perform an FIR filter on vectors through the class template Fir (section 4.8.3). Once constructed with compile-time selections, an FIR object can be applied to an input vector to produce results in an output vector.

3.3.17. Vector Histogram

VSIPL++ provides facilities to perform an histogram on vectors through the class template Histogram. Once constructed with compile-time selections, a histogram object can be applied to an input vector to produce results in an output vector.

  

3.3.18. Vector Random Number Generation

     

VSIPL++ provides facilities to generate vectors of random number   through the class template Rand. Once constructed with compile-time selections, a Rand object can generate a vector of random numbers through   the invocation of one of its member functions..

 

3.3.19. Vector Frequency Swap

VSIPL++ provides a function freqswap to swap halves of vectors. (section 4.7.3)

3.3.20. Vector Subviews

VSIPL++ allows subviews of vectors to be created. A subview represents a subset of the original vector. The subview aliases the original vector, that is changes to the subview will be reflected in the original vector, and visa versa.

A(Domain<1>(start, stride, size))
Create subview of vector. Subview is of sizesize.The nth element of the subview refers to thestart + n*stride element ofA.

3.3.21. Subview Vector Variables

To represent a vector subview in a variable, it is necessary to use the correct block type. Otherwise the variable will copy the values in the subview.

Vector<T>::subview_type A = view(Domain<1>(f, s, l));

3.3.22. Special Vector Subviews of Complex Vectors.

real(A)
returns subview of real values in complex vector A
imag(A)
returns subview of real values in complex vector A

3.3.23. User-Defined Functions on Vectors

User-defined functions that accept a vector as a parameter should use a template parameter to represent the vector's block type. This allows vectors with different block types, such as those created by subview operators, to be handled by the function.

For example, to write a function that accepts a vector of floating-point values:

template <typename BlockT>
...
function(Vector<float, BlockT> vector)
{
   ...
}

If the function can handle different value types (such as single- and double-precision), the value type can also be made a template parameter:

template <typename, T
          typename BlockT>
...
function(Vector<T, BlockT> vector)
{
   ...
}