Skip to content

Tag: c++

How to make c++ return 2d array to python

I find an example showing how to return a 1D array from c++ to python. Now I hope to return a 2D array from c++ to python. I imitate the code shown in the example and my code is as follows: The file a.cpp: The file b.py: I run the following commands: Then I get the following prints: It seems

How to use compile_commands.json with clang python bindings?

I have the following script that attempts to print out all the AST nodes in a given C++ file. This works fine when using it on a simple file with trivial includes (header file in the same directory, etc). However, I get a clang.cindex.TranslationUnitLoadError: Error parsing translation unit. when I run the sc…

Pass a 2d numpy array to c using ctypes

What is the correct way to pass a numpy 2d – array to a c function using ctypes ? My current approach so far (leads to a segfault): C code : Python code: Answer This is probably a late answer, but I finally got it working. All credit goes to Sturla Molden at this link. The key is, note that

Getting started with cython on mac os

I wrote a simple program in python: Then I execute this: It was generated a file: main.c And then I tried this: And I have an error: How to compile python to c ? How to get started with cython with xcode on mac ? Answer You have to tell the gcc compiler where is the pyconfig.h file on your

Python vs C: different outputs

I have a small program that converts a base 10 number into a kind of a base 36 number. Here’s the Python code, and it works as expected. The output is “4 45 46” correctly represents 0, and “4 9 24” correctly represents 200. But the issue is, it stops working after I convert it to…