-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
52 lines (40 loc) · 1.46 KB
/
build.py
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
49
50
51
52
import os
from cffi import FFI
CFFI_CDEF = """
struct Centroid {
long long weight;
double mean;
};
struct Point {
double value;
long long weight;
struct Point *next;
};
struct TDigest {
unsigned int compression;
int threshold;
long long size;
long long weight;
double min;
double max;
unsigned int point_count;
struct Point *points;
unsigned int centroid_count;
struct Centroid *centroids;
unsigned int compression_count;
};
extern struct TDigest *tdigest_new(unsigned int compression);
extern void tdigest_add(struct TDigest *digest, double value, long long weight);
extern void tdigest_merge(struct TDigest *digest1, struct TDigest *digest2);
extern double tdigest_cdf(struct TDigest *digest, double value);
extern double tdigest_quantile(struct TDigest *digest, double quantile);
extern void tdigest_compress(struct TDigest *digest);
extern void tdigest_free(struct TDigest *digest);
"""
source_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "sources")
tdigest_ffi = FFI()
tdigest_ffi.cdef(CFFI_CDEF)
with open(os.path.join(source_directory, "tdigest.c")) as tdigest_source_file:
tdigest_ffi.set_source("tdigest._tdigest", tdigest_source_file.read(), include_dirs=[source_directory])
if __name__ == "__main__":
tdigest_ffi.compile(verbose=True)