-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.c
42 lines (34 loc) · 989 Bytes
/
sample.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
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Name: sample.c
Purpose: Command line interface for aldr.
Author: CMU Probabilistic Computing Systems Lab
Copyright (C) 2025 CMU Probabilistic Computing Systems Lab, All Rights Reserved.
Released under Apache 2.0; refer to LICENSE.txt
*/
#include <stdio.h>
#include <stdlib.h>
#include "aldr.h"
int main(int argc, char **argv) {
if (argc < 3) {
printf("usage: %s <num_samples> <distribution>\n", argv[0]);
exit(0);
}
uint32_t num_samples = strtoul(argv[1], NULL, 10);
// Parse the distribution.
uint32_t n = argc - 2;
uint32_t *a = calloc(n, sizeof(*a));
for (uint32_t i = 0; i < n; ++i) {
a[i] = strtoul(argv[i + 2], NULL, 10);
}
// Obtain the samples.
uint32_t sample;
struct aldr_s x = aldr_preprocess(a, n);
for (uint32_t i = 0; i < num_samples; ++i) {
printf("%d ", aldr_sample(&x));
}
printf("\n");
// Free the heap.
free(a);
aldr_free(x);
return 0;
}