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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <stdbool.h> // bool
#include <stdio.h> // fprintf()
#include "util.h"
#include "km.h"
static bool
km_set_print_bounds(
const float * const bounds,
const size_t num_floats,
FILE * const fh
) {
if (bounds) {
fprintf(fh, "2 0\n");
for (size_t i = 0; i < num_floats; i++) {
fprintf(fh, "%f %f\n", bounds[i], bounds[num_floats + i]);
}
}
// return success
return true;
}
bool
km_set_print(
const km_set_t * const set,
const float * const bounds,
FILE * const fh
) {
const size_t num_floats = set->shape.num_floats;
if (!km_set_print_bounds(bounds, num_floats, fh)) {
// return failure
return false;
}
// print shape
fprintf(fh, "%zu %zu\n", num_floats, set->shape.num_ints);
// print rows
for (size_t i = 0; i < set->num_rows; i++) {
if (num_floats > 0) {
const float * const vals = km_set_get_row(set, i);
// print floats
for (size_t j = 0; j < num_floats; j++) {
fprintf(fh, "%s%f", (j > 0) ? " ": "", vals[j]);
}
}
// print ints
if (set->shape.num_ints > 0) {
const int * const vals = km_set_get_row_ints(set, i);
for (size_t j = 0; j < set->shape.num_ints; j++) {
const bool need_space = (num_floats > 0) || (j > 0);
fprintf(fh, "%s%d", need_space ? " ": "", vals[j]);
}
}
// end row
fprintf(fh, "\n");
}
// return success
return true;
}
|