#include <rw/math/mathvec.h> RWMathVec<T> vector;
Class RWMathVec<T> is a templatized vector class.
#include <rw/math/mathvec.h> main() { RWMathVec<int> v(5, rwUninitialized); v = 3; // Set all elements in v to 3 RWMathVec<int> w = v + 1; RWMathVec<int> y = v + w; }
RWMathVec()
Constructs a 0-length vector, useful for declaring arrays of vectors. Like any other vector, this vector can subsequently be reshaped or resized (see member functions reshape() and resize()).
RWMathVec(unsigned n, RWUninitialized);
Constructs a vector with n elements. The RWUninitialized type is an enumeration type with only one value, rwUninitialized. The rwUninitialized argument is used to distinguish the last dimension size from an initial value.
RWMathVec(unsigned n, T initval);
Constructs a vector with n elements, initialized to initval.
RWMathVec(unsigned n, T initval, T incr);
Constructs a vector with n elements. The first has value initval; each succeeding element is incremented by incr.
RWMathVec(unsigned n, RWTRand<RWRandGenerator>& r);
Constructs a vector with n elements initialized with random numbers generated by r.
RWMathVec(const T* dat,unsigned n);
Constructs a vector with n elements, using the data in the vector dat as initial data. A copy of dat is made. The vector dat must have at least n elements.
RWMathVec(const RWMathVec<T>&);
Copy constructor. The new vector and the old vector both view the same data.
RWMathVec(const RWMathVecPick<T>& p);
Constructs a new vector from an RWMathVecPick<T>. A copy of p's data is made.
RWMathVec(const char *s);
Constructs a matrix from the null terminated character string s. The format of the character string is the same as that expected by the global operator operator>> described in this entry.
RWMathVec<DComplex>::RWMathVec(const RWMathVec<double>& re, const RWMathVec<double>& im);
A complex vec is constructed from the double precision arrays re and im, with the real part of the vec equal to re and the imaginary part equal to im. A new copy of the data is made.
RWMathVec<T> apply(RWMathVec<T>::mathFunType) const; RWMathVec<RWMathVec<T>::norm_type> apply2(RWMathVec<T>::mathFunType2) const
Returns the result of applying the passed function to every element in the vector. A function of type RWMathVec<T>::mathFunType takes and returns a T; a function of type RWMathVec<T>::mathFunType2 takes a T and returns an RWMathVec<T>::norm_type. See class rw_numeric_traits for a description of RWMathVec<T>::norm_type.
RWMathVec<T>::iterator begin(); RWMathVec<T>::const_iterator begin() const;
Returns an iterator that points to the first element in the vector.
unsigned binaryStoreSize() const;
Returns the number of bytes required to store the vector to an RWFile using member function saveOn(RWFile&).
T* data(); const T* data() const;
Returns a pointer to the start of a vector's data. Should be used with care, as this accesses the vector's data directly. You are responsible for recognizing the length and the stride of the vector.
RWMathVec<T> deepCopy() const; RWMathVec<T> copy() const;
Returns a copy with distinct instance variables. The function copy() is a synonym for deepCopy().
void deepenShallowCopy();
When invoked for a vector, guarantees that there is only one reference to that object and that its data are in contiguous storage.
RWMathVec<T>::iterator end(); RWMathVec<T>::const_iterator end() const;
Returns an iterator that points to one element past the last element in the vector.
unsigned length() const;
Returns the number of elements in the vector.
RWMathVecPick<T> pick(const RWIntVec& v);
Returns a vector pick. The results can be used as an lvalue. You can think of the picked elements as representing a vector in the order specified by the vector of indices v. Before using this function, you must include the header file rw/math/mthvecpk.h.
RWMathVec<T>& reference(RWMathVec& v);
Makes self a view of v's data. The view currently associated with the vector is lost.
void reshape(unsigned n);
Changes the length of the vector to n elements. After reshaping, the contents of the vector are undefined; that is, they can be and probably will be garbage.
void resize(unsigned n);
Changes the size of the vector to n elements, adding 0s or truncating as necessary.
void restoreFrom(RWvistream&); void restoreFrom(RWFile&);
Restores self from a virtual stream or an RWFile. To use these functions with a user-defined type T, the corresponding operator >> must be defined:
RWvistream& operator>>(RWvistream& T&); RWFile& operator>>(RWFile&, T&);
void saveOn(RWvostream&) const; void saveOn(RWFile&) const;
Stores self to a virtual stream, or in a binary format to an RWFile. To use these functions with a user-defined type T, the corresponding
operator << must be defined:
RWvostream& operator<<(RWvostream& T&); RWFile& operator<<(RWFile&, T&);
RWMathVec<T> slice(int start, unsigned n, int stride=1) const;
Returns a vector which views a slice of the data. The slice begins at element start and extends for n elements. The increment between successive elements in the slice is stride.
int stride() const
Returns the distance between successive elements of the vector. The stride can be computed using &v[i+1]-&v[i].
T& operator[](int i); T operator[](int i) const; RWMathVec<T> operator[](RWSlice& i); const RWMathVec<T> operator[](RWSlice& i) const;
Subscripting operator for the vector, with bounds checking. All subscripting operators return a new view of the same data as the vector being subscripted. An object of type RWRange or RWToEnd, the global object RWAll, or a character string may be substituted for an RWSlice.
T& operator()(int i); T operator()(int i) const; RWMathVec<T> operator()(RWSlice& i); const RWMathVec<T> operator()(RWSlice& i) const;
Subscripting operators for the vector, with optional bounds checking. Bounds checking is enabled by defining the preprocessor macro RWBOUNDS_CHECK before including the header file. All subscripting operators return a new view of the same data as the vector being subscripted. An object of type RWRange or RWToEnd, the global object RWAll, or a character string may be substituted for an RWSlice.
RWMathVec<T>& operator++(); void operator++(int); RWMathVec<T>& operator--(); void operator--(int);
Increments or decrements each element of self. The functions taking an integer parameter are invoked if the operator is used as a postfix operator.
RWMathVec<T>& operator=(const RWMathVec<T>& m); RWMathVec<T>& operator+=(const RWMathVec<T>& m); RWMathVec<T>& operator-=(const RWMathVec<T>& m); RWMathVec<T>& operator*=(const RWMathVec<T>& m); RWMathVec<T>& operator/=(const RWMathVec<T>& m); RWMathVec<T>& operator=(const T&); RWMathVec<T>& operator+=(const T&); RWMathVec<T>& operator-=(const T&); RWMathVec<T>& operator*=(const T&); RWMathVec<T>& operator/=(const T&);
Assignment operator with conventional meaning. There are two prototypes for each of the arithmetic assignment operators, one for vector assignment and one for scalar assignment. For vector assignment, the expression:
u += v;
implies ui = ui + vi, while for scalar assignment, the same expression implies ui= ui + v. For operators that involve two vectors, they must have the same dimensions.
RWBoolean operator==(const RWMathVec<T>&); RWBoolean operator!=(const RWMathVec<T>&);
Returns TRUE if self and the argument are equivalent (or not equivalent). To be equivalent, they must have the same number of entries and each element in self must equal the corresponding element in the argument.
operator RWMathVec<promote_type>();
Implicit conversion operator to RWMathVec<promote_type>. The promote_type is rw_numeric_traits<T>::promote_type. See rw_numeric_traits<T> for more information.
RWMathVec<T> operator-(const RWMathVec<T>&); RWMathVec<T> operator+(const RWMathVec<T>&); RWMathVec<T> operator*(const RWMathVec<T>&,
const RWMathVec<T>&); RWMathVec<T> operator/(const RWMathVec<T>&,
const RWMathVec<T>&); RWMathVec<T> operator+(const RWMathVec<T>&,
const RWMathVec<T>&); RWMathVec<T> operator-(const RWMathVec<T>&,
const RWMathVec<T>&); RWMathVec<T> operator*(const RWMathVec<T>&, const T&); RWMathVec<T> operator*(const T&, const RWMathVec<T>&); RWMathVec<T> operator/(const RWMathVec<T>&, const T&); RWMathVec<T> operator/(const T&, const RWMathVec<T>&); RWMathVec<T> operator+(const RWMathVec<T>&, const T&); RWMathVec<T> operator+(const T&, const RWMathVec<T>&); RWMathVec<T> operator-(const RWMathVec<T>&, const T&); RWMathVec<T> operator-(const T&, const RWMathVec<T>&);
Operators with conventional meanings, applied element-by-element. For example, for vectors u, v, and w, the expression w=u+v implies wi = ui + vi. Therefore, operator * implies an element-by-element multiply, not the inner product. If you want the inner product, use global function dot() or conjDot().
ostream& operator<<(ostream& s,const RWMathVec<T>& v);
Outputs a vector v to ostream s beginning with a left bracket [ and terminating with a right bracket ]. The output numbers are separated by spaces. If T is a user-defined type, the following operator must be defined for RWvostream and/or RWFile:
operator<<(ostream&s,constT&t);
istream& operator>>(istream& s, RWMathVec<T>& v);
Reads vector v from stream s. It reads a sequence of numbers separated by white space. If the sequence of numbers begins with a left bracket [, the operator reads to a matching right bracket ]. If no left bracket is present, it reads to end of file. The vector v is initialized to the correct length. If T is a user-defined type, the following operator must be defined for RWvistream and/or RWFile:
operator>>(ostream&s,constT&t);
acos asin atan atan2 ceil cos cosh cumsum delta dot exp expandEven expandOdd floor log log10 maxIndex maxValue mean minIndex minValue pow prod reverse sin sinh sqrt sum tan tanh
See the Global Function Reference for the function prototypes and descriptions of these functions.
abs arg conj conjDot expandConjugateEven expandConjugateOdd frobNorm imag l1Norm l2Norm linfNorm norm maxNorm real rootsOfOne variance spectralVariance toChar toFloat toInt
See the Global Function Reference for the function prototypes and descriptions of these functions.
RWConvertMathVec<From,To>
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.