Subversion Repositories jcapco

Compare Revisions

Ignore whitespace Rev 10 → Rev 11

/lnumber/src/lib.cpp
New file
0,0 → 1,47
#include <lib.h>
#include <laman_number.h>
 
#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable: 4146 4244 4800)
#include <mpirxx.h>
#pragma warning(pop)
#else
#include <gmpxx.h>
#endif
 
using namespace std;
 
//convert symmetric matrix a[i,j] to flat symmetric no diagonal upper triangular
//nxn-matrix by getting the index of [i,j] for i>j
inline int idx_flat(int i, int j)
{
return int(i*(i-1)/2 + j);
}
 
inline std::vector<std::vector<int>> convert_to_edgelist(mpz_ptr nptr, int n=0)
{
using namespace std;
vector<vector<int>> out;
 
for (int i=1; i<n;++i)
{
for (int j=0;j<i;++j)
{
if (mpz_tstbit(nptr,idx_flat(i,j)))
{
int temp[]={j,i};
out.push_back(vector<int>(temp,temp+2));
}
}
}
return out;
}
 
size_t LIBLNUMBER_LIBRARY_INTERFACE laman_number(char* graph, size_t verts)
{
vector<vector<int>> edge_list;
mpz_class n(graph, 10);
edge_list = convert_to_edgelist(n.get_mpz_t(),verts);
return laman_number(edge_list);
}
/lnumber/inc/lib.h
New file
0,0 → 1,17
#pragma once
 
#if defined(_MSC_VER) && defined(_WIN32)
#ifdef LIBLNUMBER_EXPORTS
#define LIBLNUMBER_LIBRARY_INTERFACE __declspec(dllexport)
#else
#define LIBLNUMBER_LIBRARY_INTERFACE __declspec(dllimport)
#endif
#else
#define LIBLNUMBER_LIBRARY_INTERFACE
#include <cstddef>
#endif
 
extern "C"
{ //stops MSVC from mangling
size_t LIBLNUMBER_LIBRARY_INTERFACE laman_number(char* graph, size_t verts);
}
/lnumber/etc/lnumber.py
New file
0,0 → 1,12
from os import getcwd
from sys import path
from ctypes import cdll, c_char, c_size_t
 
path.insert(0, getcwd())
lib = cdll.LoadLibrary("./lnumber.pyd")
 
def lnumber(graph, verts):
global lib
return lib.laman_number(str(graph).encode("utf-8"), c_size_t(verts))
 
#print lnumber(252590061719913632,12)
/lnumber/etc/makelib.sh
New file
0,0 → 1,5
gcc -c ../src/laman_number.cpp -I../inc -I../ -std=c++11 -O3 -s -DNDEBUG -flto -fopenmp -fpic -m64 -Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -fpic -o ../laman_number.o
 
gcc -c ../src/lib.cpp -I../inc -I../ -std=c++11 -O3 -s -DNDEBUG -flto -fopenmp -fpic -m64 -Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -fpic -o ../lib.o
 
gcc -shared -lstdc++ -lm -lgmp -lgmpxx -lgomp -o ./lnumber.pyd ../laman_number.o ../lib.o