-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkmeans.h
More file actions
48 lines (38 loc) · 1.45 KB
/
kmeans.h
File metadata and controls
48 lines (38 loc) · 1.45 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef KMEANS_H
#define KMEANS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <stdbool.h>
typedef struct {
int k; // number of clusters
int d; // dimension of points
int n; // number of points
int max_iter; // maximum iterations
double threshold; // convergence threshold
int seed; // random seed
bool output_centroids; // true if -c flag is set
char *input_file; // input filename
int version; // version of kmeans
} kmeans_args;
typedef struct {
int iterations; // number of iterations to converge
double total_time; // total time in ms
} kmeans_result;
static unsigned long int kmeans_next = 1;
static unsigned long kmeans_rmax = 32767;
static inline int kmeans_rand() {
kmeans_next = kmeans_next * 1103515245 + 12345;
return (unsigned int)(kmeans_next/65536) % (kmeans_rmax+1);
}
static inline void kmeans_srand(unsigned int seed) {
kmeans_next = seed;
}
#define BLOCK_SIZE 256
kmeans_result kmeans_cpu(double *points, double *centers, int *assignments, kmeans_args *args);
kmeans_result kmeans_kernel(double *points, double *centers, int *assignments, kmeans_args *args);
kmeans_result kmeans_shared(double *points, double *centers, int *assignments, kmeans_args *args);
kmeans_result kmeans_thrust(double *points, double *centers, int *assignments, kmeans_args *args);
#endif