Commit 9c0a1ca1 authored by Julien Jerphanion's avatar Julien Jerphanion

[WIP] KDTree implementation

There's a problem with the third partial sort:
```
Depth 9 on dim 1: [6, 12) med: 9 27141056 27141080 27141104     [1, 0, 2, 3, 4, 5, 11, 10, 9, 6, 7, 8]
```

The second hald of the array i.e of indices in [6, 12) is wrong. It looks like it's actually reverted.
It should not be:                                                                 [11, 10, 9, 6, 7, 8]
But something with the pivot (9) in the middle:                                   [ 7,  6, 8, 9,11,10]

From there, it just mess with the second half of the indices' array.

```
C 0x19e2460, 0x19e2478, 0x19e2490
Depth 10 on dim 0: [0, 12) med: 6 27141008 27141056 27141104    [1, 0, 4, 3, 2, 5, 6, 7, 8, 9, 10, 11]
             [1.000000, 0.000000, 4.000000, 3.000000, 2.000000, 5.000000, 6.000000, 7.000000, 8.000000, 9.000000, 10.000000, 11.000000]

C 0x19e2460, 0x19e246c, 0x19e2478
Depth 9 on dim 1: [0, 6) med: 3 27141008 27141032 27141056      [1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
             [1.000000, 0.000000, 2.000000, 3.000000, 4.000000, 5.000000, 6.000000, 7.000000, 8.000000, 9.000000, 10.000000, 11.000000]

C 0x19e2478, 0x19e2484, 0x19e2490
Depth 9 on dim 1: [6, 12) med: 9 27141056 27141080 27141104     [1, 0, 2, 3, 4, 5, 11, 10, 9, 6, 7, 8]
             [1.000000, 0.000000, 2.000000, 3.000000, 4.000000, 5.000000, 11.000000, 10.000000, 9.000000, 6.000000, 7.000000, 8.000000]

C 0x19e246c, 0x19e2470, 0x19e2478
Depth 8 on dim 0: [3, 6) med: 4 27141032 27141040 27141056      [1, 0, 2, 3, 4, 5, 11, 10, 9, 6, 7, 8]
             [1.000000, 0.000000, 2.000000, 3.000000, 4.000000, 5.000000, 11.000000, 10.000000, 9.000000, 6.000000, 7.000000, 8.000000]

C 0x19e2484, 0x19e2488, 0x19e2490
Depth 8 on dim 0: [9, 12) med: 10 27141080 27141088 27141104    [1, 0, 2, 3, 4, 5, 11, 10, 9, 8, 6, 7]
             [1.000000, 0.000000, 2.000000, 3.000000, 4.000000, 5.000000, 11.000000, 10.000000, 9.000000, 8.000000, 6.000000, 7.000000]

C 0x19e2470, 0x19e2474, 0x19e2478
Depth 7 on dim 1: [4, 6) med: 5 27141040 27141048 27141056      [1, 0, 2, 3, 4, 5, 11, 10, 9, 8, 6, 7]
             [1.000000, 0.000000, 2.000000, 3.000000, 4.000000, 5.000000, 11.000000, 10.000000, 9.000000, 8.000000, 6.000000, 7.000000]

C 0x19e2488, 0x19e248c, 0x19e2490
Depth 7 on dim 1: [10, 12) med: 11 27141088 27141096 27141104   [1, 0, 2, 3, 4, 5, 11, 10, 9, 8, 7, 6]
             [1.000000, 0.000000, 2.000000, 3.000000, 4.000000, 5.000000, 11.000000, 10.000000, 9.000000, 8.000000, 7.000000, 6.000000]

C 0x19e2478, 0x19e247c, 0x19e2484
Depth 8 on dim 0: [6, 9) med: 7 27141056 27141064 27141080      [1, 0, 2, 3, 4, 5, 9, 10, 11, 8, 7, 6]
             [1.000000, 0.000000, 2.000000, 3.000000, 4.000000, 5.000000, 9.000000, 10.000000, 11.000000, 8.000000, 7.000000, 6.000000]

C 0x19e247c, 0x19e2480, 0x19e2484
Depth 7 on dim 1: [7, 9) med: 8 27141064 27141072 27141080      [1, 0, 2, 3, 4, 5, 9, 10, 11, 8, 7, 6]
             [1.000000, 0.000000, 2.000000, 3.000000, 4.000000, 5.000000, 9.000000, 10.000000, 11.000000, 8.000000, 7.000000, 6.000000]

C 0x19e2460, 0x19e2464, 0x19e246c
Depth 8 on dim 0: [0, 3) med: 1 27141008 27141016 27141032      [0, 1, 2, 3, 4, 5, 9, 10, 11, 8, 7, 6]
             [0.000000, 1.000000, 2.000000, 3.000000, 4.000000, 5.000000, 9.000000, 10.000000, 11.000000, 8.000000, 7.000000, 6.000000]

C 0x19e2464, 0x19e2468, 0x19e246c
Depth 7 on dim 1: [1, 3) med: 2 27141016 27141024 27141032      [0, 1, 2, 3, 4, 5, 9, 10, 11, 8, 7, 6]
             [0.000000, 1.000000, 2.000000, 3.000000, 4.000000, 5.000000, 9.000000, 10.000000, 11.000000, 8.000000, 7.000000, 6.000000]

indices[0] = 0
indices[1] = 1
indices[2] = 2
indices[3] = 3
indices[4] = 4
indices[5] = 5
indices[6] = 9
indices[7] = 10
indices[8] = 11
indices[9] = 8
indices[10] = 7
indices[11] = 6
X[indices[0]]= 0.000000 0.000000
X[indices[1]]= 1.000000 1.000000
X[indices[2]]= 2.000000 2.000000
X[indices[3]]= 3.000000 3.000000
X[indices[4]]= 4.000000 4.000000
X[indices[5]]= 5.000000 5.000000
X[indices[6]]= 9.000000 9.000000
X[indices[7]]= 10.000000 10.000000
X[indices[8]]= 11.000000 11.000000
X[indices[9]]= 8.000000 8.000000
X[indices[10]]= 7.000000 7.000000
X[indices[11]]= 6.000000 6.000000
```
parent 104c7ec5
...@@ -17,7 +17,7 @@ ctypedef double D_t ...@@ -17,7 +17,7 @@ ctypedef double D_t
cdef lock Scheduler scheduler cdef lock Scheduler scheduler
DEF DEBUG True DEF DEBUG = True
cdef extern from *: cdef extern from *:
""" """
...@@ -112,18 +112,18 @@ cdef cypclass Node activable: ...@@ -112,18 +112,18 @@ cdef cypclass Node activable:
indices[3], indices[4], indices[5], indices[3], indices[4], indices[5],
indices[6], indices[7], indices[8], indices[6], indices[7], indices[8],
indices[9], indices[10], indices[11], indices[9], indices[10], indices[11],
points[n_dims * 0 + dim], points[n_dims * indices[0] + dim],
points[n_dims * 1 + dim], points[n_dims * indices[1] + dim],
points[n_dims * 2 + dim], points[n_dims * indices[2] + dim],
points[n_dims * 3 + dim], points[n_dims * indices[3] + dim],
points[n_dims * 4 + dim], points[n_dims * indices[4] + dim],
points[n_dims * 5 + dim], points[n_dims * indices[5] + dim],
points[n_dims * 6 + dim], points[n_dims * indices[6] + dim],
points[n_dims * 7 + dim], points[n_dims * indices[7] + dim],
points[n_dims * 8 + dim], points[n_dims * indices[8] + dim],
points[n_dims * 9 + dim], points[n_dims * indices[9] + dim],
points[n_dims * 10 + dim], points[n_dims * indices[10] + dim],
points[n_dims * 11 + dim], points[n_dims * indices[11] + dim],
) )
self.left = activate(consume Node()) self.left = activate(consume Node())
...@@ -218,6 +218,11 @@ cdef cypclass KDTree: ...@@ -218,6 +218,11 @@ cdef cypclass KDTree:
for i in range(n): for i in range(n):
printf("indices[%d] = %d\n", i, self.indices[i]) printf("indices[%d] = %d\n", i, self.indices[i])
for i in range(n):
printf("X[indices[%d]]= %f %f\n", i,
self.points[self.indices[i] * d],
self.points[self.indices[i] * d + 1])
void __dealloc__(self): void __dealloc__(self):
printf("Deallocating KDTree datastructures\n") printf("Deallocating KDTree datastructures\n")
free(self.points) free(self.points)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment