ndarray: /home/runner/work/ndarray/ndarray/include/ndarray/detail/Core.h Source File
11#ifndef NDARRAY_DETAIL_Core_h_INCLUDED
12#define NDARRAY_DETAIL_Core_h_INCLUDED
20#include <boost/intrusive_ptr.hpp>
21#include <boost/mpl/int.hpp>
49 typedef boost::mpl::int_<N> ND;
51 typedef boost::intrusive_ptr<Core> Ptr;
52 typedef boost::intrusive_ptr<Core const> ConstPtr;
59 Manager::Ptr const & manager = Manager::Ptr()
61 return Ptr(new Core(shape, strides, manager), false);
69 Manager::Ptr const & manager = Manager::Ptr()
72 return Ptr(new Core(shape, manager), false);
74 return Ptr(new Core(shape, 1, manager), false);
80 Manager::Ptr const & manager = Manager::Ptr()
82 return Ptr(new Core(manager), false);
85 Ptr copy() const { return Ptr(new Core(*this)); }
88 Size getSize() const { return _size; }
91 Offset getStride() const { return _stride; }
94 void setSize(Size size) { _size = size; }
97 void setStride(Offset stride) { _stride = stride; }
108 shape[M-N] = this->getSize();
115 strides[M-N] = this->getStride();
131 Manager::Ptr const & manager
132 ) : Super(shape, strides, manager), _size(shape[M-N]), _stride(strides[M-N]) {}
138 Manager::Ptr const & manager
144 Vector<Size,M> const & shape,
146 Manager::Ptr const & manager
147 ) : Super(shape, stride * shape[M-N], manager), _size(shape[M-N]), _stride(stride) {}
151 Manager::Ptr const & manager
152 ) : Super(manager), _size(0), _stride(0) {}
154 Core(Core const & other) : Super(other), _size(other._size), _stride(other._stride) {}
173 typedef boost::mpl::int_<0> ND;
174 typedef boost::intrusive_ptr<Core> Ptr;
175 typedef boost::intrusive_ptr<Core const> ConstPtr;
177 friend inline void intrusive_ptr_add_ref(Core const * core) {
181 friend inline void intrusive_ptr_release(Core const * core) {
182 if ((--core->_rc)==0) delete core;
185 Ptr copy() const { return Ptr(new Core(*this)); }
187 Size getSize() const { return 1; }
188 Offset getStride() const { return 1; }
195 Manager::Ptr getManager() const { return _manager; }
198 void setManager(Manager::Ptr const & manager) { _manager = manager; }
212 int getRC() const { return _rc; }
215 bool isUnique() const { return (_rc == 1) && (_manager->getRC() == 1) && _manager->isUnique(); }
219 virtual ~Core() {}
225 Manager::Ptr const & manager
226 ) : _manager(manager), _rc(1) {}
230 Vector<Size,M> const & shape,
231 Manager::Ptr const & manager
232 ) : _manager(manager), _rc(1) {}
236 Vector<Size,M> const & shape,
238 Manager::Ptr const & manager
239 ) : _manager(manager), _rc(1) {}
242 Manager::Ptr const & manager
243 ) : _manager(manager), _rc(1) {}
245 Core(Core const & other) : _manager(other._manager), _rc(1) {}
260getDimension(Core<N> const & core) { return core; }
268inline typename Core<N-P>::Ptr
269getDimension(typename Core<N>::Ptr const & core) { return core; }
Definition of Manager, which manages the ownership of array data.
bool isUnique() const
Return true if the Core and Manager reference counts are 1 and the manager is unique.
Definition Core.h:215
void setManager(Manager::Ptr const &manager)
Set the Manager that determines the lifetime of the array data.
Definition Core.h:198
Manager::Ptr getManager() const
Return the Manager that determines the lifetime of the array data.
Definition Core.h:195
Offset computeOffset(Vector< Size, M > const &index) const
Recursively compute the offset to an element.
Definition Core.h:192
Size getNumElements() const
Recursively determine the total number of elements.
Definition Core.h:209
void fillShape(Vector< Size, M > const &shape) const
Recursively fill a shape vector.
Definition Core.h:202
int getRC() const
Return the reference count (for debugging purposes).
Definition Core.h:212
void fillStrides(Vector< Offset, M > const &strides) const
Recursively fill a strides vector.
Definition Core.h:206
static Ptr create(Vector< Size, M > const &shape, Vector< Offset, M > const &strides, Manager::Ptr const &manager=Manager::Ptr())
Create a Core::Ptr with the given shape, strides, and manager.
Definition Core.h:56
Size getSize() const
Return the size of the Nth dimension.
Definition Core.h:88
void fillStrides(Vector< Offset, M > &strides) const
Recursively fill a strides vector.
Definition Core.h:114
void fillShape(Vector< Size, M > &shape) const
Recursively fill a shape vector.
Definition Core.h:107
static Ptr create(Vector< Size, M > const &shape, DataOrderEnum order, Manager::Ptr const &manager=Manager::Ptr())
Create a Core::Ptr with the given shape and manager with contiguous strides.
Definition Core.h:66
Offset computeOffset(Vector< Size, M > const &index) const
Recursively compute the offset to an element.
Definition Core.h:101
Size getNumElements() const
Recursively determine the total number of elements.
Definition Core.h:120
void setSize(Size size)
Set the size of the Nth dimension.
Definition Core.h:94
boost::intrusive_ptr< Core > Ptr
intrusive_ptr to Core
Definition Core.h:51
boost::intrusive_ptr< Core const > ConstPtr
const intrusive_ptr to Core
Definition Core.h:52
static Ptr create(Manager::Ptr const &manager=Manager::Ptr())
Create a Core::Ptr with the given manager and zero shape and strides.
Definition Core.h:79
boost::mpl::int_< N > ND
number of dimensions
Definition Core.h:49
Core< N-1 > Super
base class
Definition Core.h:50
void setStride(Offset stride)
Set the stride of the Nth dimension.
Definition Core.h:97
Offset getStride() const
Return the stride of the Nth dimension.
Definition Core.h:91
DataOrderEnum
An enumeration for stride computation.
Definition ndarray_fwd.h:51
A fixed-size 1D array class.
Definition Vector.h:82