@@ -28,6 +28,27 @@ using InputAdapter = bitsery::InputBufferAdapter<Buffer>;
2828using Serializer = bitsery::Serializer<OutputAdapter>;
2929using Deserializer = bitsery::Deserializer<InputAdapter>;
3030
31+ // / @brief use this to provide a base object to the array
32+ // such a base object can own shared data
33+ // you might need to implement reference counting
34+ struct BaseObj {
35+ virtual ~BaseObj () {}
36+ virtual bool needGIL () const = 0;
37+ };
38+
39+ // / @brief Simple implementation of BaseObj for ref-counting types
40+ // / @tparam T ref-counting type, such as py::object of std::shared_Ptr
41+ // / we keep an object of the ref-counting type. Normal ref-counting/destructors
42+ // / will take care of the rest.
43+ template <typename T> struct SharedBaseObject : public BaseObj {
44+ SharedBaseObject (const SharedBaseObject &) = default ;
45+ SharedBaseObject (SharedBaseObject &&) = default ;
46+ SharedBaseObject (const T &o) : _base(o) {}
47+ SharedBaseObject (T &&o) : _base(std::forward<T>(o)) {}
48+ virtual bool needGIL () const { return false ; }
49+ T _base;
50+ };
51+
3152union PyScalar {
3253 int64_t _int;
3354 double _float;
@@ -42,17 +63,39 @@ enum _RANKS : rank_type {
4263};
4364
4465template <typename T> struct DTYPE {};
45- template <> struct DTYPE <double > { constexpr static DTypeId value = FLOAT64; };
46- template <> struct DTYPE <float > { constexpr static DTypeId value = FLOAT32; };
47- template <> struct DTYPE <int64_t > { constexpr static DTypeId value = INT64; };
48- template <> struct DTYPE <int32_t > { constexpr static DTypeId value = INT32; };
49- template <> struct DTYPE <int16_t > { constexpr static DTypeId value = INT16; };
50- template <> struct DTYPE <int8_t > { constexpr static DTypeId value = INT8; };
51- template <> struct DTYPE <uint64_t > { constexpr static DTypeId value = UINT64; };
52- template <> struct DTYPE <uint32_t > { constexpr static DTypeId value = UINT32; };
53- template <> struct DTYPE <uint16_t > { constexpr static DTypeId value = UINT16; };
54- template <> struct DTYPE <uint8_t > { constexpr static DTypeId value = UINT8; };
55- template <> struct DTYPE <bool > { constexpr static DTypeId value = BOOL; };
66+ template <> struct DTYPE <double > {
67+ constexpr static DTypeId value = FLOAT64;
68+ };
69+ template <> struct DTYPE <float > {
70+ constexpr static DTypeId value = FLOAT32;
71+ };
72+ template <> struct DTYPE <int64_t > {
73+ constexpr static DTypeId value = INT64;
74+ };
75+ template <> struct DTYPE <int32_t > {
76+ constexpr static DTypeId value = INT32;
77+ };
78+ template <> struct DTYPE <int16_t > {
79+ constexpr static DTypeId value = INT16;
80+ };
81+ template <> struct DTYPE <int8_t > {
82+ constexpr static DTypeId value = INT8;
83+ };
84+ template <> struct DTYPE <uint64_t > {
85+ constexpr static DTypeId value = UINT64;
86+ };
87+ template <> struct DTYPE <uint32_t > {
88+ constexpr static DTypeId value = UINT32;
89+ };
90+ template <> struct DTYPE <uint16_t > {
91+ constexpr static DTypeId value = UINT16;
92+ };
93+ template <> struct DTYPE <uint8_t > {
94+ constexpr static DTypeId value = UINT8;
95+ };
96+ template <> struct DTYPE <bool > {
97+ constexpr static DTypeId value = BOOL;
98+ };
5699
57100template <DTypeId DT> struct TYPE {};
58101template <> struct TYPE <FLOAT64> {
0 commit comments