diff options
author | Paul Duncan <pabs@pablotron.org> | 2019-02-03 06:07:00 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2019-02-03 06:07:00 -0500 |
commit | d3bf941f12d1ed453250cb74168a9999bda04a74 (patch) | |
tree | 7201fbbf88d18c59a71713a488e79f02a8c62f23 | |
parent | b4324a1d3c9f0152343c8a3f0480125deea5c48c (diff) | |
download | kmeans-d3bf941f12d1ed453250cb74168a9999bda04a74.tar.bz2 kmeans-d3bf941f12d1ed453250cb74168a9999bda04a74.zip |
add km_set_copy()
-rw-r--r-- | km-set.c | 44 | ||||
-rw-r--r-- | km.h | 3 |
2 files changed, 47 insertions, 0 deletions
@@ -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 ) { @@ -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); |