Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/NativeBridge/ManagedInterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
#include "DataViewInterop.h"
#include "ManagedInterop.h"

inline void destroyManagerCObject(PyObject* obj) {
auto* b = static_cast<PythonObjectBase*>(PyCapsule_GetPointer(obj, NULL));
if (b) { delete b; }
}

#define SetDict2(cpptype, nptype); \
{\
PythonObject<cpptype>* col = dynamic_cast<PythonObject<cpptype>*>(column);\
auto shrd = col->GetData();\
auto* data = shrd->data();\
bp::handle<> h(::PyCapsule_New((void*)column, NULL, (PyCapsule_Destructor)&destroyManagerCObject));\
dict[_names[i]] = np::from_data(\
data,\
np::dtype::get_builtin<nptype>(),\
bp::make_tuple(shrd->size()),\
bp::make_tuple(sizeof(nptype)), bp::object());\
bp::make_tuple(sizeof(nptype)), bp::object(h));\
}

#define SetDict1(type) SetDict2(type, type)
Expand All @@ -25,11 +31,12 @@
PythonObject<type>* col = dynamic_cast<PythonObject<type>*>(column);\
auto shrd = col->GetData();\
auto* data = shrd->data();\
bp::handle<> h(::PyCapsule_New((void*)column, NULL, (PyCapsule_Destructor)&destroyManagerCObject));\
np::ndarray npdata = np::from_data(\
data,\
np::dtype::get_builtin<type>(),\
bp::make_tuple(shrd->size()),\
bp::make_tuple(sizeof(float)), bp::object());\
bp::make_tuple(sizeof(float)), bp::object(h));\
if (keyNames == nullptr)\
{\
dict[_names[i]] = npdata;\
Expand Down Expand Up @@ -305,6 +312,7 @@ bp::dict EnvironmentBlock::GetData()
list.append(obj);
}
dict[_names[i]] = list;
delete column;
}
break;
case TS:
Expand Down
9 changes: 5 additions & 4 deletions src/NativeBridge/PythonInterop.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ template <class T>
class PythonObject : public PythonObjectBase
{
protected:
std::shared_ptr<std::vector<T>> _pData;
std::vector<T>* _pData;

size_t _numRows;
size_t _numCols;
Expand All @@ -71,7 +71,7 @@ class PythonObject : public PythonObjectBase
PythonObject(const int& kind, size_t numRows = 1, size_t numCols = 1);
virtual ~PythonObject();
void SetAt(size_t nRow, size_t nCol, const T& value);
const std::shared_ptr<std::vector<T> >& GetData() const;
const std::vector<T>* GetData() const;
};

template <class T>
Expand All @@ -81,14 +81,15 @@ inline PythonObject<T>::PythonObject(const int& kind, size_t numRows, size_t num
_numRows = numRows;
_numCols = numCols;

_pData = std::make_shared<std::vector<T>>();
_pData = new std::vector<T>();
if (_numRows > 0)
_pData->reserve(_numRows*_numCols);
}

template <class T>
inline PythonObject<T>::~PythonObject()
{
delete _pData;
}

template <class T>
Expand All @@ -101,7 +102,7 @@ inline void PythonObject<T>::SetAt(size_t nRow, size_t nCol, const T& value)
}

template <class T>
inline const std::shared_ptr<std::vector<T>>& PythonObject<T>::GetData() const
inline const std::vector<T>* PythonObject<T>::GetData() const
{
return _pData;
}