// File: xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::InitNeurons()
void ConstructLayer::InitNeurons()
{
    if(__type == LayerType::cnn)
        InitNeuronsCNN();
    else if(__type == LayerType::pooling)
        InitNeuronsPooling();
    else if(__type == LayerType::input)
        InitNeuronsInputLayer();
    else if(__type == LayerType::fullyConnected)
        InitNeuronsFC();
    else if(__type == LayerType::output)
        InitNeuronsFC();
    else
    {
        std::cout<<"Error: Init neurons, unrecognized layer type."<<std::endl;
        exit(0);
    }
    //std::cout<<"Debug: Layer:"<<GetID()<<" init neruons done."<<std::endl;

    // after initializing all neurons, setup neuron dimension information
    // setup total neuron dimension
    size_t k = __neurons.size();
    size_t i = 0;
    size_t j = 0;
    if(k > 0)
    {
        i = __neurons[0].Dimension().first;
        j = __neurons[0].Dimension().second;

        __neuronDim.k = k;
        __neuronDim.i = i;
        __neuronDim.j = j;
    }

    // setup neuron layer information
    for(size_t kk=0;kk<k;kk++)
    {
        for(size_t ii=0;ii<i;ii++)
            for(size_t jj=0;jj<j;jj++)
            {
                __neurons[kk][ii][jj]->SetLayer(dynamic_cast<Layer*>(this));
                //__neurons[kk][ii][jj]->SetPreviousLayer(__prevLayer); // obsolete
                //__neurons[kk][ii][jj]->SetNextLayer(__nextLayer);     // obsolete
            }
    }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpl $0x1, 0xc(%rax)
jne 0x7d48
movq 0x8(%rsp), %rdi
callq 0x7f50
jmp 0x7dd5
movq 0x8(%rsp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x7d5f
movq 0x8(%rsp), %rdi
callq 0x82b0
jmp 0x7dd3
movq 0x8(%rsp), %rax
cmpl $0x3, 0xc(%rax)
jne 0x7d76
movq 0x8(%rsp), %rdi
callq 0x8620
jmp 0x7dd1
movq 0x8(%rsp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x7d8d
movq 0x8(%rsp), %rdi
callq 0x89f0
jmp 0x7dcf
movq 0x8(%rsp), %rax
cmpl $0x4, 0xc(%rax)
jne 0x7da4
movq 0x8(%rsp), %rdi
callq 0x89f0
jmp 0x7dcd
movq 0x6322d(%rip), %rdi     # 0x6afd8
leaq 0x4a3db(%rip), %rsi     # 0x5218d
callq 0x4230
movq %rax, %rdi
movq 0x631ef(%rip), %rsi     # 0x6afb0
callq 0x4260
xorl %edi, %edi
callq 0x4290
jmp 0x7dcf
jmp 0x7dd1
jmp 0x7dd3
jmp 0x7dd5
movq 0x8(%rsp), %rdi
addq $0x40, %rdi
callq 0x1f630
movq %rax, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
cmpq $0x0, 0x58(%rsp)
jbe 0x7e8e
movq 0x8(%rsp), %rdi
addq $0x40, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f650
movq %rax, %rdi
callq 0x1f530
movq 0x8(%rsp), %rdi
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x50(%rsp)
addq $0x40, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f650
movq %rax, %rdi
callq 0x1f530
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq 0x30(%rsp), %rcx
movq %rcx, 0x48(%rsp)
movq 0x58(%rsp), %rcx
movq %rcx, 0x3a8(%rax)
movq 0x50(%rsp), %rcx
movq %rcx, 0x398(%rax)
movq 0x48(%rsp), %rcx
movq %rcx, 0x3a0(%rax)
movq $0x0, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq 0x58(%rsp), %rax
jae 0x7f42
movq $0x0, 0x18(%rsp)
movq 0x18(%rsp), %rax
cmpq 0x50(%rsp), %rax
jae 0x7f2d
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x48(%rsp), %rax
jae 0x7f1b
movq 0x8(%rsp), %rdi
addq $0x40, %rdi
movq 0x20(%rsp), %rsi
callq 0x1f650
movq %rax, %rdi
movq 0x18(%rsp), %rsi
callq 0x1f5c0
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x1f5f0
movq 0x8(%rsp), %rsi
movq (%rax), %rdi
callq 0x480e0
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x7ec5
jmp 0x7f1d
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
jmp 0x7eb0
jmp 0x7f2f
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x7e97
addq $0x68, %rsp
retq
nopw (%rax,%rax)