// File: xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::GetMu_BFor2DLayer(std::vector<Images, std::allocator<Images>>&, Images&)
void ConstructLayer::GetMu_BFor2DLayer(std::vector<Images> &source, Images &res)
{
    // 1) get \mu_B (average)
    // --- 2d case

    double batch_size = source.size();
    if(batch_size <= 0) return;
    size_t nKernel = source[0].OutputImageFromKernel.size();
    for(size_t i = 0; i< nKernel;i++)
    {
        auto dim = source[0].OutputImageFromKernel[i].Dimension();
        Matrix tmp(1, 1, 0);
        for(size_t n=0;n<source.size();n++)
        {
            Matrix& m = source[n].OutputImageFromKernel[i];
            double _sum = m.SumInSection(0, dim.first, 0, dim.second);
            tmp = tmp + _sum;
        }
        tmp = tmp / batch_size / (double)dim.first / (double) dim.second; // = sum /n /(p x q)
        res.OutputImageFromKernel.push_back(tmp);
    }
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x1ff40
movq %rax, %xmm0
movaps 0x41088(%rip), %xmm1    # 0x52060
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x4108c(%rip), %xmm1    # 0x52070
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0xd8(%rsp)
xorps %xmm0, %xmm0
ucomisd 0xd8(%rsp), %xmm0
jb 0x1100f
jmp 0x11334
movq 0xe8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1fd40
movq %rax, %rdi
callq 0x1f9c0
movq %rax, 0xd0(%rsp)
movq $0x0, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
cmpq 0xd0(%rsp), %rax
jae 0x11334
movq 0xe8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1fd40
movq %rax, %rdi
movq 0xc8(%rsp), %rsi
callq 0x1f9e0
movq %rax, %rdi
callq 0x3bae0
movq %rax, 0xb8(%rsp)
movq %rdx, 0xc0(%rsp)
leaq 0xa0(%rsp), %rdi
movl $0x1, %edx
xorps %xmm0, %xmm0
movq %rdx, %rsi
callq 0x3b590
movq $0x0, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x1ff40
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x111cc
movq 0xe8(%rsp), %rdi
movq 0x98(%rsp), %rsi
callq 0x1fd40
movq %rax, %rdi
movq 0xc8(%rsp), %rsi
callq 0x1f9e0
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rdi
movq 0xb8(%rsp), %rdx
movq 0xc0(%rsp), %r8
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
callq 0x407f0
movsd %xmm0, 0x8(%rsp)
jmp 0x11133
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x88(%rsp), %xmm0
leaq 0x60(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x3ca80
jmp 0x1115f
leaq 0xa0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x1fa20
jmp 0x11173
leaq 0x60(%rsp), %rdi
callq 0x3bb80
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
jmp 0x110af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x11325
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x3bb80
jmp 0x11325
movsd 0xd8(%rsp), %xmm0
leaq 0x18(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x3d140
jmp 0x111e9
movaps 0x40e70(%rip), %xmm1    # 0x52060
movq 0xb8(%rsp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x40e6b(%rip), %xmm1    # 0x52070
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
leaq 0x30(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3d140
jmp 0x11225
movaps 0x40e34(%rip), %xmm1    # 0x52060
movq 0xc0(%rsp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x40e2f(%rip), %xmm1    # 0x52070
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
leaq 0x48(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x3d140
jmp 0x11261
leaq 0xa0(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x1fa20
jmp 0x11275
leaq 0x48(%rsp), %rdi
callq 0x3bb80
leaq 0x30(%rsp), %rdi
callq 0x3bb80
leaq 0x18(%rsp), %rdi
callq 0x3bb80
movq 0xe0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x1fa50
jmp 0x112aa
leaq 0xa0(%rsp), %rdi
callq 0x3bb80
movq 0xc8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc8(%rsp)
jmp 0x1103c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x1131b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x11311
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x3bb80
leaq 0x30(%rsp), %rdi
callq 0x3bb80
leaq 0x18(%rsp), %rdi
callq 0x3bb80
leaq 0xa0(%rsp), %rdi
callq 0x3bb80
jmp 0x1133c
addq $0xf8, %rsp
retq
movq 0x80(%rsp), %rdi
callq 0x43f0
nopl (%rax)