// File: /workspace/github_cpp_makefile_star2_O3/xbai0624[P]dnn/src/DataInterface.cpp
// Function: DataInterface::loadFile(char const*, std::vector<Matrix, std::allocator<Matrix>>&)
void DataInterface::loadFile(const char* path, std::vector<Matrix> &contents)
{
    // this only for code development, it reads data in ./test_data/ directory
    fstream f(path, fstream::in);
    if(!f.is_open()) 
    {
        std::cout<<__func__<<" Error: Cannot open file: "<<path<<std::endl;
        exit(0);
    }

    string line;
    while(getline(f, line))
    {
        istringstream iss(line);
        string tmp;
        vector<double> vec;
        while(iss>>tmp)
        {
            if(tmp.size() > 0) 
            {
                double a = stod(tmp);
                vec.push_back(a);
            }
        }
        assert(vec.size() == 27);

        size_t horizontal = 10;
        size_t vertical = 10;
        if(__dataDimensionFromParameter.first > 0)
        {
            // if data dimension is set using the constructor parameter, then use it
            horizontal = sqrt((int)__dataDimensionFromParameter.first * (int)__dataDimensionFromParameter.second);
            vertical = horizontal;
        }
        Matrix m(horizontal, vertical); // 
        for(size_t i=0;i<vec.size();i+=3)
        {
            size_t ii = vec[i];
            size_t jj = vec[i+1];
            assert(ii<horizontal && jj < vertical);
            double val = vec[i+2];

            m[ii][jj] = val;
        }

        Matrix _mm = m.Reshape(__dataDimensionFromParameter.first, __dataDimensionFromParameter.second);
        //Matrix mm = _mm.Normalization();
        contents.push_back(_mm);
    }

    // *** implement the image dimension
    assert(__gLayerDimension != LayerDimension::Undefined); // make sure 1D or 2D interface
    auto dim = contents[0].Dimension();
    if(__gLayerDimension == LayerDimension::_1D)
    {
        __dataDimension.second = 1;
        __dataDimension.first = dim.first * dim.second;
    }
    else 
    {
        __dataDimension = dim;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rdx, 0x18(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x98(%rsp), %r12
movq %r12, %rdi
movl $0x8, %edx
callq 0x42b0
leaq 0x118(%rsp), %rdi
callq 0x4080
testb %al, %al
je 0x19603
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x2a8(%rsp), %rbp
leaq 0x80(%rsp), %r15
movq %r14, %rbx
movq 0x98(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4250
movsbl %al, %edx
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x4410
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x1953b
movq %rbp, %rdi
leaq 0x48(%rsp), %rsi
movl $0x8, %edx
callq 0x4390
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
xorl %eax, %eax
movq %rax, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq %rax, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x42a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x19388
cmpq $0x0, 0x28(%rsp)
je 0x192e2
movq 0x20(%rsp), %r12
callq 0x4040
movq %rax, %r14
movl (%rax), %r13d
movl $0x0, (%rax)
movq %r12, %rdi
movq %r15, %rsi
callq 0x41c0
cmpq %r12, 0x80(%rsp)
je 0x195cc
movl (%r14), %eax
testl %eax, %eax
je 0x19349
cmpl $0x22, %eax
jne 0x1934c
jmp 0x195d8
movl %r13d, (%r14)
movsd %xmm0, 0x68(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x19373
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
movq %rbx, %r14
jmp 0x192e2
movq %rsp, %rdi
leaq 0x68(%rsp), %rdx
callq 0x17694
movq %rbx, %r14
jmp 0x192e2
movq 0x8(%rsp), %rax
subq (%rsp), %rax
cmpq $0xd8, %rax
jne 0x195e4
movq 0x80(%r14), %rax
testq %rax, %rax
je 0x193c8
imull 0x88(%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
ucomisd 0xe1d0(%rip), %xmm0     # 0x27590
jb 0x193d0
sqrtsd %xmm0, %xmm0
jmp 0x193d5
movl $0xa, %r14d
jmp 0x193f4
callq 0x4438
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0xe1df(%rip), %xmm0     # 0x275c8
cvttsd2si %xmm0, %r14
andq %rcx, %r14
orq %rax, %r14
movq %r15, %rdi
movq %r14, %rsi
movq %r14, %rdx
callq 0x1a76e
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x194b2
xorl %r12d, %r12d
movsd (%rax,%r12,8), %xmm0
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
movsd 0xe19e(%rip), %xmm1     # 0x275c8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
cmpq %rsi, %r14
jbe 0x195ad
movsd 0x8(%rax,%r12,8), %xmm0
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %r13
sarq $0x3f, %rdx
andq %rdx, %r13
orq %rcx, %r13
cmpq %r13, %r14
jbe 0x195ad
movsd 0x10(%rax,%r12,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r15, %rdi
callq 0x1adb2
movq (%rax), %rax
movsd 0x40(%rsp), %xmm0
movsd %xmm0, (%rax,%r13,8)
addq $0x3, %r12
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %r12
jb 0x19414
movq %rbx, %r14
movq 0x80(%rbx), %rdx
movq 0x88(%rbx), %rcx
leaq 0x68(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x1c0d2
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x138a4
leaq 0x98(%rsp), %r12
movq %r13, %rdi
callq 0x1abf2
movq %r15, %rdi
callq 0x1abf2
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x19506
callq 0x4230
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x1951a
callq 0x4230
movq %rbp, %rdi
movq 0x1daa4(%rip), %rsi     # 0x36fc8
callq 0x42f0
leaq 0x320(%rsp), %rdi
callq 0x40b0
jmp 0x19271
cmpl $0x2, 0xc0(%r14)
je 0x19651
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0x1abb8
cmpl $0x0, 0xc0(%r14)
movl $0x1, %ecx
movq %rdx, %rsi
cmoveq %rcx, %rsi
cmoveq %rdx, %rcx
imulq %rcx, %rax
movq %rsi, 0x78(%r14)
movq %rax, 0x70(%r14)
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x1958e
callq 0x4230
leaq 0x98(%rsp), %rdi
callq 0x4070
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x107ec(%rip), %rdi     # 0x29da0
leaq 0x1060e(%rip), %rsi     # 0x29bc9
leaq 0x1079c(%rip), %rcx     # 0x29d5e
movl $0x105, %edx            # imm = 0x105
callq 0x4160
leaq 0x1081b(%rip), %rdi     # 0x29dee
callq 0x4150
leaq 0x1080f(%rip), %rdi     # 0x29dee
callq 0x4300
leaq 0x10762(%rip), %rdi     # 0x29d4d
leaq 0x105d7(%rip), %rsi     # 0x29bc9
leaq 0x10765(%rip), %rcx     # 0x29d5e
movl $0xf6, %edx
callq 0x4160
movq 0x1d9ce(%rip), %rdi     # 0x36fd8
leaq 0x10718(%rip), %rsi     # 0x29d29
movl $0x8, %edx
callq 0x4280
movq 0x1d9b6(%rip), %rdi     # 0x36fd8
leaq 0x10709(%rip), %rsi     # 0x29d32
movl $0x1a, %edx
callq 0x4280
movq 0x1d99e(%rip), %rdi     # 0x36fd8
movq %rbx, %rsi
callq 0x4260
movq %rax, %rdi
callq 0x4100
xorl %edi, %edi
callq 0x4290
leaq 0x10767(%rip), %rdi     # 0x29dbf
leaq 0x1056a(%rip), %rsi     # 0x29bc9
leaq 0x106f8(%rip), %rcx     # 0x29d5e
movl $0x111, %edx            # imm = 0x111
callq 0x4160
movq %rax, %rbx
jmp 0x19710
jmp 0x1968f
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x1abf2
jmp 0x19699
jmp 0x19696
jmp 0x196b6
jmp 0x1968f
movq %rax, %rbx
jmp 0x196fc
jmp 0x196b6
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x1abf2
jmp 0x196b9
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x196b9
movl %r13d, (%r14)
jmp 0x196b9
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x196c7
callq 0x4230
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x196db
callq 0x4230
movq 0x1d8e6(%rip), %rsi     # 0x36fc8
leaq 0x2a8(%rsp), %rdi
callq 0x42f0
leaq 0x320(%rsp), %rdi
callq 0x40b0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x19710
callq 0x4230
leaq 0x98(%rsp), %rdi
callq 0x4070
movq %rbx, %rdi
callq 0x43e0
nop