#include <rw/math/mtharray.h> RWMathArray<T> array;
Class RWMathArray<T> is a templatized arbitrary dimension array class.
#include <rw/math/mtharray.h> main() { RWMathArray<DComplex> A(3,3,3, DComplex(3,0)); RWMathArray<DComplex> B(5,5,5,5,reUninitialized); // Set a plane of data to 5 + 2i A(RWAll,0,RWAll) = DComplex(5,2); }
RWMathArray()
Constructs a 0-dimensional array, useful for declaring vectors of arrays. Like any other array, this array can subsequently be reshaped or resized (see member functions reshape() and resize()). Note that since this is a 0-dimensional (not 0 length) array, and since by definition a 0-dimensional array is a scalar, the array has one element of data.
RWMathArray(unsigned m, unsigned n, unsigned o, RWUninitialized); RWMathArray(unsigned m, unsigned n, unsigned o, unsigned p, RWUninitialized); RWMathArray(const RWIntVec& n, RWUninitialized);
Constructs an uninitialized array with a specified size. The constructor taking an integer vector is useful for constructing arrays with more than four dimensions. 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.
RWMathArray(unsigned m, unsigned n, unsigned o, T val); RWMathArray(unsigned m, unsigned n, unsigned o, unsigned p, T val); RWMathArray(const RWIntVec& n, T val);
Constructs an array with a specified size. Each element in the array is initialized to val. The constructor taking an integer vector is useful for constructing arrays with more than four dimensions.
RWMathArray(const RWIntVec& n, RWTRand<RWRandGenerator>& Storage s); RWMathArray(unsigned m, unsigned n, unsigned o, RWTRand<RWRandGenerator>& r, Storage s); RWMathArray(unsigned m, unsigned n, unsigned o, unsigned p, RWTRand<RWRandGenerator>& r);
Constructs an array with a specified size initialized with random numbers generated by r. The constructor taking an integer vector is useful for constructing arrays with more than four dimensions.
RWMathArray(const T* dat, unsigned m, unsigned n, unsigned o); RWMathArray(const T* dat, unsigned m, unsigned n, unsigned o, unsigned p); RWMathArray(const T* dat, const IntVec& n);
Constructs an array with a specified size using the data in the vector dat as initial data. A copy of dat is made. The vector dat must have at least as many elements as the array. The constructor taking an integer vector is useful for constructing arrays with more than four dimensions.
RWMathArray(const RWMathVec<T>& v, unsigned m, unsigned n, unsigned o); RWMathArray(const RWMathVec<T>& v, unsigned m, unsigned n, unsigned o, unsigned p); RWMathArray(const RWMathVec<T>& v, const IntVec& n);
Constructs an array using the data in the vector v. The array is a new view of the same data as v, so no copy of the data is made. The vector v must have the same number of elements as the array. The constructor taking an integer vector is useful for constructing arrays with more than four dimensions.
RWMathArray(const RWMathArray<T>& m);
Copy constructor. The new array and the old array both view the same data.
RWMathArray(const char *s);
Constructs an array 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.
RWMathArray(const RWMathVec<T>&); RWMathArray(const RWGenMat<T>&);
Constructs a 1-dimensional or 2-dimensional array from a vector or matrix. The resulting array is an alternate view of the same data. This constructor is most often used implicitly by the compiler to pass vectors or matrices to subroutines written to operate on arrays of arbitrary dimension. This allows you to write one subroutine suitable for vectors, matrices, or arrays.
RWMathArray<DComplex>::RWMathArray (const RWMathArray<double>& re, const RWMathArray<double>& im);
Constructs a complex array from the double precision arrays re and im, with the real part of the array equal to re and the imaginary part equal to im. A new copy of the data is made.
RWMathArray<T> apply(RWMathArray<T>::mathFunType) const; RWMathArray<RWMathArray<T>::norm_type> apply2(RWMathArray<T>::mathFunType2) const;
Returns the result of applying the passed function to every element in the array. A function of type RWMathArray<T>::mathFunType takes and returns a T; a function of type RWMathArray<T>::mathFunType2 takes a T and returns an RWMathArray<T>::norm_type. See class rw_numeric_traits for a description of RWMathArray<T>::norm_type.
RWMathArray<T>::iterator begin(); RWMathArray<T>::const_iterator begin() const;
Returns an iterator pointing to the first element of self.
unsigned binaryStoreSize() const;
Returns the number of bytes required to store the array to an RWFile using member function saveOn(RWFile&).
T* data(); const T* data() const;
Returns a pointer to the start of an array's data. Should be used with care, as this accesses the array's data directly.
RWMathArray<T> deepCopy() const; RWMathArray<T> copy() const;
Returns a copy with distinct instance variables. The function copy() is a synonym for deepCopy().
void deepenShallowCopy();
When invoked for an array, guarantees that there is only one reference to that object and that its data are in contiguous memory.
unsigned dimension() const;
Returns the number of dimensions of the array.
RWMathArray<T>::iterator end(); RWMathArray<T>::const_iterator end() const;
Returns an iterator pointing to one element past the last element of self.
int length(int i) const; const RWIntVec& length() const;
Returns the number of entries in a dimension of the array. The version that takes an integer parameter returns the size of the indicated dimension; the version that returns an RWMathVec<int> passes all the dimension lengths at once.
RWMathArray<T> reference(RWMathArray<T>& m);
Makes self a view of m's data. The view currently associated with the array is lost.
void reshape(unsigned m, unsigned n, unsigned o); void reshape(unsigned m, unsigned n, unsigned o, unsigned p); void reshape(const RWIntVec& v);
Changes the size of the array. After reshaping, the contents of the array are undefined; that is, they can be and probably will be garbage.
void resize(unsigned m, unsigned n, unsigned o); void resize(unsigned m, unsigned n, unsigned o, unsigned p); void resize(const RWIntVec& v);
Changes the size of the array, 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, 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 or RWvostream. To use these functions with a user-defined type, the corresponding operator << must be defined:
RWvostream& operator<<(RWvostream& T&); RWFile& operator<<(RWFile&, T&);
RWMathArray<T> slice(const RWIntVec& i, const RWIntVec& n,
const RWGenMat<int>& str);
Returns an array that views a slice of the array. The slice begins at element i and is of size n. The increment between successive elements in the slice's jth dimension is given by the jth column of the matrix str. For 3-dimensional and 4-dimensional arrays, most useful slices can be more simply constructed using subscripting.
T& operator()(const RWIntVec&); T operator()(const RWIntVec&) const; T& operator()(i,j,k); T operator()(i,j,k) const; T& operator()(i,j,k,l); T operator()(i,j,k,l) const; RWMathVec<T> operator()(i,j,k); const RWMathVec<T> operator()(i,j,k) const; RWMathVec<T> operator()(i,j,k,l); const RWMathVec<T> operator()(i,j,k,l) const; RWGenMat<T> operator()(i,j,k); const RWGenMat<T> operator()(i,j,k) const; RWGenMat<T> operator()(i,j,k,l); const RWGenMat<T> operator()(i,j,k,l) const; RWMathArray<T> operator()(i,j,k); const RWMathArray<T> operator()(i,j,k) const; RWMathArray<T> operator()(i,j,k,l); const RWMathArray<T> operator()(i,j,k,l) const;
Subscripting operator for the array, with optional bounds checking. Bounds checking is enabled by defining the preprocessor macro RWBOUNDS_CHECK before including the header file. The indices i,j,k, and l can be any one of the following: int, RWSlice, RWRange, RWToEnd, char*, or RWAll. The return type depends on the number of integers used in the subscripting. All subscripting operators return a new view of the same data as the array being subscripted.
T& operator[](const RWIntVec& i); T operator[](const RWIntVec& I) const;
Subscripting operator for the array, with bounds checking. All subscripting operators return a new view of the same data as the matrix being subscripted. An object of type RWRange or RWToEnd, the global object RWAll, or a character string may be substituted for an RWSlice.
RWMathArray<T>& operator++(); void operator++(int); RWMathArray<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.
RWMathArray<T>& operator=(const RWMathArray<T>& m); RWMathArray<T>& operator+=(const RWMathArray<T>& m); RWMathArray<T>& operator-=(const RWMathArray<T>& m); RWMathArray<T>& operator*=(const RWMathArray<T>& m); RWMathArray<T>& operator/=(const RWMathArray<T>& m); RWMathArray<T>& operator=(const T&); RWMathArray<T>& operator+=(const T&); RWMathArray<T>& operator-=(const T&); RWMathArray<T>& operator*=(const T&); RWMathArray<T>& operator/=(const T&);
Assignment operator with conventional meaning. There are two prototypes for each of the arithmetic assignment operators, one for array assignment and one for scalar assignment. For array assignment, the expression:
u += v;
implies u
RWBoolean operator==(const RWMathArray<T>&); RWBoolean operator!=(const RWMathArray<T>&);
Returns TRUE if self and the argument are equivalent (or not equivalent). To be equivalent, they must have the same number of rows as well as columns, and each element in self must equal the corresponding element in the argument.
operator RWMathArray<promote_type>();
Implicit conversion operator to RWMathArray<promote_type>. The promote_type is rw_numeric_traits<T>::promote_type. See rw_numeric_traits<T> for a description.
RWMathArray<T> operator-(const RWMathArray<T>&); RWMathArray<T> operator+(const RWMathArray<T>&); RWMathArray<T> operator*(const RWMathArray<T>&,
const RWMathArray<T>&); RWMathArray<T> operator/(const RWMathArray<T>&,
const RWMathArray<T>&); RWMathArray<T> operator+(const RWMathArray<T>&,
const RWMathArray<T>&); RWMathArray<T> operator-(const RWMathArray<T>&,
const RWMathArray<T>&); RWMathArray<T> operator*(const RWMathArray<T>&, const T&); RWMathArray<T> operator*(const T&, const RWMathArray<T>&); RWMathArray<T> operator/(const RWMathArray<T>&, const T&); RWMathArray<T> operator/(const T&, const RWMathArray<T>&); RWMathArray<T> operator+(const RWMathArray<T>&, const T&); RWMathArray<T> operator+(const T&, const RWMathArray<T>&); RWMathArray<T> operator-(const RWMathArray<T>&, const T&); RWMathArray<T> operator-(const T&, const RWMathArray<T>&);
Operator with conventional meaning, applied element-by-element. For instance, for matrices 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. For operators involving two arrays, they must conform, that is, have the same dimensions, or an exception with value MATX_MATSIZE occurs.
ostream& operator<<(ostream& s,const RWMathArray<T>& v);
Outputs an array v to ostream s. First, the size of the array is output in the form 3 x 4 x 3, for example, and then the elements of the array are output separated by spaces beginning with a left bracket [ and terminating with a right bracket ]. Newlines are used to try and convey the structure of the array.
istream& operator>>(istream& s, RWMathArray<T>& v);
Reads an array v from istream s. First, the size of the array is read, then array values separated by white space. The sequence of numbers begins with a size specification, such as 3 x 4 x 3, followed by a left bracket [, and the operator reads to a matching right bracket ].
acos asin atan atan2 ceil cos cosh exp floor log log10 maxIndex maxValue mean minIndex minValue pow prod sin sinh sqrt sum tan tanh toGenMat toScalar toVec
See the Global Function Reference for the function prototypes and descriptions of these functions.
abs arg conj frobNorm imag maxNorm norm real toChar toFloat toInt variance
See the Global Function Reference for the function prototypes and descriptions of these functions.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.