Nektar++
Static Public Member Functions | List of all members
NekMatrixToPython< T > Struct Template Reference

Static Public Member Functions

static PyObject * convert (std::shared_ptr< NekMatrix< T, StandardMatrixTag >> const &mat)
 

Detailed Description

template<typename T>
struct NekMatrixToPython< T >

Definition at line 61 of file NekMatrix.cpp.

Member Function Documentation

◆ convert()

template<typename T >
static PyObject* NekMatrixToPython< T >::convert ( std::shared_ptr< NekMatrix< T, StandardMatrixTag >> const &  mat)
inlinestatic

Definition at line 63 of file NekMatrix.cpp.

65  {
66  // Create a Python capsule to hold a pointer that contains a lightweight
67  // copy of arr. That way we guarantee Python will still have access to
68  // the memory allocated inside arr even if arr is deallocated in C++.
69 #if PY_MAJOR_VERSION == 2
70  py::object capsule(
71  py::handle<>(PyCObject_FromVoidPtr(
72  new std::shared_ptr<NekMatrix<T, StandardMatrixTag>>(mat),
73  NekMatrixCapsuleDestructor<T, StandardMatrixTag>)));
74 #else
75  py::object capsule(
76  py::handle<>(PyCapsule_New(
77  (void *)new std::shared_ptr<NekMatrix<T, StandardMatrixTag>>(mat), NULL,
78  (PyCapsule_Destructor)&NekMatrixCapsuleDestructor<T, StandardMatrixTag>)));
79 #endif
80 
81  int nRows = mat->GetRows(), nCols = mat->GetColumns();
82  MatrixStorage storage = mat->GetStorageType();
83 
84  ASSERTL0(storage == eFULL, "Only full storage matrices are currently supported.");
85 
86  return py::incref(
87  np::from_data(
88  mat->GetRawPtr(), np::dtype::get_builtin<T>(),
89  py::make_tuple(nRows, nCols),
90  py::make_tuple(sizeof(T), nRows * sizeof(T)),
91  capsule).ptr());
92  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216

References ASSERTL0, and Nektar::eFULL.