|
@@ -1,9 +1,26 @@
|
|
|
import math
|
|
import math
|
|
|
|
|
+from ctypes import cdll, c_uint, c_double, c_void_p
|
|
|
|
|
|
|
|
import tensorflow as tf
|
|
import tensorflow as tf
|
|
|
import numpy as np
|
|
import numpy as np
|
|
|
|
|
+import numpy.ctypeslib as npct
|
|
|
|
|
+
|
|
|
|
|
+array_2d_uint = npct.ndpointer(dtype=np.uint, ndim=2, flags='CONTIGUOUS')
|
|
|
|
|
+array_1d_double = npct.ndpointer(dtype=np.double, ndim=1, flags='CONTIGUOUS')
|
|
|
|
|
+array_2d_double = npct.ndpointer(dtype=np.double, ndim=2, flags='CONTIGUOUS')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
from sklearn.neighbors import NearestNeighbors
|
|
from sklearn.neighbors import NearestNeighbors
|
|
|
from library.timing import timing
|
|
from library.timing import timing
|
|
|
|
|
+from library.MaxHeap import MaxHeap
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+nbhLib = cdll.LoadLibrary("./library/c/libNeighborhood.so")
|
|
|
|
|
+nbhLib.Neighborhood.rettype = None
|
|
|
|
|
+nbhLib.Neighborhood.argtypes = [c_uint, c_uint, c_uint, array_2d_double, array_2d_uint]
|
|
|
|
|
+
|
|
|
|
|
+nbhLib.NeighborhoodHeuristic.rettype = None
|
|
|
|
|
+nbhLib.NeighborhoodHeuristic.argtypes = [c_uint, c_uint, c_uint, array_2d_double, array_2d_uint]
|
|
|
|
|
|
|
|
|
|
|
|
|
def dist(x,y):
|
|
def dist(x,y):
|
|
@@ -302,6 +319,35 @@ class NNSearch:
|
|
|
self.timerStop("NN_fit_chained_toList")
|
|
self.timerStop("NN_fit_chained_toList")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ def fit_cLib(self, X, nebSize=None):
|
|
|
|
|
+ self.timerStart("NN_fit_cLib_init")
|
|
|
|
|
+ if nebSize == None:
|
|
|
|
|
+ nebSize = self.nebSize
|
|
|
|
|
+
|
|
|
|
|
+ nbh = np.array([np.zeros(nebSize, dtype=np.uint) for i in range(X.shape[0])])
|
|
|
|
|
+ self.timerStop("NN_fit_cLib_init")
|
|
|
|
|
+ self.timerStart("NN_fit_cLib_call")
|
|
|
|
|
+ nbhLib.Neighborhood(nebSize, X.shape[0], X.shape[1], X, nbh)
|
|
|
|
|
+ self.timerStop("NN_fit_cLib_call")
|
|
|
|
|
+ self.timerStart("NN_fit_cLib_list")
|
|
|
|
|
+ self.neighbourhoods = list(nbh)
|
|
|
|
|
+ self.timerStop("NN_fit_cLib_list")
|
|
|
|
|
+
|
|
|
|
|
+ def fit_cLibHeuristic(self, X, nebSize=None):
|
|
|
|
|
+ self.timerStart("NN_fit_cLib_init")
|
|
|
|
|
+ if nebSize == None:
|
|
|
|
|
+ nebSize = self.nebSize
|
|
|
|
|
+
|
|
|
|
|
+ nbh = np.array([np.zeros(nebSize, dtype=np.uint) for i in range(X.shape[0])])
|
|
|
|
|
+ self.timerStop("NN_fit_cLib_init")
|
|
|
|
|
+ self.timerStart("NN_fit_cLib_call")
|
|
|
|
|
+ nbhLib.NeighborhoodHeuristic(nebSize, X.shape[0], X.shape[1], X, nbh)
|
|
|
|
|
+ self.timerStop("NN_fit_cLib_call")
|
|
|
|
|
+ self.timerStart("NN_fit_cLib_list")
|
|
|
|
|
+ self.neighbourhoods = list(nbh)
|
|
|
|
|
+ self.timerStop("NN_fit_cLib_list")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
# ===============================================================
|
|
# ===============================================================
|
|
|
# Heuristic search
|
|
# Heuristic search
|
|
|
# ===============================================================
|
|
# ===============================================================
|