aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--km-set.c44
-rw-r--r--km.h3
2 files changed, 47 insertions, 0 deletions
diff --git a/km-set.c b/km-set.c
index 58792c0..ca028f8 100644
--- a/km-set.c
+++ b/km-set.c
@@ -180,6 +180,50 @@ km_set_push(
}
bool
+km_set_copy(
+ km_set_t * const dst,
+ const km_set_t * const src
+) {
+ if (src->state != KM_SET_STATE_INIT || src->state != KM_SET_STATE_NORMALIZED) {
+ // return failure
+ return false;
+ }
+
+ // init dst set
+ if (!km_set_init(dst, &(src->shape), src->num_rows)) {
+ // return failure
+ return false;
+ }
+
+ // copy floats
+ const size_t num_floats = src->shape.num_floats;
+ if (num_floats > 0) {
+ const size_t stride = sizeof(float) * num_floats;
+
+ // copy floats
+ memcpy(dst->floats, src->floats, stride * src->num_rows);
+
+ // copy bounds
+ memcpy(dst->bounds, src->bounds, 2 * stride);
+ }
+
+ // copy ints
+ const size_t num_ints = src->shape.num_ints;
+ if (num_ints > 0) {
+ const size_t stride = sizeof(int) * num_ints;
+
+ // copy ints
+ memcpy(dst->ints, src->ints, stride * src->num_rows);
+ }
+
+ // increment row count
+ dst->num_rows = src->num_rows;
+
+ // return success
+ return true;
+}
+
+bool
km_set_normalize(
km_set_t * const set
) {
diff --git a/km.h b/km.h
index 1d00d50..9a58a6d 100644
--- a/km.h
+++ b/km.h
@@ -64,6 +64,9 @@ void km_set_fini(km_set_t * const);
// append rows to data set, growing set if necessary
_Bool km_set_push(km_set_t *, const size_t, const float *, const int *);
+// deep copy data set
+_Bool km_set_copy(km_set_t * const, const km_set_t * const);
+
// normalize data set
_Bool km_set_normalize(km_set_t * const);