Blitz++: TinyVector

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

# 7. TinyVector

The `TinyVector` class provides a small, lightweight vector object whose size is known at compile time. It is included via the header `<blitz/tinyvec.h>`.

Note that `TinyVector` lives in the `blitz` namespace, so you will need to refer to it as `blitz::TinyVector`, or use the directive `using namespace blitz;`.

The Blitz++ `Array` object uses `TinyVector` internally, so if you include `<blitz/array.h>`, the `TinyVector` header is automatically included. However, to use `TinyVector` expressions, you will need to include `<blitz/tinyvec-et.h>`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 7.1 Template parameters and types

The `TinyVector<T,N>` class has two template parameters:

`T`
  is the numeric type of the vector (float, double, int, `complex<float>`, etc.;

`N`
  is the number of elements in the vector.

Inside the `TinyVector` class, these types are declared:

`T_numtype`
  is the numeric type stored in the vector (the template parameter `T`)

`T_vector`
  is the vector type `TinyVector<T,N>`.

`iterator`
  is an STL-style iterator.

`constIterator`
  is an STL-style const iterator.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 7.2 Constructors

    TinyVector();

The elements of the vector are left uninitialized.

    TinyVector(const TinyVector<T,N>& x);

The elements of vector `x` are copied.

    TinyVector(T value);

All elements are initialized to `value`.

    TinyVector(T value1, T value2, ...);

The vector is initialized with the list of values given. These constructors are provided for up to N=11.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 7.3 Member functions

    TinyVector<T,N>::iterator                   begin();
    TinyVector<T,N>::const_iterator             begin() const;

Returns an STL-style iterator for the vector, positioned at the beginning of the data.

    TinyVector<T,N>::iterator                   end();
    TinyVector<T,N>::const_iterator             end() const;

Returns an STL-style iterator for the vector, positioned at the end of the data.

    T_numtype* [restrict]                       data();
    const T_numtype* [restrict]                 data() const;

Returns a pointer to the first element in the vector.

    int                                         length() const;

Returns the length of the vector (the template parameter `N`).

    T_numtype                                   operator()(int i) const;
    T_numtype&                                  operator()(int i);
    T_numtype                                   operator[](int i) const;
    T_numtype&                                  operator[](int i);

Returns the `i`th element of the vector. If the code is compiled with debugging enabled (`-DBZ_DEBUG`), bounds checking is performed.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 7.4 Assignment operators

The assignment operators =, +=, -=, *=, /=, %=, ^=, &=, |=, >>= and <<= are all provided. The right hand side of an assignment may be a scalar of type `T_numtype`, a `TinyVector` of any type but the same size, or a vector expression.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 7.5 Expressions

Expressions involving tiny vectors may contain any combination of the operators

    + - * / % ^ & | >> <<

with operands of type TinyVector, scalar, or vector expressions. The usual math functions (see the Array documentation) are supported on TinyVector.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 7.6 Global functions

    dot(TinyVector, TinyVector);
    dot(vector-expr, TinyVector);
    dot(TinyVector, vector-expr);
    dot(vector-expr, vector-expr);

These functions calculate a dot product between `TinyVector`s (or vector expressions). The result is a scalar; the type of the scalar follows the usual type promotion rules.

    product(TinyVector);

Returns the product of all the elements in the vector.

    sum(TinyVector);

Returns the sum of the elements in the vector.

    TinyVector<T,3> cross(TinyVector<T,3> x, TinyVector<T,3> y);

Returns the cross product of `x` and `y`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 7.7 Arrays of `TinyVector`

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 7.8 Input/output

    ostream& operator<<(ostream&, const TinyVector<T,N>& x);

This function outputs a `TinyVector` onto a stream. Here's an illustration of the format for a length 3 vector:

    [        0.5       0.2       0.9 ]

[ << ] | [ >> ] |  |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Julian Cummings on November, 4 2004 using texi2html