Blitz++ Class Reference: Vector<T>

Sections

Related topics and classes

Inheritance diagram

MemoryBlockReference<T>
|
Vector<T>

Synopsis

#include <blitz/vector.h>
using namespace blitz;
Vector<double> x(100);

Template parameter

The template parameter of Vector<T> is the element type of the vector. This should an integral, floating point, or complex type. These choices of T should work:

Other types may work provided they have the necessary numeric semantics.

Public types

Vector<T> declares several publicly accessible types. They may be accessed using the scope (::) operator: e.g.

Vector<double> x(50);                       // Create a vector of length 50
Vector<double>::T_iterator z = x.begin();   // Get an iterator for x
Type Description
T_numtype The numeric type of the vector elements (e.g. double)
T_vector Complete type of the vector itself (e.g. Vector<double>)
T_iterator STL-like iterator to be used on this vector (see begin(), end()) ** Not yet supported
T_constIterator STL-like const iterator to be used on this vector (see begin(), end()) ** Not yet supported

Constructors

Member functions

Member operators

T_numtype        operator()(unsigned i) const
T_numtype&       operator()(unsigned i)
T_numtype        operator[](unsigned i) const
T_numtype&       operator[](unsigned i)
T_vector         operator()(Range r)
T_vector         operator[](Range r)
T_pick           operator[](Vector<int>)        ** Currently broken

Iostream operators

ostream& operator>>(ostream& os, const vector expression&);
Formats a vector or vector expression for output. In future releases, several output formats will be supported.

Arithmetic operators

Arithmetic operators are implemented using expression templates. These assignment operators are supported:
operator=(vector expression)
operator+=(vector expression)
operator-=(vector expression)
operator*=(vector expression)
operator/=(vector expression)
operator%=(vector expression)
operator^=(vector expression)
operator&=(vector expression)
operator|=(vector expression)
operator>>=(vector expression)
operator=(vector expression)

A vector expression can be any combination of these operators and operands, as well as use of the math functions listed later.

Vector expression operators

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

Vector expression operands

Arithmetic type promotion for vectors is identical to type promotion for built-in types. For example, adding a double constant to a Vector<int> will result in a Vector<double>; multiplying a Vector<long double> by a Vector<float> will result in a Vector<long double>. Generally, the result is promoted to which ever type preserves the greatest precision.

Note that division and multiplication of integers may result in truncation and/or wraparound, since the result remains an integer type. The solution is to cast the elements of one of the vectors as floating-point types; see cast<T2> below. ** the cast() function is not yet implemented

Vector<int> x(5), y(5);
Vector<double> z(5);

// ...

z = x / y;      // Calculated using integer math, then cast as double
                // Results in truncation

z = x / cast<double>(y);   // Calculated using floating point 

Single-operand math functions

Notes
FunctionDescriptionReal vectorsComplex vectorsAvailability
absAbsolute value Y Y all
acosInverse cosine. Elements must be in the range [-1,+1]. The resulting elements lie in [-Pi,+Pi]. Y Y all
acoshInverse hyperbolic cosine Y all
arg Argument (phase/angle) of a complex vector. Result is a scalar vector whose elements lie in [-Pi, +Pi]. Y allb
asinInverse sine. Elements must be in the range [-1,+1]. The resulting elements lie in [-Pi,+Pi]. Y Y all
asinhInverse hyperbolic sine Y all
atanInverse tangent. Resulting elements lie in [-Pi,+Pi]. Y Y all
atanhInverse hyperbolic tangent Y all
cast<T2>Cast vector elements to type T2
** NOT YET AVAILABLE
YYsomee
cbrtCubic root Y somed
ceilSmallest floating integer not less than element Y all
classFloating-point classification. Result is an integer vector with elements taking values FP_PLUS_NORM, FP_MINUS_NORM, FP_PLUS_ZERO, FP_MINUS_ZERO, FP_PLUS_INF, FP_MINUS_INF, FP_PLUS_DENORM, FP_MINUS_DENORM, FP_SNAN, FP_QNAN as defined in <float.h> Y somed
conj Complex conjugate Y allb
cosCosine. Resulting elements lie in [-1,+1]. Y Y all
coshHyperbolic cosine Y Y all
expExponential. Y Y all
expm1Exponential minus one: exp(x)-1 Y somec
erfError function Y somec
erfcComplementary error function (1-erf(x)). Y somec
fabsSame as abs Y all
finiteNonzero if finite. Result is integer. Y somed
floorLargest floating int not greater than x Y all
ilogbInteger unbiased exponent Y somed
imag Imaginary portion of a complex vector. Result is a scalar vector which may be used as an lvalue. Y allb
isnanNonzero if x is NaNS (Signalling Not a Number) or NaNQ (Quiet Not A Number). Result is integer. Y somed
itruncTruncate and convert to integer. Result is integer. Y somed
inv Inverse of a complex number Y allb
j0Bessel function first kind, order 0 Y somec
j1Bessel function first kind, order 1
See also y0(x), y1(x), jn(x,y) and yn(x,y).
Y somec
lgammaLog absolute gamma Y somec
logNatural logarithm Y Y all
logbUnbiased exponent (IEEE) Y somec
log1pNatural logarithm of (1+x) Y somec
log10Logarithm base 10 Y Y all
nearestNearest floating point integer to x. Y somed
norm Norm (magnitude) of a complex vector. Result is a scalar vector. Y allb
real Real portion of a complex vector. Result is a scalar vector which may be used as an lvalue. Y allb
rintRound to floating point integer, using the current floating-point rounding mode. Rounding mode is read and set by the functions fp_read_rnd() and fp_swap_rnd(). (See system man pages) Y somec
rsqrtReciprocal square root (i.e. 1.0/sqrt(x)) Y somed
sinSine. Resulting elements lie in [-1,+1]. Y Y all
sinhHyperbolic sine Y Y all
sqrSquare: equivalent to x*x Y Y alle
sqrtSquare root Y Y all
tanTangent Y Y all
tanhHyperbolic tangent Y Y all
truncNearest floating-point integer in the direction of zero Y somec
uitruncTruncate and convert to unsigned. Result is unsigned integer. Y somed
y0Bessel function 2nd kind, order 0 Y somec
y1Bessel function 2nd kind, order 1
See also yn(x,y) below
Y somec
aANSI C math function
bANSI C++ math function
cIEEE 754 standard required function
dIEEE 754 recommended function
eNonstandard function specific to Blitz++

Global math functions with two operands

** These functions are not yet implemented **

All the two operand math functions are provided in three forms:
atan2(double,vector) atan2(vector,double) atan2(vector,vector) copysign(vector,double) drem(d,d) fmod(d,d) frexp(d, Vector<int>& e) NOT INCLUDED hypot(d,d) jn(int, d) NOT INCLUDED ldexp(d,i) NOT INCLUDED modf(d, Vector<int>& e) NOT INCLUDED max(d, d) min(d, d) nextafter(d, d) polar(d,d) NOT INCLUDED pow(d,d) remainder(d,d) scalb(d,d) unordered(d,d) yn(int,d) NOT INCLUDED

Other global functions

(These functions are available)
accumulate

dot 
delta






max
maxIndex
maxValue
mean
min
minIndex
minValue
norm




reverse


sum

The where function

The where(X,Y,Z) function provides the same functionality as the operator X ? Y : Z. If X is logical true, then Y is returned; otherwise, Z is returned.

The where function is implemented using expression templates. The arguments X, Y, and Z can each be vectors, vector expressions, Range, or Vector picks.

Example

Please see the files in the
Blitz++/examples directory.