// File: /workspace/github_cpp_makefile_star2_O3/xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::InitBatchNormalizationParameters()
void ConstructLayer::InitBatchNormalizationParameters()
{
    // only apply for cnn, fc and output layer, no need for pooling and input layers
    if( (GetType() != LayerType::cnn) &&
            ( GetType() != LayerType::fullyConnected) &&
            (GetType() != LayerType::output))
    {
        return; 
    }

    if(GetLayerDimension() == LayerDimension::_1D)
    {
        auto dim = GetOutputImageSize();
        assert(dim.first >= 1);
        assert(dim.second >= 1);

        // for 1D layer, each channel (or feature) has one pair of (\gamma, \beta)
        //   so the matrix dimension equals the output image dimension
        //   and __gamma_BN should have only one matrix
        Matrix tmp1(dim, 1.0); // initialize gamma parameters with 1.0
        __gamma_BN.push_back(tmp1);
        Matrix tmp2(dim, 0);   // initialize beta parameters with 0
        __beta_BN.push_back(tmp2);
    }
    else if(GetLayerDimension() == LayerDimension::_2D)
    {
        size_t n = GetNumberOfKernelsCNN();
        assert(n == __weightMatrix.size());  // one-on-one mapping to vector of kernels
        assert(n >= 1);

        // for 2D layer, each kernel has one pair of (\gamma, \beta)
        //   so the matrix dimension should be (1, 1)
        //   and __gamma_BN should have the same length with number of kernels
        for(size_t i=0;i<n;i++)
        {
            __gamma_BN.push_back(Matrix(1, 1, 1.0)); // initialize gamma with 1.
            __beta_BN.push_back(Matrix(1, 1, 0.0)); // initialize beta with 0.
        }
    }
    else {
        std::cout<<"Error: InitBatchNormalizationParameters(): unsupported layer dimension."<<std::endl;
        exit(0);
    }

    // Above we initilize parameter \gamma with 1. and paramter \beta with 0
    // instead of random normalization
    // ---- this needs to be tested
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x250(%rax)
cmpl $0x1, %eax
je 0x5cb7
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x250(%rax)
testl %eax, %eax
je 0x5cb7
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x250(%rax)
cmpl $0x4, %eax
jne 0x5e10
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x258(%rax)
movq (%rbx), %rcx
movq %rbx, %rdi
testl %eax, %eax
je 0x5d8d
callq *0x258(%rcx)
cmpl $0x1, %eax
jne 0x5e1c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x288(%rax)
movq %rax, %r14
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rcx
cmpq %rcx, %r14
jne 0x5e3e
testq %r14, %r14
je 0x5e5d
leaq 0x308(%rbx), %r15
addq $0x320, %rbx            # imm = 0x320
leaq 0x8(%rsp), %r12
movl $0x1, %esi
movl $0x1, %edx
movq %r12, %rdi
movsd 0x2183d(%rip), %xmm0    # 0x27580
callq 0x1a892
movq %r15, %rdi
movq %r12, %rsi
callq 0x1791a
movq %r12, %rdi
callq 0x1abf2
movl $0x1, %esi
movl $0x1, %edx
xorps %xmm0, %xmm0
movq %r12, %rdi
callq 0x1a892
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1791a
movq %r12, %rdi
callq 0x1abf2
decq %r14
jne 0x5d2e
jmp 0x5e10
callq *0x270(%rcx)
testq %rax, %rax
je 0x5e7c
movq %rdx, %r15
testq %rdx, %rdx
je 0x5e9b
movq %rax, %r14
leaq 0x8(%rsp), %r12
movsd 0x217c8(%rip), %xmm0    # 0x27580
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x1a92c
leaq 0x308(%rbx), %rdi
movq %r12, %rsi
callq 0x138a4
leaq 0x20(%rsp), %rdi
xorps %xmm0, %xmm0
movq %r14, %rsi
movq %r15, %rdx
callq 0x1a92c
addq $0x320, %rbx            # imm = 0x320
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x138a4
leaq 0x20(%rsp), %rdi
callq 0x1abf2
leaq 0x8(%rsp), %rdi
callq 0x1abf2
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x311b5(%rip), %rdi     # 0x36fd8
leaq 0x2205e(%rip), %rsi     # 0x27e88
callq 0x4260
movq %rax, %rdi
callq 0x4100
xorl %edi, %edi
callq 0x4290
leaq 0x22021(%rip), %rdi     # 0x27e66
leaq 0x218fe(%rip), %rsi     # 0x2774a
leaq 0x21fcb(%rip), %rcx     # 0x27e1e
movl $0x762, %edx            # imm = 0x762
callq 0x4160
leaq 0x2201d(%rip), %rdi     # 0x27e81
leaq 0x218df(%rip), %rsi     # 0x2774a
leaq 0x21fac(%rip), %rcx     # 0x27e1e
movl $0x763, %edx            # imm = 0x763
callq 0x4160
leaq 0x21f8c(%rip), %rdi     # 0x27e0f
leaq 0x218c0(%rip), %rsi     # 0x2774a
leaq 0x21f8d(%rip), %rcx     # 0x27e1e
movl $0x754, %edx            # imm = 0x754
callq 0x4160
leaq 0x21fb4(%rip), %rdi     # 0x27e56
leaq 0x218a1(%rip), %rsi     # 0x2774a
leaq 0x21f6e(%rip), %rcx     # 0x27e1e
movl $0x755, %edx            # imm = 0x755
callq 0x4160
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x1abf2
jmp 0x5ed2
jmp 0x5ecf
jmp 0x5ecf
jmp 0x5ecf
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x1abf2
movq %rbx, %rdi
callq 0x43e0