why scipy.spatial.ckdtree runs slower than scipy.spatial.kdtree

Multi tool use


why scipy.spatial.ckdtree runs slower than scipy.spatial.kdtree
Normally,scipy.spatial.ckdtree runs much faster than scipy.spatial.kdtree.
But in my case,scipy.spatial.ckdtree runs slower than scipy.spatial.kdtree.
My code is as follows:
import numpy as np
from laspy.file import File
from scipy import spatial
from timeit import default_timer as timer
inFile = File("Toronto_Strip_01.las")
dataset = np.vstack([inFile.x, inFile.y, inFile.z]).transpose()
print(dataset.shape)
start=timer()
tree = spatial.cKDTree(dataset)
# balanced_tree = False
end=timer()
distance,index=tree.query(dataset[100,:],k=5)
print(distance,index)
print(end-start)
start=timer()
tree = spatial.KDTree(dataset)
end=timer()
dis,indices= tree.query(dataset[100,:],k=5)
print(dis,indices)
print(end-start)
dataset.shape is (2727891, 3),dataset.max() is 4834229.32
But, in a test case, scipy.spatial.ckdtree runs much faster than scipy.spatial.kdtree,the code is as follows:
import numpy as np
from timeit import default_timer as timer
from scipy import spatial
np.random.seed(0)
A = np.random.random((2000000,3))*2000000
start1 = timer()
kdt=spatial.KDTree(A)
end1 = timer()
distance,index = kdt.query(A[100,:],k=5)
print(distance,index)
print(end1-start1)
start2 = timer()
kdt = spatial.cKDTree(A) # cKDTree + outside construction
end2 = timer()
distance,index = kdt.query(A[100,:],k=5)
print(distance,index)
print(end2-start2)
Here is my problem: in my code,Do I need to process the dataset to speedup the cKDTree?
my scipy version is 1.1.0,cython is 0.28.4
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.