Nektar++
Public Member Functions | Static Public Member Functions | List of all members
PythonToVarCoeffEntry Struct Reference

Public Member Functions

 PythonToVarCoeffEntry ()
 

Static Public Member Functions

static void * convertible (PyObject *objPtr)
 
static void decrement (void *objPtr)
 
static void construct (PyObject *objPtr, py::converter::rvalue_from_python_stage1_data *data)
 

Detailed Description

Definition at line 85 of file VarCoeffEntry.cpp.

Constructor & Destructor Documentation

◆ PythonToVarCoeffEntry()

PythonToVarCoeffEntry::PythonToVarCoeffEntry ( )
inline

Definition at line 87 of file VarCoeffEntry.cpp.

88 {
89 py::converter::registry::push_back(&convertible, &construct,
90 py::type_id<VarCoeffEntry>());
91 }
static void * convertible(PyObject *objPtr)
static void construct(PyObject *objPtr, py::converter::rvalue_from_python_stage1_data *data)

References construct(), and convertible().

Member Function Documentation

◆ construct()

static void PythonToVarCoeffEntry::construct ( PyObject *  objPtr,
py::converter::rvalue_from_python_stage1_data *  data 
)
inlinestatic

Definition at line 137 of file VarCoeffEntry.cpp.

139 {
140 // This has to be a _borrowed_ reference, otherwise at the end of this
141 // scope it seems memory gets deallocated
142 py::object obj((py::handle<>(py::borrowed(objPtr))));
143 Array<OneD, NekDouble> array = py::extract<Array<OneD, NekDouble>>(obj);
144
145 void *storage =
146 ((py::converter::rvalue_from_python_storage<VarCoeffEntry> *)data)
147 ->storage.bytes;
148 data->convertible = storage;
149
150 new (storage) VarCoeffEntry(array);
151
152 py::incref(objPtr);
153 }
Representation of a variable coefficient.
Definition: StdRegions.hpp:265

Referenced by PythonToVarCoeffEntry().

◆ convertible()

static void * PythonToVarCoeffEntry::convertible ( PyObject *  objPtr)
inlinestatic

Definition at line 92 of file VarCoeffEntry.cpp.

93 {
94 try
95 {
96 py::object obj((py::handle<>(py::borrowed(objPtr))));
97 np::ndarray array = py::extract<np::ndarray>(obj);
98
99 // Check data types match
100 np::dtype dtype = np::dtype::get_builtin<
101 typename boost::remove_const<NekDouble>::type>();
102 if (dtype != array.get_dtype())
103 {
104 return nullptr;
105 }
106
107 // Check shape is 1D
108 if (array.get_nd() != 1)
109 {
110 return nullptr;
111 }
112 }
113 catch (boost::python::error_already_set &)
114 {
115 py::handle_exception();
116 PyErr_Clear();
117 return nullptr;
118 }
119
120 return objPtr;
121 }

Referenced by PythonToVarCoeffEntry().

◆ decrement()

static void PythonToVarCoeffEntry::decrement ( void *  objPtr)
inlinestatic

Definition at line 123 of file VarCoeffEntry.cpp.

124 {
125 if (!Py_IsInitialized())
126 {
127 // In deinitialisation phase, reference counters are not terribly
128 // robust; decremementing counters here can lead to segfaults during
129 // program exit in some cases.
130 return;
131 }
132
133 // Otherwise decrement reference counter.
134 py::decref((PyObject *)objPtr);
135 }