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

Public Types | Public Member Functions | Static Public Member Functions
NumpyArray< N, T, Stride > Class Template Reference

#include <vigra/numpy_array.hxx>

Inheritance diagram for NumpyArray< N, T, Stride >:
MultiArrayView< N, NumpyArrayTraits< N, T, Stride >::value_type, Stride > NumpyAnyArray

List of all members.

Public Types

typedef value_typeconst_iterator
typedef view_type::const_pointer const_pointer
typedef view_type::const_reference const_reference
typedef view_type::const_traverser const_traverser
typedef view_type::difference_type difference_type
typedef
view_type::difference_type_1 
difference_type_1
typedef value_typeiterator
typedef view_type::pointer pointer
typedef view_type::reference reference
typedef view_type::size_type size_type
typedef view_type::traverser traverser
typedef view_type::value_type value_type
typedef MultiArrayView< N,
typename
ArrayTraits::value_type,
Stride > 
view_type
- Public Types inherited from MultiArrayView< N, NumpyArrayTraits< N, T, Stride >::value_type, Stride >
enum  ActualDimension
typedef MultiArray< N,
NumpyArrayTraits< N, T, Stride >
::value_type
matrix_type
- Public Types inherited from NumpyAnyArray

Public Member Functions

void makeCopy (PyObject *obj, bool strict=false)
bool makeReference (PyObject *obj, bool strict=true)
bool makeReference (const NumpyAnyArray &array, bool strict=true)
void makeReference (const view_type &multiArrayView)
void makeReferenceUnchecked (PyObject *obj)
 NumpyArray (PyObject *obj=0, bool createCopy=false)
 NumpyArray (const NumpyArray &other, bool createCopy=false)
 NumpyArray (const view_type &other)
 NumpyArray (difference_type const &shape)
 NumpyArray (difference_type const &shape, difference_type const &strideOrdering)
 NumpyArray (const NumpyAnyArray &other, bool createCopy=false)
NumpyArrayoperator= (const NumpyArray &other)
NumpyArrayoperator= (const NumpyAnyArray &other)
void reshape (difference_type const &shape, difference_type const &strideOrdering=standardStrideOrdering())
void reshapeIfEmpty (difference_type const &shape, std::string message="")
void reshapeIfEmpty (difference_type const &shape, difference_type const &strideOrdering, std::string message="", bool strict=false)
- Public Member Functions inherited from MultiArrayView< N, NumpyArrayTraits< N, T, Stride >::value_type, Stride >
MultiArrayView< N-1,
NumpyArrayTraits< N, T, Stride >
::value_type, typename
vigra::detail::MaybeStrided< M >
::type > 
bind (difference_type_1 d) const
MultiArrayView< N-1,
NumpyArrayTraits< N, T, Stride >
::value_type, StridedArrayTag
bindAt (difference_type_1 m, difference_type_1 d) const
MultiArrayView< N-M,
NumpyArrayTraits< N, T, Stride >
::value_type, StridedArrayTag
bindInner (const TinyVector< MultiArrayIndex, M > &d) const
MultiArrayView< N-1,
NumpyArrayTraits< N, T, Stride >
::value_type, StridedArrayTag
bindInner (difference_type_1 d) const
MultiArrayView< N-M,
NumpyArrayTraits< N, T, Stride >
::value_type, Stride > 
bindOuter (const TinyVector< MultiArrayIndex, M > &d) const
MultiArrayView< N-1,
NumpyArrayTraits< N, T, Stride >
::value_type, Stride > 
bindOuter (difference_type_1 d) const
difference_type_1 coordinateToScanOrderIndex (const difference_type &d) const
void copy (const MultiArrayView &rhs)
void copy (const MultiArrayView< N, U, CN > &rhs)
pointer data () const
difference_type_1 elementCount () const
bool hasData () const
MultiArrayViewinit (const U &init)
MultiArrayView< N+1,
NumpyArrayTraits< N, T, Stride >
::value_type, Stride > 
insertSingletonDimension (difference_type_1 i) const
bool isInside (difference_type const &p) const
 MultiArrayView ()
 MultiArrayView (const difference_type &shape, pointer ptr)
 MultiArrayView (const difference_type &shape, const difference_type &stride, pointer ptr)
NormTraits< MultiArrayView >
::NormType 
norm (int type=2, bool useSquaredNorm=true) const
bool operator!= (MultiArrayView< N, U, C1 > const &rhs) const
reference operator() (difference_type_1 x)
reference operator() (difference_type_1 x, difference_type_1 y)
reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z)
reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u)
reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u, difference_type_1 v)
const_reference operator() (difference_type_1 x) const
const_reference operator() (difference_type_1 x, difference_type_1 y) const
const_reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z) const
const_reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u) const
const_reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u, difference_type_1 v) const
MultiArrayViewoperator*= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayViewoperator*= (NumpyArrayTraits< N, T, Stride >::value_typeconst &rhs)
MultiArrayViewoperator+= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayViewoperator+= (NumpyArrayTraits< N, T, Stride >::value_typeconst &rhs)
MultiArrayViewoperator-= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayViewoperator-= (NumpyArrayTraits< N, T, Stride >::value_typeconst &rhs)
MultiArrayViewoperator/= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayViewoperator/= (NumpyArrayTraits< N, T, Stride >::value_typeconst &rhs)
MultiArrayViewoperator= (MultiArrayView const &rhs)
MultiArrayViewoperator= (MultiArrayView< N, U, C1 > const &rhs)
bool operator== (MultiArrayView< N, U, C1 > const &rhs) const
reference operator[] (const difference_type &d)
const_reference operator[] (const difference_type &d) const
MultiArrayView< N-M,
NumpyArrayTraits< N, T, Stride >
::value_type, StridedArrayTag
operator[] (const TinyVector< MultiArrayIndex, M > &d) const
reference operator[] (difference_type_1 d)
const_reference operator[] (difference_type_1 d) const
MultiArrayView< N,
NumpyArrayTraits< N, T, Stride >
::value_type, StridedArrayTag
permuteDimensions (const difference_type &s) const
MultiArrayView< N,
NumpyArrayTraits< N, T, Stride >
::value_type, StridedArrayTag
permuteStridesAscending () const
MultiArrayView< N,
NumpyArrayTraits< N, T, Stride >
::value_type, StridedArrayTag
permuteStridesDescending () const
difference_type scanOrderIndexToCoordinate (difference_type_1 d) const
const difference_typeshape () const
difference_type_1 shape (difference_type_1 n) const
difference_type_1 size () const
difference_type_1 size (difference_type_1 n) const
NormTraits< MultiArrayView >
::SquaredNormType 
squaredNorm () const
const difference_typestride () const
difference_type_1 stride (int n) const
MultiArrayView< N,
NumpyArrayTraits< N, T, Stride >
::value_type, StridedArrayTag
stridearray (const difference_type &s) const
difference_type strideOrdering () const
MultiArrayView subarray (const difference_type &p, const difference_type &q) const
void swapData (MultiArrayView rhs)
void swapData (MultiArrayView< N, T2, C2 > rhs)
MultiArrayView< N,
NumpyArrayTraits< N, T, Stride >
::value_type, StridedArrayTag
transpose () const
traverser traverser_begin ()
const_traverser traverser_begin () const
traverser traverser_end ()
const_traverser traverser_end () const
- Public Member Functions inherited from NumpyAnyArray
int dtype () 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)
PyArrayObject * pyArray () const
PyObject * pyObject () const
difference_type shape () const
MultiArrayIndex spatialDimensions () const
difference_type strideOrdering () const

Static Public Member Functions

static bool isCopyCompatible (PyObject *obj)
static bool isReferenceCompatible (PyObject *obj)
static bool isStrictlyCompatible (PyObject *obj)
static difference_type standardStrideOrdering ()
- Static Public Member Functions inherited from MultiArrayView< N, NumpyArrayTraits< N, T, Stride >::value_type, Stride >
static difference_type strideOrdering (difference_type strides)

Additional Inherited Members

- Protected Attributes inherited from MultiArrayView< N, NumpyArrayTraits< N, T, Stride >::value_type, Stride >
pointer m_ptr
difference_type m_shape
difference_type m_stride

Detailed Description

template<unsigned int N, class T, class Stride = StridedArrayTag>
class vigra::NumpyArray< N, T, Stride >

Provide the MultiArrayView interface for a Python array.

This class inherits from both vigra::MultiArrayView and vigra::NumpyAnyArray in order to support easy and save application of VIGRA functions to Python arrays.

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


Member Typedef Documentation

typedef MultiArrayView<N, typename ArrayTraits::value_type, Stride> view_type

the view type associated with this array.

Reimplemented from MultiArrayView< N, NumpyArrayTraits< N, T, Stride >::value_type, Stride >.

reference type (result of operator[])

Reimplemented from MultiArrayView< N, NumpyArrayTraits< N, T, Stride >::value_type, Stride >.

const reference type (result of operator[] const)

Reimplemented from MultiArrayView< N, NumpyArrayTraits< N, T, Stride >::value_type, Stride >.

difference type (used for multi-dimensional offsets and indices)

Reimplemented from NumpyAnyArray.

difference and index type for a single dimension

Reimplemented from MultiArrayView< N, NumpyArrayTraits< N, T, Stride >::value_type, Stride >.

traverser type to const data

Reimplemented from MultiArrayView< N, NumpyArrayTraits< N, T, Stride >::value_type, Stride >.

typedef value_type* iterator

sequential (random access) iterator type

sequential (random access) const iterator type


Constructor & Destructor Documentation

NumpyArray ( PyObject *  obj = 0,
bool  createCopy = false 
)
explicit

Construct from a given PyObject pointer. When the given python object is NULL, the internal python array will be NULL and hasData() will return false.

Otherwise, the function attempts to create a new reference to the given Python object, unless copying is forced by setting createCopy to true. If either of this fails, the function throws an exception. This will not happen if isStrictlyCompatible(obj) (in case of creating a new reference) or isCopyCompatible(obj) (in case of copying) have returned true beforehand.

NumpyArray ( const NumpyArray< N, T, Stride > &  other,
bool  createCopy = false 
)

Copy constructor; does not copy the memory, but creates a new reference to the same underlying python object, unless a copy is forced by setting createCopy to true. (If the source object has no data, this one will have no data, too.)

NumpyArray ( const view_type other)
explicit

Allocate new memory and copy data from a MultiArrayView.

NumpyArray ( difference_type const &  shape)
explicit

Construct a new array object, allocating an internal python ndarray of the given shape (in fortran order), initialized with zeros.

An exception is thrown when construction fails.

NumpyArray ( difference_type const &  shape,
difference_type const &  strideOrdering 
)

Construct a new array object, allocating an internal python ndarray of the given shape and given stride ordering, initialized with zeros.

An exception is thrown when construction fails.

NumpyArray ( const NumpyAnyArray other,
bool  createCopy = false 
)

Constructor from NumpyAnyArray. Equivalent to NumpyArray(other.pyObject())


Member Function Documentation

NumpyArray& operator= ( const NumpyArray< N, T, Stride > &  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. If this is an empty view, assignment is identical to makeReferenceUnchecked(other.pyObject()). See MultiArrayView::operator= for further information on semantics.

NumpyArray& operator= ( const NumpyAnyArray 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. If this is an empty view, assignment is identical to makeReference(other.pyObject()). Otherwise, an exception is thrown.

Reimplemented from NumpyAnyArray.

static bool isCopyCompatible ( PyObject *  obj)
static

Test whether a given python object is a numpy array that can be converted (copied) into an array compatible to this NumpyArray type. This means that the array's shape conforms to the requirements of makeCopy().

static bool isReferenceCompatible ( PyObject *  obj)
static

Test whether a given python object is a numpy array with a compatible dtype and the correct shape and strides, so that it can be referenced as a view by this NumpyArray type (i.e. it conforms to the requirements of makeReference()).

static bool isStrictlyCompatible ( PyObject *  obj)
static

Like isReferenceCompatible(obj), but also executes a customized type compatibility check when such a check has been registered for this class via registerPythonArrayType().

This facilitates proper overload resolution between NumpyArray<3, Multiband<T> > (a multiband image) and NumpyArray<3, Singleband<T> > (a scalar volume).

static difference_type standardStrideOrdering ( )
static

Create a vector representing the standard stride ordering of a NumpyArray. That is, we get a vector representing the range [0,...,N-1], which denotes the stride ordering for Fortran order.

void makeReferenceUnchecked ( PyObject *  obj)

Set up a view to the given object without checking compatibility. This function must not be used unless isReferenceCompatible(obj) returned true on the given object (otherwise, a crash is likely).

bool makeReference ( PyObject *  obj,
bool  strict = true 
)

Try to set up a view referencing the given PyObject. Returns false if the python object is not a compatible numpy array (see isReferenceCompatible() or isStrictlyCompatible(), according to the parameter strict).

bool makeReference ( const NumpyAnyArray array,
bool  strict = true 
)

Try to set up a view referencing the same data as the given NumpyAnyArray. This overloaded variant simply calls makeReference() on array.pyObject().

void makeReference ( const view_type multiArrayView)

Set up an unsafe reference to the given MultiArrayView. ATTENTION: This creates a numpy.ndarray that points to the same data, but does not own it, so it must be ensured by other means that the memory does not get freed before the end of the ndarray's lifetime! (One elegant way would be to set the 'base' attribute of the resulting ndarray to a python object which directly or indirectly holds the memory of the given MultiArrayView.)

void makeCopy ( PyObject *  obj,
bool  strict = false 
)

Try to create a copy of the given PyObject. Raises an exception when obj is not a compatible array (see isCopyCompatible() or isStrictlyCompatible(), according to the parameter strict) or the Python constructor call failed.

void reshape ( difference_type const &  shape,
difference_type const &  strideOrdering = standardStrideOrdering() 
)

Allocate new memory with the given shape and initialize with zeros.
If a stride ordering is given, the resulting array will have this stride ordering, when it is compatible with the array's memory layout (unstrided arrays only permit the standard ascending stride ordering).

Note: this operation invalidates dependent objects (MultiArrayViews and iterators)

void reshapeIfEmpty ( difference_type const &  shape,
std::string  message = "" 
)

When this array has no data, allocate new memory with the given shape and initialize with zeros. Otherwise, check if the new shape matches the old shape and throw a precondition exception with the given message if not.

void reshapeIfEmpty ( difference_type const &  shape,
difference_type const &  strideOrdering,
std::string  message = "",
bool  strict = false 
)

When this array has no data, allocate new memory with the given shape and initialize with zeros. Otherwise, check if the new shape matches the old shape and throw a precondition exception with the given message if not. If strict is true, the given stride ordering must also match that of the existing data.


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

© 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 (Tue Jul 10 2012)