My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
Changes to /classification/ncd.py
87e5f98f6eab vs. 0136ea839f68 Compare: vs.  Format:
Revision 0136ea839f68
Go to: 
Project members, sign in to write a code review
/classification/ncd.py   87e5f98f6eab /classification/ncd.py   0136ea839f68
1 from ctypes import (cdll, Structure, Union, sizeof, addressof, create_string_buffer, c_byte, c_ubyte, c_char, c_short, c_ushort, c_int, c_uint, c_ulong, c_char_p, c_void_p, c_ulonglong, c_longlong) 1 from ctypes import cdll, c_float
2 2
3 class NCD :
4 def __init__(self) :
5 self._u = cdll.LoadLibrary( "./libncd/libncd.so" )
6 self._u.ncd.restype = c_float
7 self._threads = []
3 8
4 u = cdll.LoadLibrary( "./libncd/libncd.so" ) 9 def get(self, s1, s2) :
5 print u 10 return self._u.ncd( s1, len(s1), s2, len(s2) )
11
12 def benchmark(n, ref) :
13 import itertools
14
15 idx = 0
16 for i in itertools.permutations(ref) :
17 perm = ''.join(j for j in i)
18 res = n.get(ref, perm)
19 if res < 0.2 :
20 print idx, res, ref, perm
21 idx += 1
6 22
7 TEST1 = "TOTOO" 23 if __name__ == "__main__" :
8 TEST2 = "OUPS LA BOOOM" 24 try :
25 import psyco
26 psyco.full()
27 except ImportError:
28 pass
9 29
10 u.ncd( TEST1, len(TEST1), 30 n = NCD()
11 TEST2, len(TEST2) 31 benchmark(n, "androgua")
12 )
Powered by Google Project Hosting