dlr::numeric::Array1D< Type > Class Template Reference

The Array1D class template represents a 1D array of arbitrary type. More...

#include <array1D.h>

Inheritance diagram for dlr::numeric::Array1D< Type >:

Inheritance graph
[legend]
Collaboration diagram for dlr::numeric::Array1D< Type >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef Type value_type
 Typedef for value_type describes the contents of the array.
typedef Type * iterator
 Typedef for iterator type helps with standard library interface.
typedef const Type * const_iterator
 Typedef for const_iterator type helps with standard library interface.

Public Member Functions

 Array1D ()
 Default constructor initializes to zero size.
 Array1D (size_t size)
 Constructs a "size" element array.
 Array1D (const std::string &inputString)
 Constructs an Array1D by parsing an input string.
 Array1D (const Array1D< Type > &source)
 The copy constructor does a shallow copy.
 Array1D (size_t size, Type *const dataPtr)
 Construct an array around external data.
 Array1D (size_t size, Type *const dataPtr, size_t *const refCountPtr)
 Construct an array around external data which was allocated by an Array?D instance.
 ~Array1D ()
 Destroys the Array1D instance and deletes the internal data store if no remaining arrays point to it.
iterator begin ()
 Return begin() iterator for Standard Library algorithms.
const_iterator begin () const
 Return begin() const_iterator for Standard Library algorithms.
void checkDimension (size_t size) const
 Optionally throw an exception if the shape of *this is different than specified.
void clear ()
 Reset the array to zero size, abandoning all contents.
Array1D< Type > copy () const
 Allocate a new array and deep copy the contents of *this.
template<class Type2>
void copy (const Array1D< Type2 > &source)
 Deep copies the contents of source.
template<class Type2>
void copy (const Type2 *dataPtr)
 Copies elements from dataPtr.
Type * data ()
 Returns a pointer to the internal data store.
const Type * data () const
 This version of data(void) is appropriate for const Array1D, and returns a pointer-to-const.
Type * data (size_t index)
 Just like data(void), which is documented above, but returns a pointer to the (index)th element instead of the first element.
const Type * data (size_t index) const
 This version of data(size_t) is appropriate for const Array1D, and returns a pointer-to-const.
bool empty () const
 This member function returns true if the array instance contains no elements.
iterator end ()
 Return end() iterator for Standard Library algorithms.
const_iterator end () const
 Return end() const_iterator for Standard Library algorithms.
bool isAllocated () const
 Indicates whether the internal data array is being managed (and reference counted) by *this.
size_t length () const
 Returns the number of elements in the array.
std::istream & readFromStream (std::istream &inputStream)
 This member function sets the value of the array from an input stream.
size_t * refCountPtr () const
 Temporary function to ease porting of code from early versions of dlr_libs.
void reinit (size_t size)
 Changes the shape of the array and reallocates storage.
size_t size () const
 Returns the number of elements in the array.
Array1D< Type > & operator= (const Array1D< Type > &source)
 Assignment operator shallow copies the contents of source.
Array1D< Type > & operator= (Type value)
 Assign value to every element in the array.
Type & operator() (size_t index)
 Returns the (index)th element of the array by reference.
Type operator() (size_t index) const
 Returns the (index)th element of the array by value.
Type & operator[] (size_t index)
 Returns the (index)th element of the array by reference.
Type operator[] (size_t index) const
 Returns the (index)th element of the array by value.
template<class Type2>
Array1D< Type > & operator+= (const Array1D< Type2 > &arg)
 Increments each element of *this by the value of the corresponding element of arg.
Array1D< Type > & operator+= (const Type arg)
 Increments each element of *this by a constant.
template<class Type2>
Array1D< Type > & operator-= (const Array1D< Type2 > &arg)
 Decrements each element of *this by the value of the corresponding element of arg.
Array1D< Type > & operator-= (const Type arg)
 Decrements each element of *this by a constant.
template<class Type2>
Array1D< Type > & operator *= (const Array1D< Type2 > &arg)
 Multiplies each element of *this by the value of the corresponding element of arg.
Array1D< Type > & operator *= (const Type arg)
 Multiplies each element of *this by a constant.
template<class Type2>
Array1D< Type > & operator/= (const Array1D< Type2 > &arg)
 Divides each element of *this by the value of the corresponding element of arg.
Array1D< Type > & operator/= (const Type arg)
 Divides each element of *this by a constant.

Detailed Description

template<class Type>
class dlr::numeric::Array1D< Type >

The Array1D class template represents a 1D array of arbitrary type.

This class has internal reference counting.

IMPORTANT: This class does _shallow_ copies by default. If you type:

array1 = array2;

then array1 and array2 point to the same data. To do a deep copy, type

array1.copy(array2);

or

array1 = array2.copy();

The advantage of the first form is that it doesn't involve allocating memory. The advantage of the second form is that there's no error if array1 and array2 have different shapes.

Definition at line 55 of file array1D.h.


Member Typedef Documentation

template<class Type>
typedef Type dlr::numeric::Array1D< Type >::value_type

Typedef for value_type describes the contents of the array.

Definition at line 62 of file array1D.h.

template<class Type>
typedef Type* dlr::numeric::Array1D< Type >::iterator

Typedef for iterator type helps with standard library interface.

Definition at line 67 of file array1D.h.

template<class Type>
typedef const Type* dlr::numeric::Array1D< Type >::const_iterator

Typedef for const_iterator type helps with standard library interface.

Definition at line 73 of file array1D.h.


Constructor & Destructor Documentation

template<class Type>
dlr::numeric::Array1D< Type >::Array1D (  )  [inline]

Default constructor initializes to zero size.

Definition at line 965 of file array1D.h.

template<class Type>
dlr::numeric::Array1D< Type >::Array1D ( size_t  size  )  [inline, explicit]

Constructs a "size" element array.

Parameters:
size Number of elements in the array after successful construction.

Definition at line 977 of file array1D.h.

template<class Type>
dlr::numeric::Array1D< Type >::Array1D ( const std::string &  inputString  )  [inline, explicit]

Constructs an Array1D by parsing an input string.

For example, the code line

Array1D<double> testArray("[1.0, 2.0, 3.0]");

would construct a 3 element array.

Parameters:
inputString A formatted string which could be reasonably expected to parse into the desired array values.

Definition at line 990 of file array1D.h.

References DLR_THROW3.

template<class Type>
dlr::numeric::Array1D< Type >::Array1D ( const Array1D< Type > &  source  )  [inline]

The copy constructor does a shallow copy.

The newly created array points to the same data as copied array.

Parameters:
source The Array1D<> instance to be copied.

Definition at line 1019 of file array1D.h.

template<class Type>
dlr::numeric::Array1D< Type >::Array1D ( size_t  size,
Type *const   dataPtr 
) [inline]

Construct an array around external data.

Arrays constructed in this way will not implement reference counting, and will not delete dataPtr when done.

Parameters:
size Number of elements in the array after construction.
dataPtr A C-style array of Type into which the newly constructed Array1D should index.

Definition at line 1033 of file array1D.h.

template<class Type>
dlr::numeric::Array1D< Type >::Array1D ( size_t  size,
Type *const   dataPtr,
size_t *const  refCountPtr 
) [inline]

Construct an array around external data which was allocated by an Array?D instance.

Arrays constructed in this way _do_ implement reference counting, and will delete dataPtr when done. This constructor is provided primarily so that higher dimensionality array classes can return Array1D instances which reference their data without being friend classes. Caveat emptor.

Parameters:
size Number of elements in the array after construction.
dataPtr A C-style array of Type into which the newly constructed Array1D should index.
refCountPtr Pointer to size_t indicating the number of Array classes currently using dataPtr.

Definition at line 1045 of file array1D.h.

template<class Type>
dlr::numeric::Array1D< Type >::~Array1D (  )  [inline]

Destroys the Array1D instance and deletes the internal data store if no remaining arrays point to it.

Definition at line 1056 of file array1D.h.


Member Function Documentation

template<class Type>
iterator dlr::numeric::Array1D< Type >::begin (  )  [inline]

Return begin() iterator for Standard Library algorithms.

Returns:
Iterator pointing to the first element of the array.

Definition at line 156 of file array1D.h.

Referenced by dlr::numeric::abs(), dlr::numeric::allFalse(), dlr::numeric::allTrue(), dlr::numeric::argmax(), dlr::numeric::argmin(), dlr::numeric::columnIndices(), dlr::numeric::compress(), dlr::numeric::convolve(), dlr::numeric::convolve1D(), dlr::numeric::count(), dlr::numeric::dot(), dlr::numeric::BSpline< Type >::getSpanNumber(), dlr::numeric::magnitudeSquared(), dlr::numeric::maximum(), dlr::numeric::minimum(), dlr::numeric::operator *(), dlr::numeric::operator+(), dlr::numeric::operator-(), dlr::numeric::operator/(), dlr::numeric::operator==(), dlr::numeric::operator>(), dlr::numeric::operator>=(), dlr::numeric::outerProduct(), dlr::numeric::Array1D< Type >::readFromStream(), dlr::numeric::BSpline< Type >::setKnotMultiplicities(), dlr::numeric::BSpline< Type >::setNodePositions(), and dlr::numeric::sum().

template<class Type>
const_iterator dlr::numeric::Array1D< Type >::begin (  )  const [inline]

Return begin() const_iterator for Standard Library algorithms.

Returns:
Const iterator pointing to the first element of the array.

Definition at line 165 of file array1D.h.

template<class Type>
void dlr::numeric::Array1D< Type >::checkDimension ( size_t  size  )  const [inline]

Optionally throw an exception if the shape of *this is different than specified.

Parameters:
size The required array size.

Definition at line 1064 of file array1D.h.

References DLR_THROW, and dlr::numeric::Array1D< Type >::size().

Referenced by dlr::numeric::operator==().

template<class Type>
void dlr::numeric::Array1D< Type >::clear (  )  [inline]

Reset the array to zero size, abandoning all contents.

This is equivalent to this->reinit(0);

Definition at line 183 of file array1D.h.

Referenced by dlr::numeric::Array2D< Type >::readFromStream().

template<class Type>
Array1D< Type > dlr::numeric::Array1D< Type >::copy (  )  const [inline]

Allocate a new array and deep copy the contents of *this.

Returns:
A new array which is a (deep) copy of *this.

Definition at line 1080 of file array1D.h.

References dlr::numeric::Array1D< Type >::copy().

Referenced by dlr::numeric::Array1D< Type >::copy(), dlr::numeric::BSpline< Type >::getCoefficientMatrices(), and dlr::numeric::BSpline< Type >::operator=().

template<class Type>
template<class Type2>
void dlr::numeric::Array1D< Type >::copy ( const Array1D< Type2 > &  source  )  [inline]

Deep copies the contents of source.

It is an error if source does not have the same size as *this.

Parameters:
source The array to be copied.
Exceptions:
ValueException on incompatible array sizes
See also:
void Array1D<Type>::copy(const Type2* dataPtr)

Definition at line 1090 of file array1D.h.

References dlr::numeric::Array1D< Type >::copy(), dlr::numeric::Array1D< Type >::data(), DLR_THROW3, and dlr::numeric::Array1D< Type >::size().

template<class Type>
template<class Type2>
void dlr::numeric::Array1D< Type >::copy ( const Type2 *  dataPtr  )  [inline]

Copies elements from dataPtr.

There must be valid data at all addresses from dataPtr to (dataPtr + this->size());

Parameters:
dataPtr Pointer to the data to be copied.

Definition at line 1109 of file array1D.h.

template<class Type>
Type* dlr::numeric::Array1D< Type >::data ( void   )  [inline]

Returns a pointer to the internal data store.

This is ugly but often necessary for interfacing with external libraries. Data is stored contiguously.

Returns:
Pointer to the internal data store.

Definition at line 223 of file array1D.h.

Referenced by dlr::numeric::Array1D< Type >::copy(), dlr::numeric::Array1D< Type >::operator *=(), dlr::numeric::Array1D< Type >::operator+=(), dlr::numeric::Array1D< Type >::operator-=(), and dlr::numeric::Array1D< Type >::operator/=().

template<class Type>
const Type* dlr::numeric::Array1D< Type >::data ( void   )  const [inline]

This version of data(void) is appropriate for const Array1D, and returns a pointer-to-const.

Returns:
Const pointer to the internal data store.

Definition at line 232 of file array1D.h.

template<class Type>
Type* dlr::numeric::Array1D< Type >::data ( size_t  index  )  [inline]

Just like data(void), which is documented above, but returns a pointer to the (index)th element instead of the first element.

Note that "data(index)" is synonymous with "data() + index" .

Parameters:
index Indicates to which element of the array the return value should point.
Returns:
Pointer to the (index)th element of the array.

Definition at line 245 of file array1D.h.

template<class Type>
const Type* dlr::numeric::Array1D< Type >::data ( size_t  index  )  const [inline]

This version of data(size_t) is appropriate for const Array1D, and returns a pointer-to-const.

Parameters:
index Indicates to which element of the array the return value should point.
Returns:
Const pointer to the (index)th element of the array.

Definition at line 260 of file array1D.h.

template<class Type>
bool dlr::numeric::Array1D< Type >::empty (  )  const [inline]

This member function returns true if the array instance contains no elements.

It has complexity O(1).

Returns:
The return value indicates whether or not the array is empty.

Definition at line 274 of file array1D.h.

template<class Type>
iterator dlr::numeric::Array1D< Type >::end (  )  [inline]

Return end() iterator for Standard Library algorithms.

Returns:
Iterator pointing just past the last element of the array.

Definition at line 284 of file array1D.h.

Referenced by dlr::numeric::abs(), dlr::numeric::allFalse(), dlr::numeric::allTrue(), dlr::numeric::argmax(), dlr::numeric::argmin(), dlr::numeric::columnIndices(), dlr::numeric::compress(), dlr::numeric::convolve(), dlr::numeric::convolve1D(), dlr::numeric::count(), dlr::numeric::dot(), dlr::numeric::BSpline< Type >::getSpanNumber(), dlr::numeric::magnitudeSquared(), dlr::numeric::maximum(), dlr::numeric::minimum(), dlr::numeric::operator *(), dlr::numeric::operator+(), dlr::numeric::operator-(), dlr::numeric::operator/(), dlr::numeric::operator==(), dlr::numeric::operator>(), dlr::numeric::operator>=(), dlr::numeric::outerProduct(), and dlr::numeric::sum().

template<class Type>
const_iterator dlr::numeric::Array1D< Type >::end (  )  const [inline]

Return end() const_iterator for Standard Library algorithms.

Returns:
Const iterator pointing just past the last element of the array.

Definition at line 293 of file array1D.h.

template<class Type>
bool dlr::numeric::Array1D< Type >::isAllocated (  )  const [inline]

Indicates whether the internal data array is being managed (and reference counted) by *this.

This member function is only needed in very unusual circumstances.

Returns:
The return value is a bool indicating whether the internal data requires memory management.

Definition at line 304 of file array1D.h.

template<class Type>
size_t dlr::numeric::Array1D< Type >::length (  )  const [inline]

Returns the number of elements in the array.

This is a synonym for size().

Returns:
The number of elements in the array.

Definition at line 313 of file array1D.h.

Referenced by dlr::numeric::equivalentMatrix().

template<class Type>
std::istream & dlr::numeric::Array1D< Type >::readFromStream ( std::istream &  inputStream  )  [inline]

This member function sets the value of the array from an input stream.

The array is modified only if the read was successful, otherwise the array is not modified, and failbit is set in the stream state. Because of this nice behavior, readFromStream is quite slow.

Parameters:
inputStream This is the stream from which to read the array.
Returns:
The return value is a reference to inputStream.

Definition at line 1129 of file array1D.h.

References dlr::numeric::Array1D< Type >::begin(), and dlr::numeric::Array1D< Type >::reinit().

Referenced by dlr::numeric::operator>>().

template<class Type>
size_t* dlr::numeric::Array1D< Type >::refCountPtr (  )  const [inline]

Temporary function to ease porting of code from early versions of dlr_libs.

The use of this function is discouraged.

Returns:
The return value is a pointer to the internal reference count.

Definition at line 338 of file array1D.h.

template<class Type>
void dlr::numeric::Array1D< Type >::reinit ( size_t  size  )  [inline]

Changes the shape of the array and reallocates storage.

The current array contents are lost.

Parameters:
size Number of elements in the array after reallocation.

Definition at line 1207 of file array1D.h.

Referenced by dlr::numeric::axisMaximum(), dlr::numeric::axisMinimum(), dlr::numeric::axisSum(), dlr::numeric::Array1D< size_t >::clear(), dlr::numeric::getMeanAndCovariance(), dlr::numeric::Array1D< Type >::readFromStream(), dlr::numeric::BSpline< Type >::setKnotMultiplicities(), and dlr::numeric::BSpline< Type >::setNodePositions().

template<class Type>
size_t dlr::numeric::Array1D< Type >::size (  )  const [inline]

Returns the number of elements in the array.

This is a synonym for length().

Returns:
The number of elements in the array.

Definition at line 356 of file array1D.h.

Referenced by dlr::numeric::abs(), dlr::numeric::argsort(), dlr::numeric::Array1D< Type >::checkDimension(), dlr::numeric::compress(), dlr::numeric::BSpline< Type >::computeBasisFunction(), dlr::numeric::convolve(), dlr::numeric::convolve1D(), dlr::numeric::Array1D< Type >::copy(), dlr::numeric::correlate1D(), dlr::numeric::dot(), dlr::numeric::Array1D< size_t >::empty(), dlr::numeric::equivalentMatrix(), dlr::numeric::BSpline< Type >::getKnotPosition(), dlr::numeric::BSpline< Type >::getMaximumSValue(), dlr::numeric::BSpline< Type >::getMinimumSValue(), dlr::numeric::Array1D< size_t >::length(), dlr::numeric::ln(), dlr::numeric::matrixMultiply(), dlr::numeric::maximum(), dlr::numeric::mean(), dlr::numeric::minimum(), dlr::numeric::normalizedCorrelation(), dlr::numeric::operator *(), dlr::numeric::Array1D< Type >::operator *=(), dlr::numeric::BSpline< Type >::operator()(), dlr::numeric::operator+(), dlr::numeric::Array1D< Type >::operator+=(), dlr::numeric::operator-(), dlr::numeric::Array1D< Type >::operator-=(), dlr::numeric::operator/(), dlr::numeric::Array1D< Type >::operator/=(), dlr::numeric::operator==(), dlr::numeric::operator>(), dlr::numeric::operator>=(), dlr::numeric::outerProduct(), dlr::numeric::rms(), dlr::numeric::BSpline< Type >::setControlPoints(), dlr::numeric::BSpline< Type >::setKnotMultiplicities(), dlr::numeric::BSpline< Type >::setNodePositions(), dlr::numeric::shapeMatch(), dlr::numeric::skewSymmetric(), dlr::numeric::SubArray1D< Type >::SubArray1D(), and dlr::numeric::variance().

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator= ( const Array1D< Type > &  source  )  [inline]

Assignment operator shallow copies the contents of source.

After the copy, both arrays reference the same data.

Parameters:
source The Array1D instance to be copied.
Returns:
Reference to *this.

Definition at line 1217 of file array1D.h.

References dlr::numeric::Array1D< Type >::m_dataPtr, dlr::numeric::Array1D< Type >::m_isAllocated, dlr::numeric::Array1D< Type >::m_refCountPtr, and dlr::numeric::Array1D< Type >::m_size.

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator= ( Type  value  )  [inline]

Assign value to every element in the array.

Parameters:
value The value to be copied.
Returns:
Reference to *this.

Definition at line 1117 of file array1D.h.

template<class Type>
Type& dlr::numeric::Array1D< Type >::operator() ( size_t  index  )  [inline]

Returns the (index)th element of the array by reference.

Parameters:
index Indicates the selected element.
Returns:
Reference to the (index)th element of the array.

Definition at line 387 of file array1D.h.

Referenced by dlr::numeric::Array1D< size_t >::operator[]().

template<class Type>
Type dlr::numeric::Array1D< Type >::operator() ( size_t  index  )  const [inline]

Returns the (index)th element of the array by value.

Parameters:
index Indicates the selected element.
Returns:
Value of the (index)th element of the array.

Definition at line 399 of file array1D.h.

template<class Type>
Type& dlr::numeric::Array1D< Type >::operator[] ( size_t  index  )  [inline]

Returns the (index)th element of the array by reference.

Synonymous with operator()().

Parameters:
index Indicates the selected element.
Returns:
Reference to the (index)th element of the array.

Definition at line 412 of file array1D.h.

template<class Type>
Type dlr::numeric::Array1D< Type >::operator[] ( size_t  index  )  const [inline]

Returns the (index)th element of the array by value.

Synonymous with operator()() const.

Parameters:
index Indicates the selected element.
Returns:
Value of the (index)th element of the array.

Definition at line 422 of file array1D.h.

template<class Type>
template<class Type2>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator+= ( const Array1D< Type2 > &  arg  )  [inline]

Increments each element of *this by the value of the corresponding element of arg.

Parameters:
arg Array1D of values to be added to the elements of *this.
Exceptions:
ValueException on incompatible array sizes
Returns:
Reference to *this.

Definition at line 1238 of file array1D.h.

References dlr::numeric::Array1D< Type >::data(), DLR_THROW3, and dlr::numeric::Array1D< Type >::size().

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator+= ( const Type  arg  )  [inline]

Increments each element of *this by a constant.

Parameters:
arg Value by which array elements will be incremented.
Returns:
Reference to *this.

Definition at line 1257 of file array1D.h.

template<class Type>
template<class Type2>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator-= ( const Array1D< Type2 > &  arg  )  [inline]

Decrements each element of *this by the value of the corresponding element of arg.

Parameters:
arg Array1D of values to be subtracted from the elements of *this.
Exceptions:
ValueException on incompatible array sizes
Returns:
Reference to *this.

Definition at line 1268 of file array1D.h.

References dlr::numeric::Array1D< Type >::data(), DLR_THROW3, and dlr::numeric::Array1D< Type >::size().

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator-= ( const Type  arg  )  [inline]

Decrements each element of *this by a constant.

Parameters:
arg Value by which array elements will be decremented.
Returns:
Reference to *this.

Definition at line 1287 of file array1D.h.

template<class Type>
template<class Type2>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator *= ( const Array1D< Type2 > &  arg  )  [inline]

Multiplies each element of *this by the value of the corresponding element of arg.

Parameters:
arg Array1D of values by which the elements of *this should be multiplied.
Exceptions:
ValueException on incompatible array sizes
Returns:
Reference to *this.

Definition at line 1298 of file array1D.h.

References dlr::numeric::Array1D< Type >::data(), DLR_THROW3, and dlr::numeric::Array1D< Type >::size().

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator *= ( const Type  arg  )  [inline]

Multiplies each element of *this by a constant.

Parameters:
arg Value by which array elements will be multiplied.
Returns:
Reference to *this.

Definition at line 1317 of file array1D.h.

template<class Type>
template<class Type2>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator/= ( const Array1D< Type2 > &  arg  )  [inline]

Divides each element of *this by the value of the corresponding element of arg.

Parameters:
arg Array1D of values by which the elements of *this should be divided.
Exceptions:
ValueException on incompatible array sizes
Returns:
Reference to *this.

Definition at line 1328 of file array1D.h.

References dlr::numeric::Array1D< Type >::data(), DLR_THROW3, and dlr::numeric::Array1D< Type >::size().

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator/= ( const Type  arg  )  [inline]

Divides each element of *this by a constant.

Parameters:
arg Value by which array elements will be divided.
Returns:
Reference to *this.

Definition at line 1347 of file array1D.h.


The documentation for this class was generated from the following file:
Generated on Mon Jul 9 20:34:21 2007 for dlrLibs Utility Libraries by  doxygen 1.5.2