Skip to content

Commit 36ba2ac

Browse files
committed
Add missing file
1 parent 91b1805 commit 36ba2ac

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

MLGkernel/MLGkernel/swig/MLGK.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "ThreadManager.hpp"
2+
#include "pMMFbase.hpp"
3+
#include "Vectorv.hpp"
4+
#include "Vectorl.hpp"
5+
#include "Vectorh.hpp"
6+
7+
std::default_random_engine randomNumberGenerator;
8+
bool multithreading=true;
9+
ThreadManager threadManager(4);
10+
char strbuffer[255];
11+
mutex CoutLock::mx;

MLGkernel/MLGkernel/swig/MLGK.i

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
%module MLGK
2+
%include "std_string.i"
3+
%{
4+
#define SWIG_FILE_WITH_INIT
5+
#include "../params.hpp"
6+
#include "../MLGdataset.hpp"
7+
using namespace std;
8+
%}
9+
10+
%include "numpy.i"
11+
%init
12+
%{
13+
import_array();
14+
%}
15+
16+
%apply (double* INPLACE_ARRAY2, int DIM1, int DIM2) {(double *npmatrix, int rows, int cols)};
17+
%include "../params.hpp"
18+
%include "../MLGdataset.hpp"

MLGkernel/MLGkernel/swig/Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Adjust accordingly
2+
ROOTDIR=/home/hopan/MLGkernel
3+
include ../../Makefile.base
4+
5+
6+
CC=g++
7+
CFLAGS= -std=c++11 -I $(INCLUDEDIR) -I $(UTILITYDIR) -I $(FILETYPESDIR) -I $(MATRIXDIR)
8+
9+
MKLVARS+= -lmkl_rt
10+
MLGDIR=/home/hopan/MLGkernel/MLGkernel
11+
ALLOBJECTS= $(MATRIXDIR)/*.o $(MLGDIR)/*.o $(UTILITYDIR)/*.o
12+
13+
# These need to be set according to your python location/distribution
14+
PYINCLUDE= -I/software/python-3.4-2015q1-el6-x86_64/include/python3.4m \
15+
-I/software/python-3.4-2015q1-el6-x86_64/lib/python3.4/site-packages/numpy/core/include
16+
PYLIBS= -L/Library/Frameworks/Python.framework/Versions/3.4/lib -ldl -framework CoreFoundation -lpython3.4m
17+
18+
MLGK_wrap.cxx: MLGK.i $(MLGDIR)/*.hpp $(MATRIXDIR)/*.hpp $(UTILITYDIR)/*.hpp
19+
swig -python -shadow -c++ MLGK.i
20+
21+
_MLGK.so: MLGK_wrap.cxx MLGK.cpp
22+
$(CC) -fPIC -shared MLGK_wrap.cxx MLGK.cpp \
23+
-o _MLGK.so $(CFLAGS) $(PYINCLUDE) $(ALLOBJECTS) -I $(INCLUDEDIR)
24+
25+
all: MLGK_wrap.cxx _MLGK.so
26+
27+
clean:
28+
rm -f $(OBJECTS) MLGK_wrap.cxx _MLGK.so
29+
30+
anew: clean all
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Run 'make all' at the top level of the MLGkernel directory.
2+
Then in this directory("MLGkernel/MLGkernel/swig/"), run make all.
3+
This will create the _MLGK.so shared object file as well as
4+
the MLGK.py file.
5+
6+
In python you should then be able to stuff like:
7+
import MLGK
8+
lvls = 2
9+
radius = 2
10+
m = MLGK.MLGdataset()
11+
m.loadGraphs("sampledata.txt")
12+
m.computeGram(lvls, radius)
13+
m.saveGram("savefile.txt")
14+
15+
16+
See test.py for further details.
17+
18+
NOTE: You will have to change some of the macros in the Makefile here(to change
19+
the location of where the Python.h file is stored - it should probably be
20+
somewhere like /usr/include/python3.x/. Also, in the top level directory inside
21+
Makefile.options, you need to specify where the eigen library is located, as well
22+
as the C++ compiler(IE: clang/g++/etc).

MLGkernel/MLGkernel/swig/test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from MLGK import *
2+
import numpy as np
3+
import pdb
4+
import os.path as path
5+
import sys
6+
7+
fname = path.abspath(path.join(__file__ ,"../../../data/MUTAG.txt"))
8+
save_name = "m.txt"
9+
num_graphs = 188
10+
eta = 0.01
11+
gamma= 0.001
12+
grow = True
13+
radius = 2
14+
levels = 2
15+
16+
m = MLGdataset(fname, eta, gamma, grow)
17+
m.computeGram(levels, radius)
18+
m.saveGram(save_name)
19+
20+
# fill a numpy matrix. Note: need to call compute gram
21+
# before calling fillGram
22+
gram = np.zeros((num_graphs, num_graphs))
23+
m.fillGram(gram)
24+
pdb.set_trace()

0 commit comments

Comments
 (0)