vigra - NumpyAnyArray Class Reference

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

| NumpyAnyArray Class Reference |

`#include <vigra/numpy_array.hxx>`

Inheritance diagram for NumpyAnyArray:

## Public Types
typedef ArrayVector< npy_intp > | difference_type
| difference type

## Public Member Functions
python_ptr | axistags () const
int | dtype () const
template<class Shape >
NumpyAnyArray | getitem (Shape start, Shape stop) const
bool | hasData () const
void | makeCopy (PyObject *obj, PyTypeObject *type=0)
bool | makeReference (PyObject *obj, PyTypeObject *type=0)
MultiArrayIndex | ndim () const
| NumpyAnyArray (PyObject *obj=0, bool createCopy=false, PyTypeObject *type=0)
| NumpyAnyArray (NumpyAnyArray const &other, 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

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()).

MultiArrayIndex ndim | ( |  | ) | const

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

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 shape | ( |  | ) | const

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

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.

int dtype | ( |  | ) | const

Returns the the permutation that will transpose this array into canonical ordering (currently: F-order). The size of the returned permutation equals ndim(). Returns the value type of the elements in this array, or -1 when hasData() is false.

NumpyAnyArray getitem | ( | Shape | start,
|  | Shape | stop
| ) |  | const

Constructs a slicing from the given shape objects and calls 'getitem'.

python_ptr axistags | ( |  | ) | const

Return the AxisTags of this array or a NULL pointer when the attribute 'axistags' is missing in the Python object or this array has no data.

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.

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.

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 hasData | ( |  | ) | const

Check whether this NumpyAnyArray actually points to a Python array.

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.11.0 (Fri May 19 2017)