|
Michele De Stefano's C++ Utilities
|
Wrapper class for NumPy 1D arrays. More...
#include <mds_utils/python/ublas/numpy_array.hpp>
Public Types | |
| typedef npy_intp | size_type |
| typedef npy_intp | difference_type |
| typedef T | value_type |
| typedef const T & | const_reference |
| typedef T & | reference |
| typedef T * | pointer |
| typedef const T * | const_pointer |
| typedef pointer | array_type |
| typedef const vector_reference< const self_type > | const_closure_type |
| typedef vector_reference< self_type > | closure_type |
| typedef self_type | vector_temporary_type |
| typedef dense_tag | storage_category |
| typedef indexed_iterator< self_type, dense_random_access_iterator_tag > | iterator |
| typedef indexed_const_iterator< self_type, dense_random_access_iterator_tag > | const_iterator |
| typedef reverse_iterator_base< const_iterator > | const_reverse_iterator |
| typedef reverse_iterator_base< iterator > | reverse_iterator |
Public Member Functions | |
| PyArrayObject * | getPyArrayObject () const |
| Returns the underlying PyArrayObject. | |
| operator PyArrayObject * () const | |
| Automatic type conversion operator. | |
| void | incref () |
| Increments the reference count using Py_XINCREF. More... | |
| void | decref () |
| Decrements the reference count using Py_XDECREF. | |
| PyObject * | transfer () |
| Returns the Python object with transferred ownership. More... | |
| BOOST_UBLAS_INLINE | NumPy1DArray () |
| Default constructor. More... | |
| BOOST_UBLAS_INLINE | NumPy1DArray (size_type n) |
| Constructor of a vector with a predefined size. More... | |
| template<class FwIt > | |
| BOOST_UBLAS_INLINE | NumPy1DArray (FwIt b, FwIt e) |
| Constructor of a vector by copying from another container. More... | |
| BOOST_UBLAS_INLINE | NumPy1DArray (size_type n, const_reference init) |
| Constructor of a vector with a unique initial value. More... | |
| BOOST_UBLAS_INLINE size_type | size () const |
| Return the size of the vector. More... | |
| BOOST_UBLAS_INLINE | NumPy1DArray (const NumPy1DArray &rhs) |
| Copy-constructor. More... | |
| BOOST_UBLAS_INLINE | NumPy1DArray (NumPy1DArray &&rhs) |
| Move constructor. More... | |
| template<class AE > | |
| BOOST_UBLAS_INLINE | NumPy1DArray (const vector_expression< AE > &ae) |
Copy-constructor of a NumPy1DArray from a vector_expression. More... | |
| NumPy1DArray (PyObject *rhs) | |
| Constructor from PyObject. More... | |
| BOOST_UBLAS_INLINE pointer | find_element (size_type i) |
Return a pointer to the element . More... | |
| BOOST_UBLAS_INLINE const_pointer | find_element (size_type i) const |
Return a const pointer to the element . More... | |
| BOOST_UBLAS_INLINE const_reference | operator() (size_type i) const |
Return a const reference to the element . More... | |
| BOOST_UBLAS_INLINE reference | operator() (size_type i) |
Return a reference to the element . More... | |
| BOOST_UBLAS_INLINE const_reference | operator[] (size_type i) const |
Return a const reference to the element . More... | |
| BOOST_UBLAS_INLINE reference | operator[] (size_type i) |
Return a reference to the element . More... | |
| BOOST_UBLAS_INLINE void | clear () |
Clear the vector, i.e. set all values to the zero value. More... | |
| template<class AE > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | assign (const vector_expression< AE > &ae) |
| Assign the result of a vector_expression to the vector. More... | |
| BOOST_UBLAS_INLINE NumPy1DArray & | assign_temporary (NumPy1DArray &rhs) |
| Assign a full vector (RHS-vector) to the current vector (LHS-vector). More... | |
| BOOST_UBLAS_INLINE NumPy1DArray & | operator= (const NumPy1DArray &rhs) |
| Assign a full vector (RHS-vector) to the current vector (LHS-vector). More... | |
| BOOST_UBLAS_INLINE NumPy1DArray & | operator= (NumPy1DArray &&rhs) |
| Move assignment of a full vector (RHS-vector) to the current vector (LHS-vector). More... | |
| NumPy1DArray & | operator= (PyObject *rhs) |
| Assign a NumPy array (RHS-vector) to the current vector (LHS-vector). More... | |
| template<class val_T > | |
| NumPy1DArray & | operator= (const val_T &val) |
| Assignment from a value. More... | |
| template<class C > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | operator= (const vector_container< C > &rhs) |
| Assign a full vector (RHS-vector) to the current vector (LHS-vector). More... | |
| template<class AE > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | operator= (const vector_expression< AE > &ae) |
| Assign the result of a vector_expression to the vector. More... | |
| template<class AE > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | operator+= (const vector_expression< AE > &ae) |
| Assign the sum of the vector and a vector_expression to the vector. More... | |
| template<class C > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | operator+= (const vector_container< C > &v) |
| Assign the sum of the vector and a vector_container to the vector. More... | |
| template<class AE > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | plus_assign (const vector_expression< AE > &ae) |
| Assign the sum of the vector and a vector_expression to the vector. More... | |
| template<class AE > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | operator-= (const vector_expression< AE > &ae) |
| Assign the difference of the vector and a vector_expression to the vector. More... | |
| template<class C > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | operator-= (const vector_container< C > &v) |
| Assign the difference of the vector and a vector_container to the vector. More... | |
| template<class AE > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | minus_assign (const vector_expression< AE > &ae) |
| Assign the difference of the vector and a vector_expression to the vector. More... | |
| template<class AT > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | operator*= (const AT &at) |
| Assign the product of the vector and a scalar to the vector. More... | |
| template<class AT > | |
| BOOST_UBLAS_INLINE NumPy1DArray & | operator/= (const AT &at) |
| Assign the division of the vector by a scalar to the vector. More... | |
| BOOST_UBLAS_INLINE void | swap (NumPy1DArray &rhs) |
| Swap the content of the vector with another vector. More... | |
| BOOST_UBLAS_INLINE const_iterator | find (size_type i) const |
| Return a const iterator to the element i. More... | |
| BOOST_UBLAS_INLINE iterator | find (size_type i) |
| Return an iterator to the element i. More... | |
| BOOST_UBLAS_INLINE const_iterator | begin () const |
| return an iterator on the first element of the vector | |
| BOOST_UBLAS_INLINE const_iterator | end () const |
| return an iterator after the last element of the vector | |
| BOOST_UBLAS_INLINE iterator | begin () |
| Return an iterator on the first element of the vector. | |
| BOOST_UBLAS_INLINE iterator | end () |
| Return an iterator at the end of the vector. | |
| BOOST_UBLAS_INLINE const_reverse_iterator | rbegin () const |
| Return a const reverse iterator before the first element of the reversed vector (i.e. end() of normal vector) | |
| BOOST_UBLAS_INLINE const_reverse_iterator | rend () const |
| Return a const reverse iterator on the end of the reverse vector (i.e. first element of the normal vector) | |
| BOOST_UBLAS_INLINE reverse_iterator | rbegin () |
| Return a const reverse iterator before the first element of the reversed vector (i.e. end() of normal vector) | |
| BOOST_UBLAS_INLINE reverse_iterator | rend () |
| Return a const reverse iterator on the end of the reverse vector (i.e. first element of the normal vector) | |
Public Member Functions inherited from mds_utils::python::Obj | |
| Obj () | |
| Default constructor. | |
| Obj (const Obj &rhs) | |
| The copy-constructor. More... | |
| Obj (Obj &&rhs) | |
| Move constructor. More... | |
| Obj (ProxyAttr &&rhs) | |
| Move constructor from ProxyAttr objects. More... | |
| Obj (PyObject *po) | |
| Construct from a Python object. More... | |
| Obj & | operator= (const Obj &rhs) |
| Standard assignment. | |
| Obj & | operator= (Obj &&rhs) |
| Move assignment. | |
| template<class T > | |
| Obj & | operator= (const T &val) |
| Assignment from a value. More... | |
| virtual | ~Obj () |
| Destructor. | |
| PyObject * | getPyObject () const |
| Returns the underlying PyObject. More... | |
| operator PyObject * () const | |
| Automatic type conversion towards a Python object. More... | |
| void | reset () |
| Resets the object to the state given by the default constructor. | |
| void | get_ownership () |
| Used in place of incref, when the wrapped PyObject* was increfed already. | |
| bool | has_attr (const std::string &name) const |
| Tests if the object has a particular attribute. | |
| ProxyAttr | attr (const std::string &name) |
| Retrieves an attribute. More... | |
| bool | is_callable () const |
| Checks if the object is callable. More... | |
| Obj | operator() () |
| Calling operator. More... | |
| Obj | operator() (const Obj &args) |
| Calling operator, with positional arguments. More... | |
| Obj | operator() (const Obj &args, const Obj &kw) |
| Calling operator, with positional and keyword arguments. More... | |
Friends | |
| BOOST_UBLAS_INLINE friend void | swap (NumPy1DArray &v1, NumPy1DArray &v2) |
| Swap the content of two vectors. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from mds_utils::python::Obj | |
| void | check_callable () |
| Checks if the object is callable. More... | |
| void | check_call_result (PyObject *result) |
| Checks if the result of the object call was successful. More... | |
Protected Attributes inherited from mds_utils::python::Obj | |
| size_t | decref_on_destroy |
| PyObject * | m_po |
| Underlying pointer to the wrapped Python object. | |
Wrapper class for NumPy 1D arrays.
It allows to use uBLAS with NumPy 1D arrays. Thanks to automatic type conversions, it can be directly used also with the NumPy C API.
Definition at line 55 of file numpy_array.hpp.
|
inline |
|
inlineexplicit |
Constructor of a vector with a predefined size.
By default, its elements are randomly initialized.
| n | The size of the vector. |
Definition at line 145 of file numpy_array.hpp.
References mds_utils::python::Obj::get_ownership().
|
inline |
Constructor of a vector by copying from another container.
| b | Start iterator for the source container. |
| e | Past-the-end iterator for the source container. |
Definition at line 164 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::getPyArrayObject().
|
inlineexplicit |
Constructor of a vector with a unique initial value.
| n | The size. |
| init | The initialization value. |
Definition at line 183 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::getPyArrayObject().
|
inline |
Copy-constructor.
Creates a new vector and physically copies the rhs elements into it.
| rhs | The vector to be copied. |
Definition at line 220 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::getPyArrayObject().
|
inline |
Move constructor.
Creates a new vector from an rvalue reference.
| rhs | The vector to be copied. |
Definition at line 238 of file numpy_array.hpp.
|
inline |
Copy-constructor of a NumPy1DArray from a vector_expression.
Depending on the vector_expression, this constructor can have the cost of the computations of the expression (trivial to say it, but it is to take into account in your complexity calculations).
| ae | The vector_expression which values will be duplicated into the vector. |
Definition at line 254 of file numpy_array.hpp.
|
inlineexplicit |
Constructor from PyObject.
It wraps around a PyObject, without duplicating it. Simply takes the reference to the rhs vector and increfs it.
| rhs | The PyObject vector to use. |
Definition at line 271 of file numpy_array.hpp.
References mds_utils::python::Obj::getPyObject(), boost::numeric::ublas::NumPy1DArray< T >::incref(), and boost::numeric::ublas::NumPy1DArray< T >::size().
|
inline |
Assign the result of a vector_expression to the vector.
This is lazy-compiled and will be optimized out by the compiler on any type of expression.
| AE | The type of the vector_expression |
| ae | A const reference to the vector_expression |
Definition at line 427 of file numpy_array.hpp.
Referenced by boost::numeric::ublas::NumPy1DArray< T >::operator=().
|
inline |
Assign a full vector (RHS-vector) to the current vector (LHS-vector).
| rhs | The source vector. |
Definition at line 443 of file numpy_array.hpp.
References mds_utils::python::Obj::getPyObject(), and boost::numeric::ublas::NumPy1DArray< T >::incref().
Referenced by boost::numeric::ublas::NumPy1DArray< T >::operator+=(), boost::numeric::ublas::NumPy1DArray< T >::operator-=(), and boost::numeric::ublas::NumPy1DArray< T >::operator=().
|
inline |
Clear the vector, i.e. set all values to the zero value.
Definition at line 398 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::getPyArrayObject().
|
inline |
Return a const iterator to the element i.
| i | Index of the element. |
Definition at line 848 of file numpy_array.hpp.
Referenced by boost::numeric::ublas::NumPy1DArray< T >::begin(), and boost::numeric::ublas::NumPy1DArray< T >::end().
|
inline |
Return an iterator to the element i.
| i | Index of the element. |
Definition at line 861 of file numpy_array.hpp.
|
inline |
Return a pointer to the element
.
| i | Index of the element. |
Definition at line 306 of file numpy_array.hpp.
|
inline |
Return a const pointer to the element
.
| i | Index of the element. |
Definition at line 320 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::getPyArrayObject().
|
inlinevirtual |
Increments the reference count using Py_XINCREF.
Reimplemented from mds_utils::python::Obj.
Definition at line 93 of file numpy_array.hpp.
References mds_utils::python::Obj::decref_on_destroy, and mds_utils::python::Obj::getPyObject().
Referenced by boost::numeric::ublas::NumPy1DArray< T >::assign_temporary(), and boost::numeric::ublas::NumPy1DArray< T >::NumPy1DArray().
|
inline |
Assign the difference of the vector and a vector_expression to the vector.
This is lazy-compiled and will be optimized out by the compiler on any type of expression. No temporary is created. Computations are done and stored directly into the resulting vector.
| AE | The type of the vector_expression |
| ae | A const reference to the vector_expression |
Definition at line 723 of file numpy_array.hpp.
Referenced by boost::numeric::ublas::NumPy1DArray< T >::operator-=().
|
inline |
Return a const reference to the element
.
| i | Index of the element. |
Definition at line 339 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::getPyArrayObject().
|
inline |
Return a reference to the element
.
| i | Index of the element. |
Definition at line 354 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::getPyArrayObject().
|
inline |
Assign the product of the vector and a scalar to the vector.
This is lazy-compiled and will be optimized out by the compiler on any type of expression. No temporary is created. Computations are done and stored directly into the resulting vector.
| AT | The type of the scalar |
| at | A const reference to the scalar |
Definition at line 745 of file numpy_array.hpp.
|
inline |
Assign the sum of the vector and a vector_expression to the vector.
This is lazy-compiled and will be optimized out by the compiler on any type of expression. A temporary is created for the computations.
| AE | The type of the vector_expression |
| ae | A const reference to the vector_expression |
Definition at line 616 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::assign_temporary().
|
inline |
Assign the sum of the vector and a vector_container to the vector.
This is lazy-compiled and will be optimized out by the compiler on any type of expression. No temporary is created. Computations are done and stored directly into the resulting vector.
| AE | The type of the vector_expression |
| v | A const reference to a vector_container |
Definition at line 637 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::plus_assign().
|
inline |
Assign the difference of the vector and a vector_expression to the vector.
This is lazy-compiled and will be optimized out by the compiler on any type of expression. A temporary is created for the computations.
| AE | The type of the vector_expression |
| ae | A const reference to the vector_expression |
Definition at line 679 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::assign_temporary().
|
inline |
Assign the difference of the vector and a vector_container to the vector.
This is lazy-compiled and will be optimized out by the compiler on any type of expression. No temporary is created. Computations are done and stored directly into the resulting vector.
| AE | The type of the vector_expression |
| v | A const reference to a vector_container |
Definition at line 701 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::minus_assign().
|
inline |
Assign the division of the vector by a scalar to the vector.
This is lazy-compiled and will be optimized out by the compiler on any type of expression. No temporary is created. Computations are done and stored directly into the resulting vector.
| AT | The type of the scalar |
| at | A const reference to the scalar |
Definition at line 767 of file numpy_array.hpp.
|
inline |
Assign a full vector (RHS-vector) to the current vector (LHS-vector).
This method physically copies the rhs elements into the current object.
| rhs | The source vector. |
Definition at line 463 of file numpy_array.hpp.
References mds_utils::python::Obj::get_ownership(), boost::numeric::ublas::NumPy1DArray< T >::getPyArrayObject(), mds_utils::python::Obj::m_po, mds_utils::python::Obj::reset(), and boost::numeric::ublas::NumPy1DArray< T >::size().
|
inline |
Move assignment of a full vector (RHS-vector) to the current vector (LHS-vector).
| rhs | The source vector. |
Definition at line 495 of file numpy_array.hpp.
References mds_utils::python::Obj::operator=().
|
inlinevirtual |
Assign a NumPy array (RHS-vector) to the current vector (LHS-vector).
This method only takes the reference to the rhs object and it does not incref it.
| rhs | The source NumPy array. |
Reimplemented from mds_utils::python::Obj.
Definition at line 515 of file numpy_array.hpp.
References mds_utils::python::Obj::getPyObject(), and mds_utils::python::Obj::operator=().
|
inline |
Assignment from a value.
Sets all the elements of the array to the passed value.
| val | The value to assign. |
Definition at line 540 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::begin(), boost::numeric::ublas::NumPy1DArray< T >::end(), and boost::numeric::ublas::NumPy1DArray< T >::size().
|
inline |
Assign a full vector (RHS-vector) to the current vector (LHS-vector).
It physically copies the elements.
| v | The source vector container. |
Definition at line 566 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::assign(), and boost::numeric::ublas::NumPy1DArray< T >::size().
|
inline |
Assign the result of a vector_expression to the vector.
This is lazy-compiled and will be optimized out by the compiler on any type of expression.
| AE | The type of the vector_expression. |
| ae | A const reference to the vector_expression. |
Definition at line 590 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::assign_temporary().
|
inline |
Return a const reference to the element
.
| i | Index of the element. |
Definition at line 369 of file numpy_array.hpp.
|
inline |
Return a reference to the element
.
| i | Index of the element. |
Definition at line 383 of file numpy_array.hpp.
|
inline |
Assign the sum of the vector and a vector_expression to the vector.
This is lazy-compiled and will be optimized out by the compiler on any type of expression. No temporary is created. Computations are done and stored directly into the resulting vector.
| AE | The type of the vector_expression |
| ae | A const reference to the vector_expression |
Definition at line 659 of file numpy_array.hpp.
Referenced by boost::numeric::ublas::NumPy1DArray< T >::operator+=().
|
inline |
Return the size of the vector.
Definition at line 202 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::getPyArrayObject().
Referenced by boost::numeric::ublas::NumPy1DArray< T >::end(), boost::numeric::ublas::NumPy1DArray< T >::NumPy1DArray(), and boost::numeric::ublas::NumPy1DArray< T >::operator=().
|
inline |
Swap the content of the vector with another vector.
| rhs | The vector to be swapped with. |
Definition at line 786 of file numpy_array.hpp.
References boost::numeric::ublas::NumPy1DArray< T >::getPyArrayObject().
|
inlinevirtual |
Returns the Python object with transferred ownership.
Reimplemented from mds_utils::python::Obj.
Definition at line 114 of file numpy_array.hpp.
References mds_utils::python::Obj::getPyObject(), and mds_utils::python::Obj::reset().
|
friend |
Swap the content of two vectors.
| v1 | The first vector. It takes values from v2. |
| v2 | The second vector. It takes values from v1. |
Definition at line 815 of file numpy_array.hpp.