2.4. Vector Objects

VSIPL++ Vector objects represent one-dimensional sets of data.

2.4.1. Vector Declarations

The type of values stored in the vector is given by the first template argument.

Examples:

Vector<scalar_f>
A vector of default (single-precision) floating-point values.
Vector<double>
A vector of double-precision floating-point values.
Vector<cscalar_f>
A vector of default (single-precision) complex values.
Vector<complex<double> >
A vector of double-precision complex values.

Optionally, the physical storage format can be controlled by the second template argument, which specifies the block type used to represent the data. If this is not specified, the default block type of Dense is used, which represents data stored in contiguous memory.

Example:

Vector<float, Dense<1, float> >
A vector of single-precision floating-point values, explicitly specified with Dense<1, float> storage.

Vectors can also be of type const_Vector, in which case their values cannot be modified directly.

2.4.2. Vector Constructors

Vectors are created by declaring an object of type Vector. The following constructors exist:

Vector<float> A(size)
Creates a vector with given size, with its values uninitialized.
Vector<float> A(size, value)
Creates a vector with given size, with its Values initialized to value.
Vector<float> A(block)
Creates a vector which is associated with the given data block.
Vector<float> A(vector)
Creates a vector which is a either a copy or an alias of the given vector, with type casts as necessary. (If A and vector have the same block type, a reference (alias) is created. Otherwise a copy is performed.)

Vectors of const_Vector type can only be constructed from existing Vectors with the block and vector constructor forms.

2.4.3. Vector Attributes

The following operations can be performed on a vector in order to determine various attributes.

A.size()
Returns the total number of elements in a vector.
A.size(d)
Returns the number of elements in the vector's dth dimension. Since vectors are one-dimensional, this is only defined for d = 0, and size(0) == size().
A.length()
Equivalent to A.size().
A.block()
Returns the underlying data-storage block for the vector.

2.4.4. Vector Elements

The following operations can be performed on a vector to read values from or write values to particular elements of the vector.

A(n)
Returns an lvalue reference to the nth value of a vector. Unless the vector is a const_vector, this can be used both to read values from the vector and to write values to it.
A.get(n)
Returns the nth value of a vector. This is generally more efficient than A(n) for retrieving the values of an elements.
A.put(n, value)
Sets the nth value of a vector to value. As with A.get(n), this is generally more efficient than using A(n).

2.4.5. 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))
Return a subview of A. The subview is of size size. The nth element of the subview refers to the start + n*stride element of A.
A.get(Domain<1>(start, stride, size))
Return a const_Vector subview of A.

2.4.6. Subview Vector Variables

The subview type of a vector type allows for the creation of variables that reference subviews of a vector. For example,

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

will create a variable A that references the given subdomain of view. Thus, modifying elements of A will modify the corresponding elements of view and visa versa.

The underlying storage is reference-counted, and it will not be deallocated until all references have been destroyed. Thus, even if view is destroyed, the elements of A will continue to be valid until it is destroyed as well.

It is also possible to declare constant subview variables that cannot be modified directly, thus preventing unexpected alterations to the primary vector. These are declared with const_subview_type, as (for instance)

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

2.4.7. Special Vector Subviews of Complex Vectors.

There are two additional subview functions for vectors of complex numbers:

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

Reference variables for the real and imaginary variables have the types Vector<T>::realview_type and Vector<T>::imagview_type, respectively, or Vector<T>::const_realview_type and Vector<T>::const_imagview_type for subviews that cannot be directly modified.