aboutsummaryrefslogtreecommitdiff
path: root/km-set.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-02-03 06:07:00 -0500
committerPaul Duncan <pabs@pablotron.org>2019-02-03 06:07:00 -0500
commitd3bf941f12d1ed453250cb74168a9999bda04a74 (patch)
tree7201fbbf88d18c59a71713a488e79f02a8c62f23 /km-set.c
parentb4324a1d3c9f0152343c8a3f0480125deea5c48c (diff)
downloadkmeans-d3bf941f12d1ed453250cb74168a9999bda04a74.tar.bz2
kmeans-d3bf941f12d1ed453250cb74168a9999bda04a74.zip
add km_set_copy()
Diffstat (limited to 'km-set.c')
-rw-r--r--km-set.c44
1 files changed, 44 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
) {