Class star::NDArray¶
template <typename T>
Modern n-dimensional array class with xtensor-style API. More...
#include <stards.h>
Public Types¶
| Type | Name |
|---|---|
| typedef typename std::vector< T >::const_iterator | const_iterator |
| typedef typename std::vector< T >::const_reverse_iterator | const_reverse_iterator |
| typedef typename std::vector< T >::iterator | iterator |
| typedef typename std::vector< T >::reverse_iterator | reverse_iterator |
| typedef T | value_type |
Public Functions¶
| Type | Name |
|---|---|
| NDArray () = default Default constructor. |
|
| NDArray (const std::vector< size_t > & shape_in) Constructor with shape. |
|
| NDArray (const std::vector< size_t > & shape_in, const T & initial_value) Constructor with shape and initial value. |
|
| NDArray (const std::vector< T > & data_in, const std::vector< size_t > & shape_in) Constructor with data and shape. |
|
| NDArray (std::vector< T > && data_in, const std::vector< size_t > & shape_in) Move constructor with data and shape (zero-copy for Python bindings). |
|
| NDArray (const NDArray & other) Copy constructor. |
|
| T & | at (const std::vector< size_t > & indices) Get Array element. |
| const T & | at (const std::vector< size_t > & indices) const |
| iterator | begin () |
| const_iterator | begin () const |
| const_iterator | cbegin () const |
| const_iterator | cend () const |
| std::vector< T > & | data () Get reference to internal data vector. |
| const std::vector< T > & | data () const |
| T * | data_ptr () Get raw pointer to data. |
| const T * | data_ptr () const |
| size_t | dimension () const Get number of dimensions. |
| iterator | end () |
| const_iterator | end () const |
| T & | flat (size_t index) Flat indexing for 1D access. |
| const T & | flat (size_t index) const |
| T & | operator() (Indices... indices) Variadic operator() for multi-dimensional indexing. |
| const T & | operator() (Indices... indices) const |
| reverse_iterator | rbegin () |
| const_reverse_iterator | rbegin () const |
| reverse_iterator | rend () |
| const_reverse_iterator | rend () const |
| void | reshape (const std::vector< size_t > & new_shape) Reshape array (no reallocation). |
| void | resize (const std::vector< size_t > & new_shape, const T & fill_value=T{}) Resize array (with reallocation). |
| const std::vector< size_t > & | shape () const Get shape vector. |
| size_t | shape (size_t dim) const Get specific dimension size. |
| size_t | size () const Get total number of elements. |
| const std::vector< size_t > & | strides () const Get strides vector. |
Public Static Functions¶
| Type | Name |
|---|---|
| std::enable_if< std::is_arithmetic< U >::value, NDArray< T > >::type | arange (T start, T stop, T step=T{1}) Create range array (numeric types only). |
| NDArray< T > | empty (const std::vector< size_t > & shape) Create uninitialized array. |
| NDArray | from_vector_move (std::vector< T > & data_in, const std::vector< size_t > & shape_in) Factory method to create NDArray by moving vector (for Python bindings) SWIG doesn't handle rvalue references well, so we use this factory method. |
| NDArray< T > | full (const std::vector< size_t > & shape, const T & value) Create array filled with specific value. |
| NDArray< T > | ones (const std::vector< size_t > & shape) Create one-initialized array. |
| NDArray< T > | zeros (const std::vector< size_t > & shape) Create zero-initialized array. |
Detailed Description¶
This class implements an n-dimensional array stored as a flat 1D vector with operator() indexing, iterators, and static factory methods.
Public Types Documentation¶
typedef const_iterator¶
typedef const_reverse_iterator¶
typedef iterator¶
typedef reverse_iterator¶
typedef value_type¶
Public Functions Documentation¶
function NDArray [1/6]¶
Default constructor.
function NDArray [2/6]¶
Constructor with shape.
Parameters:
shape_inDimensions of the array
function NDArray [3/6]¶
Constructor with shape and initial value.
Parameters:
shape_inDimensions of the arrayinitial_valueValue to initialize all elements with
function NDArray [4/6]¶
Constructor with data and shape.
inline star::NDArray::NDArray (
const std::vector< T > & data_in,
const std::vector< size_t > & shape_in
)
Parameters:
data_inFlat data to useshape_inDimensions of the array
function NDArray [5/6]¶
Move constructor with data and shape (zero-copy for Python bindings).
inline star::NDArray::NDArray (
std::vector< T > && data_in,
const std::vector< size_t > & shape_in
)
Parameters:
data_inFlat data to move fromshape_inDimensions of the array
function NDArray [6/6]¶
Copy constructor.
Parameters:
otherNDArray to copy from
function at [1/2]¶
Get Array element.
Deprecated
Use operator() instead
function at [2/2]¶
function begin [1/2]¶
function begin [2/2]¶
function cbegin¶
function cend¶
function data [1/2]¶
Get reference to internal data vector.
function data [2/2]¶
function data_ptr [1/2]¶
Get raw pointer to data.
function data_ptr [2/2]¶
function dimension¶
Get number of dimensions.
function end [1/2]¶
function end [2/2]¶
function flat [1/2]¶
Flat indexing for 1D access.
function flat [2/2]¶
function operator()¶
Variadic operator() for multi-dimensional indexing.
function operator()¶
template<typename... Indices>
inline const T & star::NDArray::operator() (
Indices... indices
) const
function rbegin [1/2]¶
function rbegin [2/2]¶
function rend [1/2]¶
function rend [2/2]¶
function reshape¶
Reshape array (no reallocation).
function resize¶
Resize array (with reallocation).
inline void star::NDArray::resize (
const std::vector< size_t > & new_shape,
const T & fill_value=T{}
)
function shape [1/2]¶
Get shape vector.
function shape [2/2]¶
Get specific dimension size.
function size¶
Get total number of elements.
function strides¶
Get strides vector.
Public Static Functions Documentation¶
function arange¶
Create range array (numeric types only).
template<typename U>
static inline std::enable_if< std::is_arithmetic< U >::value, NDArray < T > >::type star::NDArray::arange (
T start,
T stop,
T step=T{1}
)
function empty¶
Create uninitialized array.
function from_vector_move¶
Factory method to create NDArray by moving vector (for Python bindings) SWIG doesn't handle rvalue references well, so we use this factory method.
static inline NDArray star::NDArray::from_vector_move (
std::vector< T > & data_in,
const std::vector< size_t > & shape_in
)
Parameters:
data_inVector to move fromshape_inDimensions of the array
function full¶
Create array filled with specific value.
static inline NDArray < T > star::NDArray::full (
const std::vector< size_t > & shape,
const T & value
)
function ones¶
Create one-initialized array.
function zeros¶
Create zero-initialized array.
Friends Documentation¶
friend operator<<¶
Write array to output stream.
Parameters:
osOutput stream
friend operator>>¶
Read array from input stream.
Parameters:
isInput stream
The documentation for this class was generated from the following file StarDS/include/stards.h