MCPcopy Create free account
hub / github.com/davisking/dlib / split_array

Function split_array

dlib/array/array_tools.h:12–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10{
11 template <typename T>
12 void split_array (
13 T& a,
14 T& b,
15 double frac
16 )
17 {
18 // make sure requires clause is not broken
19 DLIB_ASSERT(0 <= frac && frac <= 1,
20 "\t void split_array()"
21 << "\n\t frac must be between 0 and 1."
22 << "\n\t frac: " << frac
23 );
24
25 const unsigned long asize = static_cast<unsigned long>(a.size()*frac);
26 const unsigned long bsize = a.size()-asize;
27
28 b.resize(bsize);
29 for (unsigned long i = 0; i < b.size(); ++i)
30 {
31 swap(b[i], a[i+asize]);
32 }
33 a.resize(asize);
34 }
35}
36
37#endif // DLIB_ARRAY_tOOLS_H_

Callers 1

test_array_splitFunction · 0.85

Calls 3

swapFunction · 0.70
sizeMethod · 0.45
resizeMethod · 0.45

Tested by 1

test_array_splitFunction · 0.68