HepMC3 event record library
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions
array_t< T, ExtraFlags > Class Template Reference
+ Inheritance diagram for array_t< T, ExtraFlags >:
+ Collaboration diagram for array_t< T, ExtraFlags >:

Data Structures

struct  private_ctor
 

Public Types

using value_type = T
 
enum  { c_style = detail::npy_api::NPY_ARRAY_C_CONTIGUOUS_, f_style = detail::npy_api::NPY_ARRAY_F_CONTIGUOUS_, forcecast = detail::npy_api::NPY_ARRAY_FORCECAST_ }
 
using ShapeContainer = detail::any_container< ssize_t >
 
using StridesContainer = detail::any_container< ssize_t >
 

Public Member Functions

 array_t (handle h, borrowed_t)
 
 array_t (handle h, stolen_t)
 
 array_t (handle h, bool is_borrowed)
 
 array_t (const object &o)
 
 array_t (const buffer_info &info, handle base=handle())
 
 array_t (ShapeContainer shape, StridesContainer strides, const T *ptr=nullptr, handle base=handle())
 
 array_t (ShapeContainer shape, const T *ptr=nullptr, handle base=handle())
 
 array_t (ssize_t count, const T *ptr=nullptr, handle base=handle())
 
constexpr ssize_t itemsize () const
 
template<typename... Ix>
ssize_t index_at (Ix... index) const
 
template<typename... Ix>
const T * data (Ix... index) const
 
template<typename... Ix>
T * mutable_data (Ix... index)
 
template<typename... Ix>
const T & at (Ix... index) const
 
template<typename... Ix>
T & mutable_at (Ix... index)
 
template<ssize_t Dims = -1>
detail::unchecked_mutable_reference< T, Dims > mutable_unchecked () &
 
template<ssize_t Dims = -1>
detail::unchecked_reference< T, Dims > unchecked () const &
 
pybind11::dtype dtype () const
 Array descriptor (dtype) More...
 
ssize_t size () const
 Total number of elements. More...
 
ssize_t nbytes () const
 Total number of bytes. More...
 
ssize_t ndim () const
 Number of dimensions. More...
 
object base () const
 Base object. More...
 
const ssize_t * shape () const
 Dimensions of the array. More...
 
ssize_t shape (ssize_t dim) const
 Dimension along a given axis. More...
 
const ssize_t * strides () const
 Strides of the array. More...
 
ssize_t strides (ssize_t dim) const
 Stride along a given axis. More...
 
int flags () const
 Return the NumPy array flags. More...
 
bool writeable () const
 If set, the array is writeable (otherwise the buffer is read-only) More...
 
bool owndata () const
 If set, the array owns the data (will be freed when the array is deleted) More...
 
template<typename... Ix>
ssize_t offset_at (Ix... index) const
 
ssize_t offset_at () const
 
array squeeze ()
 Return a new view with all of the dimensions of length 1 removed. More...
 
void resize (ShapeContainer new_shape, bool refcheck=true)
 
buffer_info request (bool writable=false) const
 
 PYBIND11_DEPRECATED ("Use reinterpret_borrow<object>() or reinterpret_steal<object>()") object(handle h
 
handle release ()
 
template<typename T >
cast () const &
 
template<typename T >
cast () &&
 
template<typename T >
cast () const &
 
template<typename T >
cast () &&
 
template<>
void cast () const &
 
template<>
void cast () &&
 
template<typename T >
cast () const
 
PyObject * ptr () const
 Return the underlying PyObject * pointer. More...
 
PyObject *& ptr ()
 
const handleinc_ref () const &
 
const handledec_ref () const &
 
 operator bool () const
 Return true when the handle wraps a valid Python object. More...
 
bool operator== (const handle &h) const
 
bool operator!= (const handle &h) const
 
bool check () const
 

Static Public Member Functions

static array_t ensure (handle h)
 
static bool check_ (handle h)
 
static array ensure (handle h, int ExtraFlags=0)
 

Data Fields

bool is_borrowed: handle(h) { if (is_borrowed) inc_ref()
 

Protected Member Functions

void fail_dim_check (ssize_t dim, const std::string &msg) const
 
template<typename... Ix>
ssize_t byte_offset (Ix... index) const
 
void check_writeable () const
 
template<typename... Ix>
void check_dimensions (Ix... index) const
 
void check_dimensions_impl (ssize_t, const ssize_t *) const
 
template<typename... Ix>
void check_dimensions_impl (ssize_t axis, const ssize_t *shape, ssize_t i, Ix... index) const
 

Static Protected Member Functions

static PyObject * raw_array_t (PyObject *ptr)
 Create array from any object – always returns a new reference. More...
 
static PyObject * raw_array (PyObject *ptr, int ExtraFlags=0)
 Create array from any object – always returns a new reference. More...
 

Protected Attributes

PyObject * m_ptr = nullptr
 

Private Member Functions

 array_t (private_ctor, ShapeContainer &&shape, StridesContainer &&strides, const T *ptr, handle base)
 

Detailed Description

template<typename T, int ExtraFlags = array::forcecast>
class array_t< T, ExtraFlags >

Definition at line 835 of file numpy.h.

Member Function Documentation

◆ base()

object base ( ) const
inlineinherited

Base object.

Definition at line 659 of file numpy.h.

◆ cast()

T cast
inherited

\rst Attempt to cast the Python object into the given C++ type. A cast_error will be throw upon failure. \endrst

Definition at line 1743 of file cast.h.

◆ dec_ref()

const handle& dec_ref ( ) const &
inlineinherited

\rst Manually decrease the reference count of the Python object. Usually, it is preferable to use the object class which derives from handle and calls this function automatically. Returns a reference to itself. \endrst

Definition at line 199 of file pytypes.h.

◆ dtype()

pybind11::dtype dtype ( ) const
inlineinherited

Array descriptor (dtype)

Definition at line 634 of file numpy.h.

◆ ensure() [1/2]

static array_t ensure ( handle  h)
inlinestatic

Ensure that the argument is a NumPy array of the correct dtype (and if not, try to convert it). In case of an error, nullptr is returned and the Python error is cleared.

Definition at line 928 of file numpy.h.

◆ ensure() [2/2]

static array ensure ( handle  h,
int  ExtraFlags = 0 
)
inlinestaticinherited

Ensure that the argument is a NumPy array In case of an error, nullptr is returned and the Python error is cleared.

Definition at line 784 of file numpy.h.

References handle::ptr(), and array::raw_array().

◆ flags()

int flags ( ) const
inlineinherited

Return the NumPy array flags.

Definition at line 688 of file numpy.h.

◆ inc_ref()

const handle& inc_ref ( ) const &
inlineinherited

\rst Manually increase the reference count of the Python object. Usually, it is preferable to use the object class which derives from handle and calls this function automatically. Returns a reference to itself. \endrst

Definition at line 192 of file pytypes.h.

◆ mutable_unchecked()

detail::unchecked_mutable_reference<T, Dims> mutable_unchecked ( ) &
inline

Returns a proxy object that provides access to the array's data without bounds or dimensionality checking. Will throw if the array is missing the writeable flag. Use with care: the array must not be destroyed or reshaped for the duration of the returned object, and the caller must take care not to access invalid dimensions or dimension indices.

Definition at line 911 of file numpy.h.

◆ nbytes()

ssize_t nbytes ( ) const
inlineinherited

Total number of bytes.

Definition at line 649 of file numpy.h.

References array::itemsize(), and array::size().

◆ ndim()

ssize_t ndim ( ) const
inlineinherited

Number of dimensions.

Definition at line 654 of file numpy.h.

◆ offset_at()

ssize_t offset_at ( Ix...  index) const
inlineinherited

Byte offset from beginning of the array to a given index (full or partial). May throw if the index would lead to out of bounds access.

Definition at line 718 of file numpy.h.

References array::ndim().

◆ operator bool()

operator bool ( ) const
inlineexplicitinherited

Return true when the handle wraps a valid Python object.

Definition at line 207 of file pytypes.h.

◆ operator==()

bool operator== ( const handle h) const
inlineinherited

\rst Deprecated: Check that the underlying pointers are the same. Equivalent to obj1 is obj2 in Python. \endrst

Definition at line 213 of file pytypes.h.

◆ owndata()

bool owndata ( ) const
inlineinherited

If set, the array owns the data (will be freed when the array is deleted)

Definition at line 698 of file numpy.h.

◆ ptr()

PyObject* ptr ( ) const
inlineinherited

Return the underlying PyObject * pointer.

Definition at line 184 of file pytypes.h.

◆ raw_array()

static PyObject* raw_array ( PyObject *  ptr,
int  ExtraFlags = 0 
)
inlinestaticprotectedinherited

Create array from any object – always returns a new reference.

Definition at line 825 of file numpy.h.

References handle::ptr().

◆ raw_array_t()

static PyObject* raw_array_t ( PyObject *  ptr)
inlinestaticprotected

Create array from any object – always returns a new reference.

Definition at line 944 of file numpy.h.

◆ release()

handle release ( )
inlineinherited

\rst Resets the internal pointer to nullptr without decreasing the object's reference count. The function returns a raw handle to the original Python object. \endrst

Definition at line 249 of file pytypes.h.

References handle::handle().

◆ resize()

void resize ( ShapeContainer  new_shape,
bool  refcheck = true 
)
inlineinherited

Resize array to given shape If refcheck is true and more that one reference exist to this array then resize will succeed only if it makes a reshape, i.e. original size doesn't change

Definition at line 768 of file numpy.h.

◆ shape() [1/2]

const ssize_t* shape ( ) const
inlineinherited

Dimensions of the array.

Definition at line 664 of file numpy.h.

◆ shape() [2/2]

ssize_t shape ( ssize_t  dim) const
inlineinherited

Dimension along a given axis.

Definition at line 669 of file numpy.h.

References array::ndim(), and array::shape().

◆ size()

ssize_t size ( ) const
inlineinherited

Total number of elements.

Definition at line 639 of file numpy.h.

References array::ndim(), and array::shape().

◆ squeeze()

array squeeze ( )
inlineinherited

Return a new view with all of the dimensions of length 1 removed.

Definition at line 760 of file numpy.h.

◆ strides() [1/2]

const ssize_t* strides ( ) const
inlineinherited

Strides of the array.

Definition at line 676 of file numpy.h.

◆ strides() [2/2]

ssize_t strides ( ssize_t  dim) const
inlineinherited

Stride along a given axis.

Definition at line 681 of file numpy.h.

References array::ndim(), and array::strides().

◆ unchecked()

detail::unchecked_reference<T, Dims> unchecked ( ) const &
inline

Returns a proxy object that provides const access to the array's data without bounds or dimensionality checking. Unlike unchecked(), this does not require that the underlying array have the writable flag. Use with care: the array must not be destroyed or reshaped for the duration of the returned object, and the caller must take care not to access invalid dimensions or dimension indices.

Definition at line 922 of file numpy.h.

◆ writeable()

bool writeable ( ) const
inlineinherited

If set, the array is writeable (otherwise the buffer is read-only)

Definition at line 693 of file numpy.h.


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