// File: /workspace/github_cpp_makefile_star2_O2/ghulette[P]neural-net-openmp/dataset.cpp
// Function: DataSet::DataSet(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
DataSet::DataSet(std::string idx_image_file, std::string idx_label_file, int output_enc) {
	using namespace std;
	
	IdxData *image_idx = new IdxData(idx_image_file);
	IdxData *label_idx = new IdxData(idx_label_file);
	
	if(image_idx->num_records() != label_idx->num_records()) {
		cerr << "Image and label files have differing lengths" << endl;
		exit(1);
	}
	num_entries = image_idx->num_records();
	image_data_length = image_idx->record_size();
	
	switch(output_enc) {
		case OUTPUT_ASCII:
			label_data_length = ASCII_LENGTH;
			break;
		case OUTPUT_PACKED:
			label_data_length = PACKED_LENGTH;
			break;
		case OUTPUT_FULL:
			label_data_length = FULL_LENGTH;
			break;
		default:
			cerr << "Error: Output encoding " << output_enc << " not supported." << endl;
			exit(1);
	}
	
	image_data = new double *[num_entries];
	label_data = new double *[num_entries];
	labels = new int[num_entries];
	
	for(int i=0; i < num_entries; i ++) {
		// Label digit
		labels[i] = int(label_idx->record(i)[0]);
		
		// Label output vector
		switch(output_enc) {
			case OUTPUT_ASCII:
				label_data[i] = vector_for_label_ascii(labels[i]);
				break;
			case OUTPUT_PACKED:
				label_data[i] = vector_for_label_packed(labels[i]);
				break;
			case OUTPUT_FULL:
				label_data[i] = vector_for_label_full(labels[i]);
				break;
		}
		
		// Image vector (rescaled from 0-255 to 0.0-1.0)
		image_data[i] = new double[image_idx->record_size()];
		unsigned char *idx_img = image_idx->record(i);
		for(int j=0; j < image_data_length; j++) {
			image_data[i][j] = double(idx_img[j]) / 255.0;
		}
	}
	
	delete image_idx;
	delete label_idx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
pushq $0x10
popq %rdi
callq 0x2110
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x2160
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x2ca0
leaq 0x28(%rsp), %rdi
callq 0x21f8
pushq $0x10
popq %rdi
callq 0x2110
movq %rax, %r15
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x2160
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2ca0
leaq 0x8(%rsp), %rdi
callq 0x21f8
movq %rbx, %rdi
callq 0x2e20
movl %eax, %r12d
movq %r15, %rdi
callq 0x2e20
cmpl %eax, %r12d
jne 0x29ef
movq %rbx, %rdi
callq 0x2e20
movl %eax, (%r14)
movq %rbx, %rdi
callq 0x2e24
movl %eax, 0x4(%r14)
cmpl $0x3, %ebp
jae 0x29ff
movl %ebp, %eax
leaq 0x1848(%rip), %rcx      # 0x40f4
movl (%rcx,%rax,4), %eax
movl %eax, 0x8(%r14)
movslq (%r14), %r13
leaq (,%r13,8), %r12
testq %r13, %r13
pushq $-0x1
popq %rax
cmovsq %rax, %r12
leaq (,%r13,4), %rcx
cmovsq %rax, %rcx
movq %rcx, (%rsp)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x10(%r14)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x18(%r14)
movq (%rsp), %rdi
callq 0x2030
movq %rax, 0x20(%r14)
xorl %r12d, %r12d
movslq %r13d, %rax
cmpq %rax, %r12
jge 0x29b6
movq %r15, %rdi
movl %r12d, %esi
callq 0x2e28
movzbl (%rax), %edi
movq 0x20(%r14), %rax
movl %edi, (%rax,%r12,4)
cmpl $0x2, %ebp
je 0x293e
cmpl $0x1, %ebp
je 0x2937
testl %ebp, %ebp
jne 0x294b
callq 0x247c
jmp 0x2943
callq 0x24db
jmp 0x2943
callq 0x2531
movq 0x18(%r14), %rcx
movq %rax, (%rcx,%r12,8)
movq %rbx, %rdi
callq 0x2e24
movl %eax, %edi
shlq $0x3, %rdi
testl %eax, %eax
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq 0x10(%r14), %rcx
movq %rax, (%rcx,%r12,8)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x2e28
movslq 0x4(%r14), %rcx
movq 0x10(%r14), %rdx
xorl %esi, %esi
movsd 0x168c(%rip), %xmm1     # 0x4018
cmpq %rcx, %rsi
jge 0x29ab
movzbl (%rax,%rsi), %edi
cvtsi2sd %edi, %xmm0
divsd %xmm1, %xmm0
movq (%rdx,%r12,8), %rdi
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
jmp 0x298c
incq %r12
movl (%r14), %r13d
jmp 0x2900
movq %rbx, %rdi
callq 0x2e12
pushq $0x10
popq %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2120
movq %r15, %rdi
callq 0x2e12
movq %r15, %rdi
movq %r14, %rsi
callq 0x2120
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x35fa(%rip), %rdi      # 0x5ff0
leaq 0x168f(%rip), %rsi      # 0x408c
jmp 0x2a26
movq 0x35ea(%rip), %rdi      # 0x5ff0
leaq 0x16ac(%rip), %rsi      # 0x40b9
callq 0x2100
movq %rax, %rdi
movl %ebp, %esi
callq 0x2190
leaq 0x16ae(%rip), %rsi      # 0x40d1
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2090
pushq $0x1
popq %rdi
callq 0x2130
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x21f8
jmp 0x2a4d
movq %rax, %r14
movq %r15, %rbx
jmp 0x2a64
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x21f8
jmp 0x2a64
movq %rax, %r14
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x2120
movq %r14, %rdi
callq 0x21a0
nop