#include <arrayND.h>
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 | |
| ArrayND () | |
| Default constructor initializes to zero size. | |
| ArrayND (size_t dimension, size_t const shape[]) | |
| Constructs an array with a user-specified shape. | |
| ArrayND (const Array1D< size_t > &shape) | |
| Constructs an array with a user-specified shape. | |
| ArrayND (const ArrayND< Dimension, Type > &source) | |
| The copy constructor does a shallow copy. | |
| ArrayND (const std::string &inputString) | |
| Construct from an initialization string. | |
| ~ArrayND () | |
| Destroys the ArrayND 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 (Array1D< size_t > const &shape) 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. | |
| ArrayND< Dimension, Type > | copy () const |
| Allocate a new array and deep copy the contents of *this. | |
| template<class Type2> | |
| void | copy (const ArrayND< Dimension, 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 ArrayND, 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. | |
| size_t | flattenIndex (const Array1D< size_t > &indexArray) const |
| This member function converts a multi-dimensional index (such as would be passed to getElement(Array1D<size_t> const&)) into a scalar index (such as would be passed to getElement(size_t). | |
| Type | getElement (size_t index0) const |
| This member function returns a specific element of the array by value. | |
| Type | getElement (Array1D< size_t > const &index0) const |
| This member function returns a specific element of the array by value. | |
| const Array1D< size_t > & | getShape () const |
| This member function returns a (reference to an) array describing the shape of *this. | |
| size_t | getStride (size_t axis) const |
| This member function establishes the relationship between single-indexing (for example using getElement(size_t)) and array indexing (for example using getElement(Array1D<size_t> const&)) by returning the single-index offset between adjacent elements along the specified axis. | |
| bool | isAllocated () const |
| Indicates whether the internal data array is being managed (and reference counted) by *this. | |
| Array1D< Type > | ravel () |
| Returns an Array1D, with size equal to this->size(), which references the same data as *this. | |
| Array1D< Type > const | ravel () const |
| Returns an Array1D, with size equal to this->size(), which references the same data as *this. | |
| void | reinit (Array1D< size_t > const &shape) |
| Changes the shape of the array and reallocates storage. | |
| Type & | setElement (size_t index0, const Type &value) |
| This member function sets the value of a specific element of the array. | |
| Type & | setElement (Array1D< size_t > const &index0, const Type &value) |
| This member function sets the value of a specific element of the array. | |
| size_t | size () const |
| Returns the number of elements in the array. | |
| ArrayND< Dimension, Type > & | operator= (const ArrayND< Dimension, Type > &source) |
| Assignment operator shallow copies the contents of source. | |
| ArrayND< Dimension, Type > & | operator= (Type value) |
| Assign value to every element in the array. | |
| Type & | operator() (size_t index0) |
| Returns the (index)th element of the array by reference. | |
| Type | operator() (size_t index0) const |
| Returns the (index)th element of the array by value. | |
| Type & | operator() (Array1D< size_t > const &index0) |
| Returns the (index)th element of the array by reference. | |
| Type | operator() (Array1D< size_t > const &index0) 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> | |
| ArrayND< Dimension, Type > & | operator+= (const ArrayND< Dimension, Type2 > &arg) |
| Increments each element of *this by the value of the corresponding element of arg. | |
| ArrayND< Dimension, Type > & | operator+= (const Type arg) |
| Increments each element of *this by a constant. | |
| template<class Type2> | |
| ArrayND< Dimension, Type > & | operator-= (const ArrayND< Dimension, Type2 > &arg) |
| Decrements each element of *this by the value of the corresponding element of arg. | |
| ArrayND< Dimension, Type > & | operator-= (const Type arg) |
| Decrements each element of *this by a constant. | |
| template<class Type2> | |
| ArrayND< Dimension, Type > & | operator*= (const ArrayND< Dimension, Type2 > &arg) |
| Multiplies each element of *this by the value of the corresponding element of arg. | |
| ArrayND< Dimension, Type > & | operator*= (const Type arg) |
| Multiplies each element of *this by a constant. | |
| template<class Type2> | |
| ArrayND< Dimension, Type > & | operator/= (const ArrayND< Dimension, Type2 > &arg) |
| Divides each element of *this by the value of the corresponding element of arg. | |
| ArrayND< Dimension, Type > & | operator/= (const Type arg) |
| Divides each element of *this by a constant. | |
Element storage in the ArrayND class is contiguous along the last axis, then the next-to-last axis, etc. To make this clearer, you can think of the 2-dimensional array in the example below as having 3 rows and 4 columns, with the elements stored in raster order, starting from the top-left corner of the array.
size_t const shape[] = {3, 4}; ArrayND<2, int> exampleArray3x4(shape);
In the current implementation, there is no provision for padding between rows of the array (for example, to align on 16-byte boundaries). We may add support for this later, however the default behavior will always be to have no padding unless it is explicitly enabled. If your code counts on contiguous storage in an ArrayND instance passed in from code you do not control, you can make sure there's no padding by confirming that the isContiguous() method returns true.
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 73 of file arrayND.h.
| typedef Type dlr::numeric::ArrayND< Dimension, Type >::value_type |
| typedef Type* dlr::numeric::ArrayND< Dimension, Type >::iterator |
| typedef const Type* dlr::numeric::ArrayND< Dimension, Type >::const_iterator |
| dlr::numeric::ArrayND< Dimension, Type >::ArrayND | ( | ) | [inline] |
| dlr::numeric::ArrayND< Dimension, Type >::ArrayND | ( | size_t | dimension, | |
| size_t const | shape[] | |||
| ) | [inline, explicit] |
Constructs an array with a user-specified shape.
For example, the following code constructs a 2-dimensional ArrayND instance with 5 rows and 6 columns:
size_t shape[] = {5, 6};
ArrayND<2, int> myArray(2, shape);
Here's a second example, which creates a 3-dimensional ArrayND instance with 2 levels of 5 rows and 6 columns:
size_t const shape[] = {2, 5, 6}; ArrayND<3, int> myArray(3, shape);
| dimension | This argument specifies the dimension (number of axes) in the array. Set this to 1 if you want a vector, 2 if you want a matrix, 3 if you want a 3D array, etc. | |
| shape | This array specifies the size (number of elements along each axis) of the new ArrayND instance. |
Definition at line 1032 of file arrayND.h.
References dlr::numeric::Array1D< Type >::copy().
| dlr::numeric::ArrayND< Dimension, Type >::ArrayND | ( | const Array1D< size_t > & | shape | ) | [inline, explicit] |
Constructs an array with a user-specified shape.
For example, the following code constructs a 2-dimensional ArrayND instance with 5 rows and 6 columns:
ArrayND<2, int> myArray(Array1D<size_t>("[5, 6]"));
Here's a second example, which creates a 3-dimensional ArrayND instance with 2 levels of 5 rows and 6 columns:
ArrayND<3, int> myArray(Array1D<size_t>("[2, 5, 6]"));
| shape | This array specifies the size (number of elements along each axis) of the new ArrayND instance. |
| dlr::numeric::ArrayND< Dimension, Type >::ArrayND | ( | const ArrayND< Dimension, Type > & | source | ) | [inline] |
| dlr::numeric::ArrayND< Dimension, Type >::ArrayND | ( | const std::string & | inputString | ) | [inline, explicit] |
Construct from an initialization string.
Ultimately, this constructor will be very flexible about interpreting string syntax, but right now it only accepts a secret format known only to the developers of this library.
| inputString | The argument specifies the string from which the array will be constructed. |
| dlr::numeric::ArrayND< Dimension, Type >::~ArrayND | ( | ) | [inline] |
| iterator dlr::numeric::ArrayND< Dimension, Type >::begin | ( | ) | [inline] |
Return begin() iterator for Standard Library algorithms.
Definition at line 190 of file arrayND.h.
Referenced by dlr::numeric::operator*(), dlr::numeric::operator+(), dlr::numeric::operator-(), dlr::numeric::operator/(), dlr::numeric::operator==(), dlr::numeric::operator>(), and dlr::numeric::operator>=().
| const_iterator dlr::numeric::ArrayND< Dimension, Type >::begin | ( | ) | const [inline] |
| void dlr::numeric::ArrayND< Dimension, Type >::checkDimension | ( | Array1D< size_t > const & | shape | ) | const [inline] |
Optionally throw an exception if the shape of *this is different than specified.
| size | The required array size. |
Definition at line 1092 of file arrayND.h.
References dlr::numeric::Array1D< Type >::size().
Referenced by dlr::numeric::ArrayND< Dimension, Type >::copy(), and dlr::numeric::operator==().
| void dlr::numeric::ArrayND< Dimension, Type >::clear | ( | ) | [inline] |
Reset the array to zero size, abandoning all contents.
This is equivalent to this->reinit(0);
Definition at line 218 of file arrayND.h.
References dlr::numeric::Array1D< Type >::reinit().
| ArrayND< Dimension, Type > dlr::numeric::ArrayND< Dimension, Type >::copy | ( | ) | const [inline] |
Allocate a new array and deep copy the contents of *this.
Definition at line 1119 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::copy().
Referenced by dlr::numeric::ArrayND< Dimension, Type >::copy().
| void dlr::numeric::ArrayND< Dimension, Type >::copy | ( | const ArrayND< Dimension, Type2 > & | source | ) | [inline] |
Deep copies the contents of source.
It is an error if source does not have the same shape as *this.
| source | The array to be copied. |
| ValueException | on incompatible array sizes |
Definition at line 1129 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::checkDimension(), dlr::numeric::ArrayND< Dimension, Type >::copy(), dlr::numeric::ArrayND< Dimension, Type >::data(), and dlr::numeric::ArrayND< Dimension, Type >::m_shape.
| void dlr::numeric::ArrayND< Dimension, Type >::copy | ( | const Type2 * | dataPtr | ) | [inline] |
| Type* dlr::numeric::ArrayND< Dimension, Type >::data | ( | void | ) | [inline] |
Returns a pointer to the internal data store.
This is ugly but often necessary for interfacing with external libraries. In the current implementation, data is stored contiguously. At some point, we may add support for padding to byte-align subsequent rows. In this event, any ArrayND instance for which the returned data is not contiguous will also return false from member function isContiguous().
Definition at line 266 of file arrayND.h.
Referenced by dlr::numeric::ArrayND< Dimension, Type >::copy().
| const Type* dlr::numeric::ArrayND< Dimension, Type >::data | ( | void | ) | const [inline] |
This version of data(void) is appropriate for const ArrayND, and returns a pointer-to-const.
| bool dlr::numeric::ArrayND< Dimension, Type >::empty | ( | ) | const [inline] |
| iterator dlr::numeric::ArrayND< Dimension, Type >::end | ( | ) | [inline] |
Return end() iterator for Standard Library algorithms.
Definition at line 299 of file arrayND.h.
Referenced by dlr::numeric::operator*(), dlr::numeric::operator+(), dlr::numeric::operator-(), dlr::numeric::operator/(), dlr::numeric::operator==(), dlr::numeric::operator>(), and dlr::numeric::operator>=().
| const_iterator dlr::numeric::ArrayND< Dimension, Type >::end | ( | ) | const [inline] |
| size_t dlr::numeric::ArrayND< Dimension, Type >::flattenIndex | ( | const Array1D< size_t > & | indexArray | ) | const [inline] |
This member function converts a multi-dimensional index (such as would be passed to getElement(Array1D<size_t> const&)) into a scalar index (such as would be passed to getElement(size_t).
| indexArray | This argument is the array to be converted. |
Definition at line 1160 of file arrayND.h.
References dlr::numeric::Array1D< Type >::begin(), and dlr::numeric::Array1D< Type >::end().
Referenced by dlr::numeric::convolve(), dlr::numeric::ArrayND< Dimension, Type >::operator()(), and dlr::numeric::ArrayND< Dimension, Type >::setElement().
| Type dlr::numeric::ArrayND< Dimension, Type >::getElement | ( | size_t | index0 | ) | const [inline] |
This member function returns a specific element of the array by value.
| index0 | This argument specifies which element value should be returned. |
Definition at line 336 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::operator()().
| Type dlr::numeric::ArrayND< Dimension, Type >::getElement | ( | Array1D< size_t > const & | index0 | ) | const [inline] |
This member function returns a specific element of the array by value.
| index0 | This argument specifies which element value should be returned. |
Definition at line 349 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::operator()().
| const Array1D<size_t>& dlr::numeric::ArrayND< Dimension, Type >::getShape | ( | ) | const [inline] |
This member function returns a (reference to an) array describing the shape of *this.
Note that Array1D copy semantics are _shallow_, so you'll actually get an array that references memory inside *this. If you copy (shallow copy) this array, and then modify its contents, you will break the internal state of *this.
Definition at line 366 of file arrayND.h.
Referenced by dlr::numeric::convolve(), dlr::numeric::operator*(), dlr::numeric::operator+(), dlr::numeric::operator-(), dlr::numeric::operator/(), dlr::numeric::operator==(), dlr::numeric::operator>(), and dlr::numeric::operator>=().
| size_t dlr::numeric::ArrayND< Dimension, Type >::getStride | ( | size_t | axis | ) | const [inline] |
This member function establishes the relationship between single-indexing (for example using getElement(size_t)) and array indexing (for example using getElement(Array1D<size_t> const&)) by returning the single-index offset between adjacent elements along the specified axis.
| axis | This argument specifies the axis along which we wish to move. |
Definition at line 384 of file arrayND.h.
Referenced by dlr::numeric::convolve().
| bool dlr::numeric::ArrayND< Dimension, 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.
| Array1D<Type> dlr::numeric::ArrayND< Dimension, Type >::ravel | ( | ) | [inline] |
| Array1D<Type> const dlr::numeric::ArrayND< Dimension, Type >::ravel | ( | ) | const [inline] |
| void dlr::numeric::ArrayND< Dimension, Type >::reinit | ( | Array1D< size_t > const & | shape | ) | [inline] |
Changes the shape of the array and reallocates storage.
The current array contents are lost.
| size | Number of elements in the array after reallocation. |
Definition at line 1171 of file arrayND.h.
References dlr::numeric::Array1D< Type >::copy().
| Type& dlr::numeric::ArrayND< Dimension, Type >::setElement | ( | size_t | index0, | |
| const Type & | value | |||
| ) | [inline] |
This member function sets the value of a specific element of the array.
| index0 | This argument specifies which element value should be set. | |
| value | This argument will be copied into the selected array element. |
Definition at line 445 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::operator()().
| Type& dlr::numeric::ArrayND< Dimension, Type >::setElement | ( | Array1D< size_t > const & | index0, | |
| const Type & | value | |||
| ) | [inline] |
This member function sets the value of a specific element of the array.
| index0 | This argument specifies which element value should be set. | |
| value | This argument will be copied into the selected array element. |
Definition at line 464 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::flattenIndex(), and dlr::numeric::ArrayND< Dimension, Type >::operator()().
| size_t dlr::numeric::ArrayND< Dimension, Type >::size | ( | ) | const [inline] |
Returns the number of elements in the array.
Definition at line 475 of file arrayND.h.
Referenced by dlr::numeric::operator*(), dlr::numeric::operator+(), dlr::numeric::operator-(), and dlr::numeric::operator/().
| ArrayND< Dimension, Type > & dlr::numeric::ArrayND< Dimension, Type >::operator= | ( | const ArrayND< Dimension, Type > & | source | ) | [inline] |
Assignment operator shallow copies the contents of source.
After the copy, both arrays reference the same data.
| source | The ArrayND instance to be copied. |
Definition at line 1181 of file arrayND.h.
References dlr::numeric::Array1D< Type >::copy(), dlr::numeric::ArrayND< Dimension, Type >::m_shape, dlr::numeric::ArrayND< Dimension, Type >::m_storage, and dlr::numeric::ArrayND< Dimension, Type >::m_strideArray.
| ArrayND< Dimension, Type > & dlr::numeric::ArrayND< Dimension, Type >::operator= | ( | Type | value | ) | [inline] |
| Type& dlr::numeric::ArrayND< Dimension, Type >::operator() | ( | size_t | index0 | ) | [inline] |
Returns the (index)th element of the array by reference.
| index | Indicates the selected element. |
Definition at line 509 of file arrayND.h.
Referenced by dlr::numeric::ArrayND< Dimension, Type >::getElement(), dlr::numeric::ArrayND< Dimension, Type >::operator[](), and dlr::numeric::ArrayND< Dimension, Type >::setElement().
| Type dlr::numeric::ArrayND< Dimension, Type >::operator() | ( | size_t | index0 | ) | const [inline] |
| Type& dlr::numeric::ArrayND< Dimension, Type >::operator() | ( | Array1D< size_t > const & | index0 | ) | [inline] |
Returns the (index)th element of the array by reference.
| index | Indicates the selected element. |
Definition at line 530 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::flattenIndex().
| Type dlr::numeric::ArrayND< Dimension, Type >::operator() | ( | Array1D< size_t > const & | index0 | ) | const [inline] |
Returns the (index)th element of the array by value.
| index | Indicates the selected element. |
Definition at line 542 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::flattenIndex().
| Type& dlr::numeric::ArrayND< Dimension, Type >::operator[] | ( | size_t | index | ) | [inline] |
Returns the (index)th element of the array by reference.
Synonymous with operator()().
| index | Indicates the selected element. |
Definition at line 555 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::operator()().
| Type dlr::numeric::ArrayND< Dimension, Type >::operator[] | ( | size_t | index | ) | const [inline] |
Returns the (index)th element of the array by value.
Synonymous with operator()() const.
| index | Indicates the selected element. |
Definition at line 566 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::operator()().
| ArrayND< Dimension, Type > & dlr::numeric::ArrayND< Dimension, Type >::operator+= | ( | const ArrayND< Dimension, Type2 > & | arg | ) | [inline] |
Increments each element of *this by the value of the corresponding element of arg.
| arg | ArrayND of values to be added to the elements of *this. |
| ValueException | on incompatible array sizes |
Definition at line 1196 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::m_storage.
| ArrayND< Dimension, Type > & dlr::numeric::ArrayND< Dimension, Type >::operator+= | ( | const Type | arg | ) | [inline] |
| ArrayND< Dimension, Type > & dlr::numeric::ArrayND< Dimension, Type >::operator-= | ( | const ArrayND< Dimension, Type2 > & | arg | ) | [inline] |
Decrements each element of *this by the value of the corresponding element of arg.
| arg | ArrayND of values to be subtracted from the elements of *this. |
| ValueException | on incompatible array sizes |
Definition at line 1217 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::m_storage.
| ArrayND< Dimension, Type > & dlr::numeric::ArrayND< Dimension, Type >::operator-= | ( | const Type | arg | ) | [inline] |
| ArrayND< Dimension, Type > & dlr::numeric::ArrayND< Dimension, Type >::operator*= | ( | const ArrayND< Dimension, Type2 > & | arg | ) | [inline] |
Multiplies each element of *this by the value of the corresponding element of arg.
| arg | ArrayND of values by which the elements of *this should be multiplied. |
| ValueException | on incompatible array sizes |
Definition at line 1238 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::m_storage.
| ArrayND< Dimension, Type > & dlr::numeric::ArrayND< Dimension, Type >::operator*= | ( | const Type | arg | ) | [inline] |
| ArrayND< Dimension, Type > & dlr::numeric::ArrayND< Dimension, Type >::operator/= | ( | const ArrayND< Dimension, Type2 > & | arg | ) | [inline] |
Divides each element of *this by the value of the corresponding element of arg.
| arg | ArrayND of values by which the elements of *this should be divided. |
| ValueException | on incompatible array sizes |
Definition at line 1259 of file arrayND.h.
References dlr::numeric::ArrayND< Dimension, Type >::m_storage.
| ArrayND< Dimension, Type > & dlr::numeric::ArrayND< Dimension, Type >::operator/= | ( | const Type | arg | ) | [inline] |
1.5.6