[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

| NumpyAnyArray |

`#include <vigra/numpy_array.hxx>`

Inheritance diagram for NumpyAnyArray:

List of all members.

## Public Types
typedef ArrayVector< npy_intp > | difference_type
| difference type
## Public Member Functions
int | dtype () const
bool | hasData () const
void | makeCopy (PyObject *obj, PyTypeObject *type=0)
bool | makeReference (PyObject *obj, PyTypeObject *type=0)
MultiArrayIndex | ndim () const
| NumpyAnyArray (NumpyAnyArray const &other, bool createCopy=false, PyTypeObject *type=0)
| NumpyAnyArray (PyObject *obj=0, bool createCopy=false, PyTypeObject *type=0)
NumpyAnyArray & | operator= (NumpyAnyArray const &other)
PyArrayObject * | pyArray () const
PyObject * | pyObject () const
difference_type | shape () const
MultiArrayIndex | spatialDimensions () const
difference_type | strideOrdering () const

## Detailed Description

Wrapper class for a Python array.

This class stores a reference-counted pointer to an Python numpy array object, i.e. an object where `PyArray_Check(object)` returns true (in Python, the object is then a subclass of `numpy.ndarray`). This class is mainly used as a smart pointer to these arrays, but some basic access and conversion functions are also provided.

#include <vigra/numpy_array.hxx>
Namespace: vigra

## Constructor & Destructor Documentation

NumpyAnyArray | ( | PyObject * | obj = `0`,
|  | bool | createCopy = `false`,
|  | PyTypeObject * | type = `0` |
| ) |  |  | `[explicit]`

Construct from a Python object. If obj is NULL, or is not a subclass of numpy.ndarray, the resulting NumpyAnyArray will have no data (i.e. hasData() returns false). Otherwise, it creates a new reference to the array obj, unless createCopy is true, where a new array is created by calling the C-equivalent of obj->copy().

NumpyAnyArray | ( | NumpyAnyArray const & | other,
|  | bool | createCopy = `false`,
|  | PyTypeObject * | type = `0` |
| ) |  |  |

Copy constructor. By default, it creates a new reference to the array other. When createCopy is true, a new array is created by calling the C-equivalent of other.copy().

## Member Function Documentation

int dtype | ( |  | ) | const

Returns the value type of the elements in this array, or -1 when hasData() is false.

bool hasData | ( |  | ) | const

Check whether this NumpyAnyArray actually points to a Python array.

void makeCopy | ( | PyObject * | obj,
|  | PyTypeObject * | type = `0` |
| ) |  |  |

Create a copy of the given array object. If obj is a numpy array object, a copy is created via the C-equivalent of 'obj->copy()'. If this call fails, or obj was not an array, an exception is thrown and the NumpyAnyArray remains unchanged.

bool makeReference | ( | PyObject * | obj,
|  | PyTypeObject * | type = `0` |
| ) |  |  |

Reset the NumpyAnyArray to the given object. If obj is a numpy array object, a new reference to that array is created, and the function returns true. Otherwise, it returns false and the NumpyAnyArray remains unchanged. If type is given, the new reference will be a view with that type, provided that type is a numpy ndarray or a subclass thereof. Otherwise, an exception is thrown.

MultiArrayIndex ndim | ( |  | ) | const

Returns the number of dimensions of this array, or 0 if hasData() is false.

NumpyAnyArray& operator= | ( | NumpyAnyArray const & | other | ) |

Assignment operator. If this is already a view with data (i.e. hasData() is true) and the shapes match, the RHS array contents are copied via the C-equivalent of 'self[...] = other[...]'. If the shapes don't matched, broadcasting is tried on the trailing (i.e. channel) dimension. If the LHS is an empty view, assignment is identical to makeReference(other.pyObject()).

Reimplemented in NumpyArray.

PyArrayObject* pyArray | ( |  | ) | const

Return a borrowed reference to the internal PyArrayObject.

PyObject* pyObject | ( |  | ) | const

Return a borrowed reference to the internal PyArrayObject (see pyArray()), cast to PyObject for your convenience.

difference_type shape | ( |  | ) | const

Returns the shape of this array. The size of the returned shape equals ndim().

MultiArrayIndex spatialDimensions | ( |  | ) | const

Returns the number of spatial dimensions of this array, or 0 if hasData() is false. If the enclosed Python array does not define the attribute spatialDimensions, ndim() is returned.

difference_type strideOrdering | ( |  | ) | const

Compute the ordering of the strides of this array. The result is describes the current permutation of the axes relative to an ascending stride order.

The documentation for this class was generated from the following file:

- vigra/numpy_array.hxx

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.7.1 (3 Dec 2010)