summaryrefslogtreecommitdiffstats
path: root/ml/dlib/dlib/array/array_tools.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:20:02 +0000
commit58daab21cd043e1dc37024a7f99b396788372918 (patch)
tree96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /ml/dlib/dlib/array/array_tools.h
parentReleasing debian version 1.43.2-1. (diff)
downloadnetdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz
netdata-58daab21cd043e1dc37024a7f99b396788372918.zip
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ml/dlib/dlib/array/array_tools.h')
-rw-r--r--ml/dlib/dlib/array/array_tools.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/ml/dlib/dlib/array/array_tools.h b/ml/dlib/dlib/array/array_tools.h
new file mode 100644
index 000000000..fce634396
--- /dev/null
+++ b/ml/dlib/dlib/array/array_tools.h
@@ -0,0 +1,38 @@
+// Copyright (C) 2013 Davis E. King (davis@dlib.net)
+// License: Boost Software License See LICENSE.txt for the full license.
+#ifndef DLIB_ARRAY_tOOLS_H_
+#define DLIB_ARRAY_tOOLS_H_
+
+#include "../assert.h"
+#include "array_tools_abstract.h"
+
+namespace dlib
+{
+ template <typename T>
+ void split_array (
+ T& a,
+ T& b,
+ double frac
+ )
+ {
+ // make sure requires clause is not broken
+ DLIB_ASSERT(0 <= frac && frac <= 1,
+ "\t void split_array()"
+ << "\n\t frac must be between 0 and 1."
+ << "\n\t frac: " << frac
+ );
+
+ const unsigned long asize = static_cast<unsigned long>(a.size()*frac);
+ const unsigned long bsize = a.size()-asize;
+
+ b.resize(bsize);
+ for (unsigned long i = 0; i < b.size(); ++i)
+ {
+ swap(b[i], a[i+asize]);
+ }
+ a.resize(asize);
+ }
+}
+
+#endif // DLIB_ARRAY_tOOLS_H_
+