// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
leaq 0x98(%rsp), %r13
movq %r13, %rdi
movl $0x8, %edx
callq 0x42b0
leaq 0x118(%rsp), %rdi
callq 0x4080
testb %al, %al
je 0x196a3
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x2a8(%rsp), %rbp
leaq 0x80(%rsp), %r14
movq %r15, %r12
movq 0x98(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4250
movsbl %al, %edx
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
callq 0x4410
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x195db
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 0x19427
cmpq $0x0, 0x28(%rsp)
je 0x19382
movq 0x20(%rsp), %r15
callq 0x4040
movq %rax, %rbx
movl (%rax), %r13d
movl $0x0, (%rax)
movq %r15, %rdi
movq %r14, %rsi
callq 0x41c0
cmpq %r15, 0x80(%rsp)
je 0x1966c
movl (%rbx), %eax
testl %eax, %eax
je 0x193e8
cmpl $0x22, %eax
jne 0x193eb
jmp 0x19678
movl %r13d, (%rbx)
movsd %xmm0, 0x68(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x19412
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
movq %r12, %r15
jmp 0x19382
movq %rsp, %rdi
leaq 0x68(%rsp), %rdx
callq 0x17770
movq %r12, %r15
jmp 0x19382
movq 0x8(%rsp), %rax
subq (%rsp), %rax
cmpq $0xd8, %rax
jne 0x19684
movq 0x80(%r15), %rax
testq %rax, %rax
je 0x19467
imull 0x88(%r15), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
ucomisd 0xe131(%rip), %xmm0     # 0x27590
jb 0x1946e
sqrtsd %xmm0, %xmm0
jmp 0x19473
movl $0xa, %ebx
jmp 0x19492
callq 0x4438
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0xe141(%rip), %xmm0     # 0x275c8
cvttsd2si %xmm0, %rbx
andq %rcx, %rbx
orq %rax, %rbx
movq %r14, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0x1a82e
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x19550
xorl %r15d, %r15d
movsd (%rax,%r15,8), %xmm0
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
movsd 0xe100(%rip), %xmm1     # 0x275c8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
cmpq %rsi, %rbx
jbe 0x1964d
movsd 0x8(%rax,%r15,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, %rbx
jbe 0x1964d
movsd 0x10(%rax,%r15,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r14, %rdi
callq 0x1ae76
movq (%rax), %rax
movsd 0x40(%rsp), %xmm0
movsd %xmm0, (%rax,%r13,8)
addq $0x3, %r15
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %r15
jb 0x194b2
movq %r12, %r15
movq 0x80(%r12), %rdx
movq 0x88(%r12), %rcx
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1c1c4
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x13a14
leaq 0x98(%rsp), %r13
movq %rbx, %rdi
callq 0x1acb6
movq %r14, %rdi
callq 0x1acb6
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x195a6
callq 0x4230
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x195ba
callq 0x4230
movq %rbp, %rdi
movq 0x1da04(%rip), %rsi     # 0x36fc8
callq 0x42f0
leaq 0x320(%rsp), %rdi
callq 0x40b0
jmp 0x19311
cmpl $0x2, 0xc0(%r15)
je 0x196f1
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0x1ac7c
cmpl $0x0, 0xc0(%r15)
je 0x1960a
movq %rax, 0x70(%r15)
movq %rdx, 0x78(%r15)
jmp 0x1961a
movq $0x1, 0x78(%r15)
imulq %rdx, %rax
movq %rax, 0x70(%r15)
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x1962e
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 0x1078b(%rip), %rdi     # 0x29ddf
leaq 0x105ad(%rip), %rsi     # 0x29c08
leaq 0x1073b(%rip), %rcx     # 0x29d9d
movl $0x105, %edx            # imm = 0x105
callq 0x4160
leaq 0x107ba(%rip), %rdi     # 0x29e2d
callq 0x4150
leaq 0x107ae(%rip), %rdi     # 0x29e2d
callq 0x4300
leaq 0x10701(%rip), %rdi     # 0x29d8c
leaq 0x10576(%rip), %rsi     # 0x29c08
leaq 0x10704(%rip), %rcx     # 0x29d9d
movl $0xf6, %edx
callq 0x4160
movq 0x1d92e(%rip), %rdi     # 0x36fd8
leaq 0x106b7(%rip), %rsi     # 0x29d68
movl $0x8, %edx
callq 0x4280
movq 0x1d916(%rip), %rdi     # 0x36fd8
leaq 0x106a8(%rip), %rsi     # 0x29d71
movl $0x1a, %edx
callq 0x4280
movq 0x1d8fe(%rip), %rdi     # 0x36fd8
movq %rbx, %rsi
callq 0x4260
movq %rax, %rdi
callq 0x4100
xorl %edi, %edi
callq 0x4290
leaq 0x10706(%rip), %rdi     # 0x29dfe
leaq 0x10509(%rip), %rsi     # 0x29c08
leaq 0x10697(%rip), %rcx     # 0x29d9d
movl $0x111, %edx            # imm = 0x111
callq 0x4160
movq %rax, %r14
jmp 0x197af
jmp 0x1972f
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x1acb6
jmp 0x19739
jmp 0x19736
jmp 0x19755
jmp 0x1972f
movq %rax, %r14
jmp 0x1979b
jmp 0x19755
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x1acb6
jmp 0x19758
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x19758
movl %r13d, (%rbx)
jmp 0x19758
movq %rax, %r14
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x19766
callq 0x4230
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x1977a
callq 0x4230
movq 0x1d847(%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 0x197af
callq 0x4230
leaq 0x98(%rsp), %rdi
callq 0x4070
movq %r14, %rdi
callq 0x43e0