// File: xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::InitNeuronsInputLayer()
void ConstructLayer::InitNeuronsInputLayer()
{
    __neurons.clear();

    if(__p_data_interface == nullptr)
    {
        std::cout<<__func__<<" Error: must implement/pass DataInterface class before initializing neurons for input layer"
            <<std::endl;
        exit(0);
    }

    assert(__layerDimension != LayerDimension::Undefined);

    auto dim = __p_data_interface->GetDataDimension();

    // 1):
    // for 1D (fc) input layer; 1D input layer needs fake neurons, which will be used by
    //     its following layer to setup weight matrix dimension
    if(__layerDimension == LayerDimension::_1D)
    {
        assert(dim.second == 1); // make sure matrix transformation has been done
        //cout<<"Info::input layer dimension: "<<dim<<endl;
        Pixel2D<Neuron*> image(dim.first, dim.second);
        for(size_t i=0;i<dim.first;i++)
        {
            for(size_t j=0;j<dim.second;j++)
            {
                Neuron *n = new Neuron();
                // n->SetCoord(i, j, k); // input layer neuron does not need coord
                n->SetActuationFuncType(__neuron_actuation_func_type);
                image[i][0] = n;
            }
        }
        __neurons.push_back(image);
    }

    // 2):
    // for 2D input layer, 2D input layer does not need fake neurons, instead
    //     its following layers will directly get 'A' images from 2D input layer
    else if(__layerDimension == LayerDimension::_2D)
    {
        // 2D layers neurons number should equal to dim.first * dim.second
        size_t total_neurons = dim.first * dim.second;
        Pixel2D<Neuron*> image(total_neurons, 1);
        for(size_t i=0;i<total_neurons;i++)
        {
            for(size_t j=0;j<1;j++)
            {
                Neuron *n = new Neuron();
                // n->SetCoord(i, j, k); // input layer neuron does not need coord
                image[i][0] = n;
            }
        }
        __neurons.push_back(image);
    }
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xc0(%rsp)
movq 0xc0(%rsp), %rdi
movq %rdi, 0x30(%rsp)
addq $0x40, %rdi
callq 0x1f670
movq 0x30(%rsp), %rax
cmpq $0x0, 0x400(%rax)
jne 0x868c
movq 0x6297d(%rip), %rdi     # 0x6afd8
leaq 0x49c98(%rip), %rsi     # 0x522fa
callq 0x4230
movq %rax, %rdi
leaq 0x49c9f(%rip), %rsi     # 0x52310
callq 0x4230
movq %rax, %rdi
movq 0x62930(%rip), %rsi     # 0x6afb0
callq 0x4260
xorl %edi, %edi
callq 0x4290
movq 0x30(%rsp), %rax
cmpl $0x2, 0x408(%rax)
je 0x869c
jmp 0x86bb
leaq 0x49cc9(%rip), %rdi     # 0x5236c
leaq 0x49b28(%rip), %rsi     # 0x521d2
movl $0x1ce, %edx            # imm = 0x1CE
leaq 0x49ce4(%rip), %rcx     # 0x5239a
callq 0x4170
movq 0x30(%rsp), %rax
movq 0x400(%rax), %rdi
callq 0x1f800
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0xb0(%rsp)
movq %rdx, 0xb8(%rsp)
cmpl $0x0, 0x408(%rax)
jne 0x8898
cmpq $0x1, 0xb8(%rsp)
jne 0x86fe
jmp 0x871d
leaq 0x4a43d(%rip), %rdi     # 0x52b42
leaq 0x49ac6(%rip), %rsi     # 0x521d2
movl $0x1d7, %edx            # imm = 0x1D7
leaq 0x49c82(%rip), %rcx     # 0x5239a
callq 0x4170
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
leaq 0x98(%rsp), %rdi
callq 0x1f690
movq $0x0, 0x90(%rsp)
movq 0x90(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jae 0x885c
movq $0x0, 0x88(%rsp)
movq 0x88(%rsp), %rax
cmpq 0xb8(%rsp), %rax
jae 0x8841
movl $0xa0, %edi
callq 0x4240
movq %rax, 0x28(%rsp)
jmp 0x878f
movq 0x28(%rsp), %rdi
callq 0x474c0
jmp 0x879b
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x80(%rsp)
movq 0x80(%rsp), %rdi
movl 0x58(%rax), %esi
callq 0x48100
jmp 0x87bf
movq 0x80(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x90(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x1f5c0
movq %rax, 0x20(%rsp)
jmp 0x87e8
movq 0x20(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f5f0
movq 0x18(%rsp), %rcx
movq %rcx, (%rax)
movq 0x88(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x88(%rsp)
jmp 0x8768
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
jmp 0x8886
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
callq 0x4220
jmp 0x8886
jmp 0x8843
movq 0x90(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x90(%rsp)
jmp 0x8746
movq 0x30(%rsp), %rdi
addq $0x40, %rdi
leaq 0x98(%rsp), %rsi
callq 0x1f780
jmp 0x8874
leaq 0x98(%rsp), %rdi
callq 0x1f7f0
jmp 0x89db
leaq 0x98(%rsp), %rdi
callq 0x1f7f0
jmp 0x89e3
movq 0x30(%rsp), %rax
cmpl $0x1, 0x408(%rax)
jne 0x89d9
movq 0xb0(%rsp), %rax
imulq 0xb8(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rsi
leaq 0x50(%rsp), %rdi
movl $0x1, %edx
callq 0x1f690
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq 0x68(%rsp), %rax
jae 0x89ac
movq $0x0, 0x40(%rsp)
cmpq $0x1, 0x40(%rsp)
jae 0x8997
movl $0xa0, %edi
callq 0x4240
movq %rax, 0x10(%rsp)
jmp 0x8913
movq 0x10(%rsp), %rdi
callq 0x474c0
jmp 0x891f
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
movq 0x48(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x1f5c0
movq %rax, 0x8(%rsp)
jmp 0x8948
movq 0x8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f5f0
movq (%rsp), %rcx
movq %rcx, (%rax)
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x88f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
jmp 0x89cd
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
callq 0x4220
jmp 0x89cd
jmp 0x8999
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x88dd
movq 0x30(%rsp), %rdi
addq $0x40, %rdi
leaq 0x50(%rsp), %rsi
callq 0x1f780
jmp 0x89c1
leaq 0x50(%rsp), %rdi
callq 0x1f7f0
jmp 0x89d9
leaq 0x50(%rsp), %rdi
callq 0x1f7f0
jmp 0x89e3
jmp 0x89db
addq $0xc8, %rsp
retq
movq 0x78(%rsp), %rdi
callq 0x43f0
nopl (%rax)