c++

pybind11 cannot import templates

pybind11 cannot import templates Question: I tried to use templates in pybind11 based on this demo. Error >>> from example import add >>> add(2,3) 5L >>> from example import myadd Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name myadd Why does myadd cannot be imported while add can? …

Total answers: 1

Running C Program on Heroku: No such file

Running C Program on Heroku: No such file Question: I am trying to open a C program in a python script running on a Heroku dyno. The Python script works fine locally, but on the dyno it says that the executable cannot be found. The line to run the program in Python is: proc = …

Total answers: 1

Python C API sys.getsizeof()

Python C API sys.getsizeof() Question: I’m trying to call a method getsizeof from a C library for Python. Here’s my code: //Returns in bytes the size of obj in memory //sys.getsizeof(obj) size_t getSizeOf(PyObject* obj){ //obj could be dict or list Py_INCREF(obj); PyObject* sys = PyModule_New("sys"); //import sys PyObject* string = Py_BuildValue("s", "getsizeof"); PyObject* res = …

Total answers: 1

Why don't you need to do target_link_libraries when using Eigen with pybind11

Why don't you need to do target_link_libraries when using Eigen with pybind11 Question: I was trying to compile this example.cpp from a pybind11 tutorial called pybind11_examples on GitHub #include <pybind11/pybind11.h> #include <pybind11/eigen.h> #include <Eigen/LU> #include <iostream> // —————- // regular C++ code // —————- Eigen::MatrixXd mul(const Eigen::MatrixXd &xs, double fac) { std::cout << "Double" << …

Total answers: 2

How to pass references of declared variables to C function in python using ctypes

How to pass references of declared variables to C function in python using ctypes Question: I would like to call a C function from python. This C function is void, thus the "return parameters" (data I want to change) are defined as pointers in the C function’s definition. The function in C looks like this …

Total answers: 2

OpenCV Mat cpp operation only on condition

OpenCV Mat cpp operation only on condition Question: Having a hard time figuring out how to do this python operation in c++ without looping. The goal is to perform an operation only on a part of the cv::Mat that meets a condition. In this case, scaling values of the image that were originally between -5 …

Total answers: 1

Embedding Python in C++: how to parse a list returned from Python function?

Embedding Python in C++: how to parse a list returned from Python function? Question: My code looks something like this: PyObject *pArguments, *pArgumentValue; pArgumentValue = PyObject_CallObject(pFunction, pArguments); Py_DECREF(pArguments); if (pArgumentValue != NULL) { #????????????????? } else { PyErr_Print(); } I would like to parse the return value of the python method, which returns a list …

Total answers: 1

How to debug crashing C++ library loaded in python project

How to debug crashing C++ library loaded in python project Question: I am attempting to figure out why calling a function in a dynamically loaded lib crashes python. I’m doing the following, I have a C++ function in a dynamic library file, which is loaded in python using ctypes. I then call the function from …

Total answers: 1

c++ programming realted , array of numbers

c++ programming realted , array of numbers Question: I’m new to c++ .This is the first part of my program.I want the output of list a .But it doesn’t give a output.only get input.After getting inputs the program stops. #include <iostream> using namespace std; class clist { public: int i, j,k,times; double numbers[1000]; clist () …

Total answers: 1

Python Swig interface for C function allocating a list of structures

Python Swig interface for C function allocating a list of structures Question: I’m trying to get the following C function to be exposed as a python interface. void myfunc(struct MyStruct** list, int* size) { int n = 10; *size = n; *list = (struct MyStruct*) malloc(n * sizeof(struct MyStruct)); for (int i = 0; i …

Total answers: 2