// File: /workspace/github_cpp_makefile_star2_O1/nikosgalanis[P]Vectors-Similarity-Search-and-Clustering/programs/Clustering/../../algorithms/Clustering/clustering.h
// Function: Clustering<double>::initialization()
void initialization(void) {
		// chose a first index randomly
		std::random_device mch;
		std::default_random_engine generator(mch());
		std::uniform_int_distribution<int> distribution_int(0,n_points - 1);
		int index = distribution_int(generator);
		// this is our first centroid
		centroids.push_back(feature_vectors.at(index));
			// find the other centroids with the algorithm init++
			for (int t = 1; t < k; t++) {
				// define a distance vector
				vector<T> D(n_points, INT_MAX);
				// define a vector of the partial sums
				vector<T> P(n_points, 0);
				// for every point
				for (int i = 0; i < n_points; i++) {
					// check if it is centroid
					vector<T> curr = feature_vectors.at(i);
					if (std::find(centroids.begin(), centroids.end(), curr) == centroids.end()) {
						//compute D(i)
						for (int j = 0; j < t; j++) {
							T dist = metrics::ManhatanDistance(feature_vectors.at(i), centroids.at(j), space_dim);
							if (dist < D.at(i))
								D.at(i) = dist;
						}
					} else {
						// if it is a centroid, set its D value to 0
						D.at(i) = 0;
					}
					// compute the partial sums effectively
					if (i == 0)
						P.at(i) = pow(D.at(0), 2);
					else 
						P.at(i) = P.at(i - 1) + pow(D.at(i), 2);
				}
				//pick a uniformly distributed x
				std::uniform_real_distribution<double> distribution_real(0, P.at(n_points -1));
				double x = distribution_real(generator);

				// find its correct position
				int r_index = -1;
				int i = 0;
				for (i = 0; i < n_points; i++) {
					if (P.at(i) > (T)x) {
						r_index = i;
						break;
					}
				}
				// ensure that the point is not a csntroid
				while ((i - 1 > 0) && P.at(i) == P.at(i - 1)) {
					r_index--;
				}
				assert(r_index > 0);
				// now the r_index has a correct value, so its our new centroid
				centroids.push_back(feature_vectors.at(r_index));
			}
		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1428, %rsp           # imm = 0x1428
movq %rdi, %rbx
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
callq 0x65de
movq %r14, %rdi
callq 0x2310
movl %eax, %ecx
leaq (%rcx,%rcx,2), %rcx
shrq $0x20, %rcx
movl %eax, %edx
subl %ecx, %edx
shrl %edx
addl %ecx, %edx
shrl $0x1e, %edx
movl %edx, %ecx
shll $0x1f, %ecx
orl %edx, %ecx
leal (%rax,%rcx), %edx
cmpl $0x1, %edx
adcl %eax, %ecx
leaq 0x60(%rsp), %rsi
movq %rcx, (%rsi)
movl 0x4(%rbx), %eax
decl %eax
leaq 0x98(%rsp), %rdi
movl $0x0, (%rdi)
movl %eax, 0x4(%rdi)
movq %rdi, %rdx
callq 0x79dc
movslq %eax, %rsi
movq 0x48(%rbx), %rax
movq 0x50(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x894e
leaq 0x30(%rbx), %rdi
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
movq %rdi, 0x58(%rsp)
callq 0x35ec
cmpl $0x2, (%rbx)
jl 0x889b
movl $0x1, %r15d
leaq 0x10(%rsp), %r14
movslq 0x4(%rbx), %rsi
movabsq $0x41dfffffffc00000, %rax # imm = 0x41DFFFFFFFC00000
movq %rax, 0x10(%rsp)
leaq 0x28(%rsp), %rdi
movq %r14, %rdx
leaq 0x40(%rsp), %r12
movq %r12, %rcx
callq 0x643c
movslq 0x4(%rbx), %rsi
movq $0x0, 0x40(%rsp)
movq %r14, %rdi
movq %r12, %rdx
leaq 0x7(%rsp), %rcx
callq 0x643c
movl 0x4(%rbx), %eax
testl %eax, %eax
jle 0x876f
xorl %r12d, %r12d
leaq 0x40(%rsp), %r14
movq 0x48(%rbx), %rax
movq 0x50(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r12, %rdx
jbe 0x88dc
leaq (%r12,%r12,2), %rbp
leaq (%rax,%rbp,8), %rsi
movq %r14, %rdi
callq 0x3900
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rsi
movq %r14, %rdx
callq 0x953e
cmpq 0x38(%rbx), %rax
je 0x85a0
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r12, %rdx
jbe 0x890b
movq $0x0, (%rax,%r12,8)
jmp 0x86a9
xorl %r14d, %r14d
movq 0x48(%rbx), %rax
movq 0x50(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r12, %rdx
jbe 0x88ba
leaq (%rax,%rbp,8), %rsi
leaq 0x68(%rsp), %rdi
callq 0x3900
movq 0x30(%rbx), %rax
movq 0x38(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r14, %rdx
jbe 0x88cb
leaq (%r14,%r14,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x80(%rsp), %rdi
callq 0x3900
movslq 0x8(%rbx), %rax
testq %rax, %rax
jle 0x863e
movq 0x68(%rsp), %rcx
xorpd %xmm2, %xmm2
movq 0x80(%rsp), %rdx
xorl %esi, %esi
movapd 0x2bee(%rip), %xmm1     # 0xb210
movsd (%rcx,%rsi,8), %xmm0
subsd (%rdx,%rsi,8), %xmm0
andpd %xmm1, %xmm0
addsd %xmm0, %xmm2
incq %rsi
cmpq %rsi, %rax
jne 0x8622
jmp 0x8642
xorpd %xmm2, %xmm2
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
movsd %xmm2, 0x8(%rsp)
je 0x8660
callq 0x2260
movsd 0x8(%rsp), %xmm2
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x8675
callq 0x2260
movsd 0x8(%rsp), %xmm2
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r12, %rdx
jbe 0x88ba
ucomisd (%rax,%r12,8), %xmm2
jae 0x869d
movsd %xmm2, (%rax,%r12,8)
incq %r14
cmpq %r15, %r14
jne 0x85a3
testq %r12, %r12
je 0x870e
leaq -0x1(%r12), %rdx
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rdx, %rcx
leaq 0x40(%rsp), %r14
jbe 0x88ed
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
cmpq %r12, %rdx
jbe 0x890b
cmpq %r12, %rcx
jbe 0x88f0
movsd (%rsi,%r12,8), %xmm0
mulsd %xmm0, %xmm0
addsd -0x8(%rax,%r12,8), %xmm0
movsd %xmm0, (%rax,%r12,8)
jmp 0x874b
movq 0x28(%rsp), %rax
cmpq %rax, 0x30(%rsp)
leaq 0x40(%rsp), %r14
je 0x8906
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %r12, %rdx
jbe 0x890b
movsd (%rax), %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, (%rcx,%r12,8)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x875a
callq 0x2260
incq %r12
movslq 0x4(%rbx), %rax
cmpq %rax, %r12
jl 0x8537
leaq 0x10(%rsp), %r14
decl %eax
movslq %eax, %rsi
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x891c
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x6648
movl 0x4(%rbx), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %edx, %edx
jle 0x87e4
mulsd 0x8(%rsp), %xmm0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
sarq $0x3, %rsi
xorl %ecx, %ecx
cmpq %rcx, %rsi
je 0x88f5
ucomisd (%rdi,%rcx,8), %xmm0
jb 0x87e8
incq %rcx
cmpq %rcx, %rdx
jne 0x87c8
movl %edx, %ecx
jmp 0x87ea
xorl %ecx, %ecx
jmp 0x87ea
movl %ecx, %eax
cmpl $0x2, %ecx
jb 0x8834
movl %ecx, %esi
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x88f8
leal -0x1(%rcx), %r8d
cmpq %r8, %rdx
jbe 0x8949
movsd (%rdi,%rsi,8), %xmm0
movsd (%rdi,%r8,8), %xmm1
movl %eax, %edx
ucomisd %xmm1, %xmm0
jne 0x8834
decl %edx
cmpl $0x1, %ecx
ja 0x8825
jmp 0x8836
movl %eax, %edx
testl %edx, %edx
jle 0x892a
movl %edx, %esi
movq 0x48(%rbx), %rax
movq 0x50(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x88f8
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
movq 0x58(%rsp), %rdi
callq 0x35ec
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x887d
callq 0x2260
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x888c
callq 0x2260
incq %r15
movslq (%rbx), %rax
cmpq %rax, %r15
jl 0x84df
leaq 0xa0(%rsp), %rdi
callq 0x2250
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2a84(%rip), %rdi      # 0xb345
movq %r12, %rsi
xorl %eax, %eax
callq 0x2370
leaq 0x2a73(%rip), %rdi      # 0xb345
movq %r14, %rsi
xorl %eax, %eax
callq 0x2370
leaq 0x2a62(%rip), %rdi      # 0xb345
movq %r12, %rsi
xorl %eax, %eax
callq 0x2370
movq %rdx, %r12
movq %rcx, %rdx
jmp 0x890b
movq %rsi, %rdx
leaq 0x2a46(%rip), %rdi      # 0xb345
xorl %eax, %eax
callq 0x2370
xorl %r12d, %r12d
xorl %edx, %edx
leaq 0x2a33(%rip), %rdi      # 0xb345
movq %r12, %rsi
xorl %eax, %eax
callq 0x2370
leaq 0x2a22(%rip), %rdi      # 0xb345
xorl %eax, %eax
callq 0x2370
leaq 0x2deb(%rip), %rdi      # 0xb71c
leaq 0x2aac(%rip), %rsi      # 0xb3e4
leaq 0x2de9(%rip), %rcx      # 0xb728
movl $0x10e, %edx            # imm = 0x10E
callq 0x21a0
movq %r8, %rsi
jmp 0x88f8
leaq 0x29f0(%rip), %rdi      # 0xb345
xorl %eax, %eax
callq 0x2370
jmp 0x89dc
jmp 0x8968
jmp 0x8968
jmp 0x8976
jmp 0x8976
jmp 0x8976
movq %rax, %rbx
jmp 0x89c7
movq %rax, %rbx
jmp 0x89b8
jmp 0x8976
jmp 0x8976
movq %rax, %rbx
jmp 0x89a9
jmp 0x8997
jmp 0x8997
jmp 0x8981
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x899a
callq 0x2260
jmp 0x899a
jmp 0x8997
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x89a9
callq 0x2260
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x89b8
callq 0x2260
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x89c7
callq 0x2260
leaq 0xa0(%rsp), %rdi
callq 0x2250
movq %rbx, %rdi
callq 0x2450
movq %rax, %rdi
callq 0x3657