// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/dimreduction.c
// Function: dimension_reduction_lda
Instanceptr dimension_reduction_lda(Datasetptr d, Instanceptr traindata, void* parameters, Datasetptr* new_dataset, char* new_dataset_name)
{
 /*!Last Changed 16.01.2008*/
 int howmany = 0, reversed;
 matrix eigenvectors, sw, sb, W;
 double *eigenvalues;
 Pca_parameterptr ppca = (Pca_parameterptr) parameters;
 Instanceptr newlist;
 sw = within_class_matrix(traindata);
 reversed = matrix_inverse(&sw);
 if (!reversed)
   printf("Matrix inverse problem\n");
 sb = between_class_matrix(traindata);
 W = matrix_multiply(sw, sb);
 matrix_free(sw);
 matrix_free(sb);
 switch (ppca->reduction_type)
  {
   case REDUCTION_TYPE_FEATURE :if (is_symmetric(W))
                                  eigenvalues = find_eigenvalues_eigenvectors_symmetric(&eigenvectors, W);
                                else
                                  eigenvalues = find_eigenvalues_eigenvectors_unsymmetric(&eigenvectors, W);
                                if (ppca->featurecount > d->classno - 1)
                                  howmany = d->classno - 1;
                                else
                                  howmany = ppca->featurecount;
                                break;
   case REDUCTION_TYPE_VARIANCE:if (is_symmetric(W))
                                  eigenvalues = find_eigenvalues_eigenvectors(&eigenvectors, W, &howmany, ppca->variance_explained);
                                else
                                  eigenvalues = find_eigenvalues_eigenvectors_unsymmetric(&eigenvectors, W);
                                break;
  }
 safe_free(eigenvalues);
 newlist = reduce_dimension_of_instancelist(traindata, howmany, eigenvectors);
 *new_dataset = dimension_reduced_dataset(d, howmany + 1, newlist, new_dataset_name);
 matrix_free(eigenvectors);
 matrix_free(W);
 return newlist;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x38(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
andl $0x0, 0xc(%rsp)
movq %rsi, %rdi
callq 0x10f6d
leaq 0x28(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
callq 0x3a9f7
testl %eax, %eax
jne 0x1c1fc
leaq 0x7b786(%rip), %rdi     # 0x9797d
callq 0x4090
movq %r12, %rdi
callq 0x11b8a
movq %rax, %r14
movq %rdx, %r15
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rax, %rdx
movq %r15, %rcx
callq 0x3933d
movq %rax, %r13
movq %rdx, %rbp
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x3929f
movq %r14, %rdi
movq %r15, %rsi
callq 0x3929f
movl 0x10(%rbx), %r14d
movq %r13, %rdi
movq %rbp, %rsi
callq 0x397dd
testl %r14d, %r14d
je 0x1c273
testl %eax, %eax
je 0x1c289
movsd 0x8(%rbx), %xmm0
leaq 0x18(%rsp), %rdi
leaq 0xc(%rsp), %rcx
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3c5f6
jmp 0x1c299
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
testl %eax, %eax
je 0x1c2a0
callq 0x3c5c1
jmp 0x1c2a5
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3c506
movq 0x10(%rsp), %r14
jmp 0x1c2c0
callq 0x3c506
movq 0x10(%rsp), %r14
movl (%rbx), %edx
movl 0x10(%r14), %ecx
cmpl %ecx, %edx
jge 0x1c2ba
movl %edx, 0xc(%rsp)
jmp 0x1c2c0
decl %ecx
movl %ecx, 0xc(%rsp)
movq %rax, %rdi
callq 0x34ff7
movl 0xc(%rsp), %esi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %r12, %rdi
callq 0x1cc2b
movq %rax, %rbx
movl 0xc(%rsp), %esi
incl %esi
movq %r14, %rdi
movq %rax, %rdx
movq 0x38(%rsp), %rcx
callq 0x1414c
movq 0x40(%rsp), %rcx
movq %rax, (%rcx)
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x3929f
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3929f
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq