pybinding

Pybind11: passing a string* argument to a constructor

眉间皱痕 提交于 2019-12-11 00:24:32
问题 In a C++ library that I'm not allowed to change I have a constructor that looks like this: Dfa(const int n_state, const int dim_alf, const string *alf); If I simply bind with .def(py::init<const int, const int, const std::string*>()) it compiles succesfully. The problem is that I can't pass a string* by python, because for example if I try to execute on python alph=['x','y'] z=Dfa(3,2,alph) It returns the following error: TypeError: __init__(): incompatible constructor arguments. The

Creating a NumPy array directly from __array_interface__

我只是一个虾纸丫 提交于 2019-12-04 03:38:29
问题 Suppose I have an __array_interface__ dictionary and I would like to create a numpy view of this data from the dictionary itself. For example: buff = {'shape': (3, 3), 'data': (140546686381536, False), 'typestr': '<f8'} view = np.array(buff, copy=False) However, this does not work as np.array searches for either the buffer or array interface as attributes. The simple workaround could be the following: class numpy_holder(object): pass holder = numpy_holder() holder.__array_interface__ = buff

Creating a NumPy array directly from __array_interface__

断了今生、忘了曾经 提交于 2019-12-01 19:03:51
Suppose I have an __array_interface__ dictionary and I would like to create a numpy view of this data from the dictionary itself. For example: buff = {'shape': (3, 3), 'data': (140546686381536, False), 'typestr': '<f8'} view = np.array(buff, copy=False) However, this does not work as np.array searches for either the buffer or array interface as attributes. The simple workaround could be the following: class numpy_holder(object): pass holder = numpy_holder() holder.__array_interface__ = buff view = np.array(holder, copy=False) This seems a bit roundabout. Am I missing a straightforward way to