Skip to content

Instantly share code, notes, and snippets.

@Grumbel
Last active December 23, 2015 22:49
Show Gist options
  • Save Grumbel/6705867 to your computer and use it in GitHub Desktop.
Save Grumbel/6705867 to your computer and use it in GitHub Desktop.
*.so
*.os
*~
*.pyc
/example_wrap.cc
/example.py
/.sconsign.dblite
#include <iostream>
#include <math.h>
#include <vector>
std::vector<int>
example(std::vector<double> R, int tot)
{
int N = R.size();
int bin_tot = tot;
std::vector<int> hist(bin_tot+1, 0);
double rmax = 6059.82;
double rlim = rmax/3;
double dr = 2020/tot;
for(int i = 0; i < N; ++i)
{
for(int j = 0; j < N; ++j)
{
double r = pow((pow(R[i/*,0*/]-R[j/*,0*/], 2) +
pow(R[i/*,1*/]-R[j/*,1*/], 2)),
0.5);
if(r <= rlim)
{
int bin_num = floor(r/dr);
hist[bin_num]++;
}
}
}
return hist;
}
/* EOF */
#include <vector>
std::vector<int> example(std::vector<double> R, int tot);
/* EOF */
%module "example"
%{
#include "example.h"
%}
%include "std_vector.i"
namespace std {
%template(vectori) vector<int>;
%template(vectord) vector<double>;
};
%include "example.h"
/* EOF */
#!/usr/bin/env python
import example
print example.example([1,2,3,4,5], 5)
# EOF #
import os
env = Environment(ENV=os.environ,
CXXFLAGS=['-Wall', '-Wextra'],
SWIGFLAGS=['-python', '-c++'],
SHLIBPREFIX="")
env.ParseConfig("pkg-config --libs --cflags python")
env.SharedLibrary("_example", ["example.i", "example.cpp"])
# EOF #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment