Skip to content

Instantly share code, notes, and snippets.

View mukundraj's full-sized avatar

Mukund Raj mukundraj

  • Massachusetts
View GitHub Profile
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
import matplotlib.mlab as mlab
plt.figure(facecolor="white")
F = plt.gcf() # get current frame.
DefaultSize = F.get_size_inches()
F.set_size_inches((DefaultSize[0]*1.5 ,DefaultSize[1]*1.0))
plt.subplot(2,3,3)
plt.axis('equal')
plt.title('New positions')
@mukundraj
mukundraj / sum.c
Created October 16, 2014 17:45
The C++ code
extern "C" int sum(short len, short *costs) {
int i;
int sum=0;
for (i = 0; i < len; i++) {
sum += costs[i];
}
return sum;
}
@mukundraj
mukundraj / sum
Created October 16, 2014 14:59
Calling C++ code from Python
import ctypes
_sum = ctypes.CDLL('./sum.so')
_sum.our_function.argtypes = (ctypes.c_int, ctypes.POINTER(ctypes.c_int))
def our_function(numbers):
global _sum
num_numbers = len(numbers)
array_type = ctypes.c_int * num_numbers
result = _sum.our_function(ctypes.c_int(num_numbers), array_type(*numbers))