Scarab  v2.11.1
Project 8 C++ Utility Library
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
array Class Reference

#include <numpy.h>

Inheritance diagram for array:
Inheritance graph

Public Types

using ShapeContainer = detail::any_container< ssize_t >
 
using StridesContainer = detail::any_container< ssize_t >
 

Public Member Functions

 __attribute__ ((deprecated("Use reinterpret_borrow<""array"">() or reinterpret_steal<""array"">()"))) array(handle h
 
 array ()
 
 array (const pybind11::dtype &dt, ShapeContainer shape, StridesContainer strides, const void *ptr=nullptr, handle base=handle())
 
 array (const pybind11::dtype &dt, ShapeContainer shape, const void *ptr=nullptr, handle base=handle())
 
template<typename T , typename = detail::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>>
 array (const pybind11::dtype &dt, T count, const void *ptr=nullptr, handle base=handle())
 
template<typename T >
 array (ShapeContainer shape, StridesContainer strides, const T *ptr, handle base=handle())
 
template<typename T >
 array (ShapeContainer shape, const T *ptr, handle base=handle())
 
template<typename T >
 array (ssize_t count, const T *ptr, handle base=handle())
 
 array (const buffer_info &info)
 
pybind11::dtype dtype () const
 Array descriptor (dtype) More...
 
ssize_t size () const
 Total number of elements. More...
 
ssize_t itemsize () const
 Byte size of a single element. 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_tshape () const
 Dimensions of the array. More...
 
ssize_t shape (ssize_t dim) const
 Dimension along a given axis. More...
 
const ssize_tstrides () 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>
const void * data (Ix... index) const
 
template<typename... Ix>
void * mutable_data (Ix... index)
 
template<typename... Ix>
ssize_t offset_at (Ix... index) const
 
ssize_t offset_at () const
 
template<typename... Ix>
ssize_t index_at (Ix... index) const
 
template<typename T , ssize_t Dims = -1>
detail::unchecked_mutable_reference< T, Dims > mutable_unchecked () &
 
template<typename T , ssize_t Dims = -1>
detail::unchecked_reference< T, Dims > unchecked () 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)
 
- Public Member Functions inherited from buffer
 __attribute__ ((deprecated("Use reinterpret_borrow<""buffer"">() or reinterpret_steal<""buffer"">()"))) buffer(handle h
 
- Public Member Functions inherited from object
 object ()=default
 
 __attribute__ ((deprecated("Use reinterpret_borrow<object>() or reinterpret_steal<object>()"))) object(handle h
 
 object (const object &o)
 Copy constructor; always increases the reference count. More...
 
 object (object &&other) noexcept
 Move constructor; steals the object from other and preserves its reference count. More...
 
 ~object ()
 Destructor; automatically calls handle::dec_ref() More...
 
handle release ()
 
objectoperator= (const object &other)
 
objectoperator= (object &&other) noexcept
 
template<typename T >
cast () const &
 
template<typename T >
cast () &&
 
 object (handle h, borrowed_t)
 
 object (handle h, stolen_t)
 
template<typename T >
cast () const &
 
template<typename T >
cast () &&
 
template<>
void cast () const &
 
template<>
void cast () &&
 
- Public Member Functions inherited from handle
 handle ()=default
 The default constructor creates a handle with a nullptr-valued pointer. More...
 
 handle (PyObject *ptr)
 Creates a handle from the given raw Python object pointer. More...
 
PyObject * ptr () const
 Return the underlying PyObject * pointer. More...
 
PyObject *& ptr ()
 
const handleinc_ref () const &
 
const handledec_ref () const &
 
template<typename T >
cast () const
 
 operator bool () const
 Return true when the handle wraps a valid Python object. More...
 
 __attribute__ ((deprecated("Use obj1.is(obj2) instead"))) bool operator
 
template<>
void cast () const
 
- Public Member Functions inherited from object_api< handle >
iterator begin () const
 
iterator end () const
 Return a sentinel which ends iteration. More...
 
item_accessor operator[] (handle key) const
 
item_accessor operator[] (const char *key) const
 See above (the only difference is that they key is provided as a string literal) More...
 
obj_attr_accessor attr (handle key) const
 
str_attr_accessor attr (const char *key) const
 See above (the only difference is that they key is provided as a string literal) More...
 
args_proxy operator* () const
 
object operator* (object_api const &other) const
 
bool contains (T &&item) const
 Check if the given item is contained within this object, i.e. item in obj. More...
 
object operator() (Args &&...args) const
 
 __attribute__ ((deprecated("call(...) was deprecated in favor of operator()(...)"))) object call(Args &&... args) const
 Get or set the object's docstring, i.e. obj.__doc__. More...
 
bool is (object_api const &other) const
 Equivalent to obj is other in Python. More...
 
bool is_none () const
 Equivalent to obj is None in Python. More...
 
bool equal (object_api const &other) const
 Equivalent to obj == other in Python. More...
 
bool not_equal (object_api const &other) const
 
bool operator< (object_api const &other) const
 
bool operator<= (object_api const &other) const
 
bool operator> (object_api const &other) const
 
bool operator>= (object_api const &other) const
 
object operator- () const
 
object operator- (object_api const &other) const
 
object operator~ () const
 
object operator+ (object_api const &other) const
 
object operator+= (object_api const &other) const
 
object operator-= (object_api const &other) const
 
object operator*= (object_api const &other) const
 
object operator/ (object_api const &other) const
 
object operator/= (object_api const &other) const
 
object operator| (object_api const &other) const
 
object operator|= (object_api const &other) const
 
object operator& (object_api const &other) const
 
object operator&= (object_api const &other) const
 
object operator^ (object_api const &other) const
 
object operator^= (object_api const &other) const
 
object operator<< (object_api const &other) const
 
object operator<<= (object_api const &other) const
 
object operator>> (object_api const &other) const
 
object operator>>= (object_api const &other) const
 
int ref_count () const
 Return the object's current reference count. More...
 
handle get_type () const
 Return a handle to the Python type object underlying the instance. More...
 

Static Public Member Functions

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

Public Attributes

bool is_borrowed: buffer (is_borrowed ? buffer (h
 
bool borrowed_t
 
- Public Attributes inherited from buffer
bool is_borrowed: object (is_borrowed ? object (h
 
- Public Attributes inherited from object
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 std::vector< ssize_tc_strides (const std::vector< ssize_t > &shape, ssize_t itemsize)
 
static std::vector< ssize_tf_strides (const std::vector< ssize_t > &shape, ssize_t itemsize)
 
static PyObject * raw_array (PyObject *ptr, int ExtraFlags=0)
 Create array from any object – always returns a new reference. More...
 

Friends

template<typename , typename >
struct detail::npy_format_descriptor
 

Detailed Description

Definition at line 538 of file numpy.h.

Member Typedef Documentation

◆ ShapeContainer

Definition at line 550 of file numpy.h.

◆ StridesContainer

Definition at line 551 of file numpy.h.

Constructor & Destructor Documentation

◆ array() [1/8]

array ( )
inline

Definition at line 548 of file numpy.h.

◆ array() [2/8]

array ( const pybind11::dtype dt,
ShapeContainer  shape,
StridesContainer  strides,
const void *  ptr = nullptr,
handle  base = handle() 
)
inline

Definition at line 554 of file numpy.h.

◆ array() [3/8]

array ( const pybind11::dtype dt,
ShapeContainer  shape,
const void *  ptr = nullptr,
handle  base = handle() 
)
inline

Definition at line 591 of file numpy.h.

◆ array() [4/8]

array ( const pybind11::dtype dt,
count,
const void *  ptr = nullptr,
handle  base = handle() 
)
inline

Definition at line 595 of file numpy.h.

◆ array() [5/8]

array ( ShapeContainer  shape,
StridesContainer  strides,
const T *  ptr,
handle  base = handle() 
)
inline

Definition at line 599 of file numpy.h.

◆ array() [6/8]

array ( ShapeContainer  shape,
const T *  ptr,
handle  base = handle() 
)
inline

Definition at line 603 of file numpy.h.

◆ array() [7/8]

array ( ssize_t  count,
const T *  ptr,
handle  base = handle() 
)
inlineexplicit

Definition at line 607 of file numpy.h.

◆ array() [8/8]

array ( const buffer_info info)
inlineexplicit

Definition at line 609 of file numpy.h.

Member Function Documentation

◆ __attribute__()

__attribute__ ( (deprecated("Use reinterpret_borrow<""array"">() or reinterpret_steal<""array"">()"))  )

◆ base()

object base ( ) const
inline

Base object.

Definition at line 638 of file numpy.h.

◆ byte_offset()

ssize_t byte_offset ( Ix...  index) const
inlineprotected

Definition at line 776 of file numpy.h.

◆ c_strides()

static std::vector<ssize_t> c_strides ( const std::vector< ssize_t > &  shape,
ssize_t  itemsize 
)
inlinestaticprotected

Definition at line 787 of file numpy.h.

◆ check_dimensions()

void check_dimensions ( Ix...  index) const
inlineprotected

Definition at line 805 of file numpy.h.

◆ check_dimensions_impl() [1/2]

void check_dimensions_impl ( ssize_t  ,
const ssize_t  
) const
inlineprotected

Definition at line 809 of file numpy.h.

◆ check_dimensions_impl() [2/2]

void check_dimensions_impl ( ssize_t  axis,
const ssize_t shape,
ssize_t  i,
Ix...  index 
) const
inlineprotected

Definition at line 811 of file numpy.h.

◆ check_writeable()

void check_writeable ( ) const
inlineprotected

Definition at line 781 of file numpy.h.

◆ data()

const void* data ( Ix...  index) const
inline

Pointer to the contained data. If index is not provided, points to the beginning of the buffer. May throw if the index would lead to out of bounds access.

Definition at line 683 of file numpy.h.

◆ dtype()

pybind11::dtype dtype ( ) const
inline

Array descriptor (dtype)

Definition at line 613 of file numpy.h.

◆ ensure()

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

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 761 of file numpy.h.

◆ f_strides()

static std::vector<ssize_t> f_strides ( const std::vector< ssize_t > &  shape,
ssize_t  itemsize 
)
inlinestaticprotected

Definition at line 797 of file numpy.h.

◆ fail_dim_check()

void fail_dim_check ( ssize_t  dim,
const std::string &  msg 
) const
inlineprotected

Definition at line 771 of file numpy.h.

◆ flags()

int flags ( ) const
inline

Return the NumPy array flags.

Definition at line 667 of file numpy.h.

◆ index_at()

ssize_t index_at ( Ix...  index) const
inline

Item count 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 707 of file numpy.h.

◆ itemsize()

ssize_t itemsize ( ) const
inline

Byte size of a single element.

Definition at line 623 of file numpy.h.

◆ mutable_data()

void* mutable_data ( Ix...  index)
inline

Mutable pointer to the contained data. If index is not provided, points to the beginning of the buffer. May throw if the index would lead to out of bounds access. May throw if the array is not writeable.

Definition at line 690 of file numpy.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 717 of file numpy.h.

◆ nbytes()

ssize_t nbytes ( ) const
inline

Total number of bytes.

Definition at line 628 of file numpy.h.

◆ ndim()

ssize_t ndim ( ) const
inline

Number of dimensions.

Definition at line 633 of file numpy.h.

◆ offset_at() [1/2]

ssize_t offset_at ( Ix...  index) const
inline

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 697 of file numpy.h.

◆ offset_at() [2/2]

ssize_t offset_at ( ) const
inline

Definition at line 703 of file numpy.h.

◆ owndata()

bool owndata ( ) const
inline

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

Definition at line 677 of file numpy.h.

◆ raw_array()

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

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

Definition at line 821 of file numpy.h.

◆ resize()

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

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 747 of file numpy.h.

◆ shape() [1/2]

const ssize_t* shape ( ) const
inline

Dimensions of the array.

Definition at line 643 of file numpy.h.

◆ shape() [2/2]

ssize_t shape ( ssize_t  dim) const
inline

Dimension along a given axis.

Definition at line 648 of file numpy.h.

◆ size()

ssize_t size ( ) const
inline

Total number of elements.

Definition at line 618 of file numpy.h.

◆ squeeze()

array squeeze ( )
inline

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

Definition at line 739 of file numpy.h.

◆ strides() [1/2]

const ssize_t* strides ( ) const
inline

Strides of the array.

Definition at line 655 of file numpy.h.

◆ strides() [2/2]

ssize_t strides ( ssize_t  dim) const
inline

Stride along a given axis.

Definition at line 660 of file numpy.h.

◆ 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 mutable_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 731 of file numpy.h.

◆ writeable()

bool writeable ( ) const
inline

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

Definition at line 672 of file numpy.h.

Friends And Related Function Documentation

◆ detail::npy_format_descriptor

friend struct detail::npy_format_descriptor
friend

Definition at line 769 of file numpy.h.

Member Data Documentation

◆ borrowed_t

bool borrowed_t
Initial value:
{}) : buffer (h, stolen_t{})) { } array (handle h, borrowed_t) : buffer (h, borrowed_t{}) { } array (handle h, stolen_t) : buffer (h, stolen_t{}) { } PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") bool check() const { return m_ptr != nullptr && (bool) detail::npy_api::get().PyArray_Check_ (m_ptr); } static bool check_(handle h) { return h.ptr() != nullptr && detail::npy_api::get().PyArray_Check_ (h.ptr()); } array (const object &o) : buffer (check_(o) ? o.inc_ref().ptr() : raw_array (o.ptr()), stolen_t{}) { if (!m_ptr) throw error_already_set(); } array (object &&o) : buffer (check_(o) ? o.release().ptr() : raw_array (o.ptr()), stolen_t{}) { if (!m_ptr) throw error_already_set(); } template <typename Policy_> array (const ::pybind11::detail::accessor<Policy_> &a) : array (object(a)) { }
enum {
}

Definition at line 540 of file numpy.h.

◆ is_borrowed

bool is_borrowed

Definition at line 540 of file numpy.h.


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