// File: /workspace/github_cpp_makefile_star2_O2/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 $0x438, %rsp            # imm = 0x438
movq %rdx, 0x20(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xa8(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x4280
leaq 0x128(%rsp), %rdi
callq 0x4080
testb %al, %al
je 0x16951
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x58(%rsp), %r15
leaq 0x2b8(%rsp), %r13
leaq 0x38(%rsp), %rbp
movq %rsp, %r12
leaq 0x78(%rsp), %r14
movq %rbx, 0x28(%rsp)
leaq 0xa8(%rsp), %rdi
movq %r15, %rsi
callq 0x4060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x168af
movq %r13, %rdi
movq %r15, %rsi
pushq $0x8
popq %rdx
callq 0x4370
leaq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
andq $0x0, 0x40(%rsp)
movb $0x0, 0x48(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4270
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x16733
cmpq $0x0, 0x40(%rsp)
je 0x166f5
movq %rbp, %rdi
xorl %esi, %esi
callq 0x17063
movsd %xmm0, 0x78(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x11d08
jmp 0x166f5
movq 0x8(%rsp), %rax
subq (%rsp), %rax
cmpq $0xd8, %rax
jne 0x16932
movq 0x80(%rbx), %rax
pushq $0xa
popq %r12
testq %rax, %rax
je 0x16797
imull 0x88(%rbx), %eax
cvtsi2sd %eax, %xmm0
ucomisd 0xadb5(%rip), %xmm0     # 0x21520
jb 0x16773
sqrtsd %xmm0, %xmm0
jmp 0x16778
callq 0x43f8
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0xadcc(%rip), %xmm0     # 0x21558
cvttsd2si %xmm0, %r12
andq %rcx, %r12
orq %rax, %r12
movq %r14, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0x176e6
xorl %ebx, %ebx
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %rbx
jae 0x16847
movsd (%rax,%rbx,8), %xmm0
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
movsd 0xad83(%rip), %xmm1     # 0x21558
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
cmpq %rsi, %r12
jbe 0x16913
movsd 0x8(%rax,%rbx,8), %xmm0
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %r15
sarq $0x3f, %rdx
andq %rdx, %r15
orq %rcx, %r15
cmpq %r15, %r12
jbe 0x16913
movsd 0x10(%rax,%rbx,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r14, %rdi
callq 0x17c46
movq (%rax), %rax
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax,%r15,8)
addq $0x3, %rbx
jmp 0x167a7
movq 0x28(%rsp), %rbx
movq 0x80(%rbx), %rdx
movq 0x88(%rbx), %rcx
leaq 0x90(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x18a0c
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x1139c
leaq 0x58(%rsp), %r15
movq %r12, %rdi
movq %rsp, %r12
callq 0x17a9a
movq %r14, %rdi
callq 0x17a9a
movq %r12, %rdi
callq 0x127dc
movq %rbp, %rdi
callq 0x4100
movq %r13, %rdi
callq 0x4120
jmp 0x166a1
cmpl $0x2, 0xc0(%rbx)
je 0x1698d
movq 0x20(%rsp), %rax
movq (%rax), %rdi
callq 0x17a6a
cmpl $0x0, 0xc0(%rbx)
pushq $0x1
popq %rcx
movq %rdx, %rsi
cmoveq %rcx, %rsi
cmoveq %rdx, %rcx
imulq %rcx, %rax
movq %rsi, 0x78(%rbx)
movq %rax, 0x70(%rbx)
leaq 0x58(%rsp), %rdi
callq 0x4100
leaq 0xa8(%rsp), %rdi
callq 0x4070
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd41e(%rip), %rdi      # 0x23d38
leaq 0xd240(%rip), %rsi      # 0x23b61
leaq 0xd3ce(%rip), %rcx      # 0x23cf6
movl $0x105, %edx            # imm = 0x105
callq 0x4180
leaq 0xd3ac(%rip), %rdi      # 0x23ce5
leaq 0xd221(%rip), %rsi      # 0x23b61
leaq 0xd3af(%rip), %rcx      # 0x23cf6
movl $0xf6, %edx
callq 0x4180
movq 0x1c680(%rip), %rdi     # 0x32fd8
leaq 0xd362(%rip), %rsi      # 0x23cc1
callq 0x4240
leaq 0xd35f(%rip), %rsi      # 0x23cca
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
movq %r14, %rsi
callq 0x4240
movq %rax, %rdi
callq 0x4130
xorl %edi, %edi
callq 0x4260
leaq 0xd3c3(%rip), %rdi      # 0x23d57
leaq 0xd1c6(%rip), %rsi      # 0x23b61
leaq 0xd354(%rip), %rcx      # 0x23cf6
movl $0x111, %edx            # imm = 0x111
callq 0x4180
movq %rax, %rbx
jmp 0x16a0d
jmp 0x169cb
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x17a9a
jmp 0x169d3
jmp 0x169d0
jmp 0x169e1
jmp 0x169cb
movq %rax, %rbx
jmp 0x16a03
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x17a9a
jmp 0x169e4
jmp 0x169e1
movq %rax, %rbx
movq %rsp, %rdi
callq 0x127dc
leaq 0x38(%rsp), %rdi
callq 0x4100
leaq 0x2b8(%rsp), %rdi
callq 0x4120
leaq 0x58(%rsp), %rdi
callq 0x4100
leaq 0xa8(%rsp), %rdi
callq 0x4070
movq %rbx, %rdi
callq 0x43b0