// File: /workspace/github_cpp_makefile_star2_O2/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 $0x1448, %rsp           # imm = 0x1448
movq %rdi, %rbx
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
callq 0x53b6
movq %r14, %rdi
callq 0x2280
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
divl %ecx
cmpl $0x1, %edx
adcl $0x0, %edx
leaq 0x80(%rsp), %rsi
movq %rdx, (%rsi)
movl 0x4(%rbx), %eax
decl %eax
leaq 0x88(%rsp), %rdi
andl $0x0, (%rdi)
movl %eax, 0x4(%rdi)
callq 0x6558
leaq 0x48(%rbx), %rdi
movslq %eax, %rsi
movq %rdi, 0x20(%rsp)
callq 0x4200
leaq 0x30(%rbx), %rdi
movq %rdi, 0x48(%rsp)
movq %rax, %rsi
callq 0x2ee2
pushq $0x1
popq %rcx
leaq 0xa8(%rsp), %rbp
leaq 0x90(%rsp), %r13
movslq (%rbx), %rax
cmpq %rax, %rcx
jge 0x7797
movq %rcx, %r14
movslq 0x4(%rbx), %rsi
movabsq $0x41dfffffffc00000, %rax # imm = 0x41DFFFFFFFC00000
movq %rax, 0x30(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x30(%rsp), %r15
movq %r15, %rdx
leaq 0x50(%rsp), %r12
movq %r12, %rcx
callq 0x530e
movslq 0x4(%rbx), %rsi
andq $0x0, 0x50(%rsp)
movq %r15, %rdi
movq %r12, %rdx
leaq 0x13(%rsp), %rcx
callq 0x530e
xorl %r12d, %r12d
movslq 0x4(%rbx), %rsi
cmpq %rsi, %r12
jge 0x769a
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x4200
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x31d2
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rsi
movq %r15, %rdx
callq 0x7f6a
cmpq 0x38(%rbx), %rax
je 0x75c4
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x5414
andq $0x0, (%rax)
testq %r12, %r12
je 0x7658
leaq -0x1(%r12), %rsi
leaq 0x30(%rsp), %rdi
callq 0x5414
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x5414
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x5414
movsd 0x18(%rsp), %xmm0
mulsd %xmm0, %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0x7684
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x7569
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x4200
movq %rbp, %rdi
movq %rax, %rsi
callq 0x31d2
movq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0x4200
movq %r13, %rdi
movq %rax, %rsi
callq 0x31d2
movl 0x8(%rbx), %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x7f34
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
callq 0x2f86
movq %rbp, %rdi
callq 0x2f86
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x5414
movsd 0x8(%rsp), %xmm0
ucomisd (%rax), %xmm0
jae 0x7650
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x5414
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
incq %r15
jmp 0x75c7
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
callq 0x5414
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x5414
movsd 0x8(%rsp), %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x50(%rsp), %rdi
callq 0x2f86
incq %r12
jmp 0x7518
decq %rsi
leaq 0x30(%rsp), %rdi
callq 0x5414
movsd (%rax), %xmm0
andq $0x0, 0x50(%rsp)
movsd %xmm0, 0x58(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x540c
movsd %xmm0, 0x8(%rsp)
xorl %r15d, %r15d
movslq 0x4(%rbx), %rax
cmpq %rax, %r15
jge 0x76f9
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x5414
movsd 0x8(%rsp), %xmm0
ucomisd (%rax), %xmm0
jb 0x76fe
incq %r15
jmp 0x76d2
pushq $-0x1
popq %rax
jmp 0x7701
movl %r15d, %eax
leal -0x1(%r15), %ecx
movq %rcx, 0x18(%rsp)
movl %eax, 0x2c(%rsp)
movl %eax, 0x14(%rsp)
cmpq $0x2, %r15
jb 0x7751
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x5414
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq 0x5414
movsd 0x8(%rsp), %xmm0
ucomisd (%rax), %xmm0
jne 0x7757
decl 0x14(%rsp)
jmp 0x7712
movl 0x2c(%rsp), %eax
jmp 0x775b
movl 0x14(%rsp), %eax
testl %eax, %eax
jle 0x77b6
movl %eax, %esi
movq 0x20(%rsp), %rdi
callq 0x4200
movq 0x48(%rsp), %rdi
movq %rax, %rsi
callq 0x2ee2
leaq 0x30(%rsp), %rdi
callq 0x2f86
leaq 0x68(%rsp), %rdi
callq 0x2f86
movq %r14, %rcx
incq %rcx
jmp 0x74bf
leaq 0xc0(%rsp), %rdi
callq 0x5466
addq $0x1448, %rsp           # imm = 0x1448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2ee5(%rip), %rdi      # 0xa6a2
leaq 0x2ba6(%rip), %rsi      # 0xa36a
leaq 0x2ee3(%rip), %rcx      # 0xa6ae
movl $0x10e, %edx            # imm = 0x10E
callq 0x2170
jmp 0x77dd
jmp 0x77dd
jmp 0x77ef
jmp 0x77ef
movq %rax, %rbx
jmp 0x783b
movq %rax, %rbx
jmp 0x7831
jmp 0x77ef
jmp 0x77ef
jmp 0x781a
jmp 0x77ef
movq %rax, %rbx
jmp 0x7827
jmp 0x781a
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x2f86
jmp 0x780b
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x2f86
jmp 0x781d
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x2f86
leaq 0x30(%rsp), %rdi
callq 0x2f86
leaq 0x68(%rsp), %rdi
callq 0x2f86
leaq 0xc0(%rsp), %rdi
callq 0x5466
movq %rbx, %rdi
callq 0x23b0