-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallel_splits.c
29 lines (24 loc) · 1001 Bytes
/
parallel_splits.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// $d: number of features
// $n: number of samples
##include <limits.h>
// This is the exhaustive greedy method
__global__ void parallel_splits(double samples[$n][$d],
double hyperplans[$d*$n][$d+2]) {
int t_x, t_y; // Thread id
int i; // Index variable
double next = 1000000; //XXX Fix that
t_x = blockIdx.x * blockDim.x + threadIdx.x; // Indexes the samples
t_y = blockIdx.y * blockDim.y + threadIdx.y; // Indexes the features
if(t_x < $n && t_y < $d) {
// Find the next sample
for(i = 0 ; i < $n ; i++)
if(samples[i][t_y] > samples[t_x][t_y] && samples[i][t_y] < next)
next = samples[i][t_y];
// If a next point was found: the current point is not the last one
if(next != 1000000) {
hyperplans[t_x+t_y*$n][$d+1] = 1;
hyperplans[t_x+t_y*$n][t_y] = 1;
hyperplans[t_x+t_y*$n][$d] = -(samples[t_x][t_y] + next)/2.0;
}
}
}