// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, 0x18(%rsp)
movq (%rsi), %rcx
movq %rsi, 0x10(%rsp)
movq 0x8(%rsi), %rsi
movq %rsi, %rax
subq %rcx, %rax
pushq $0x18
popq %rdi
cqto
idivq %rdi
cmpq %rcx, %rsi
je 0xa96c
movq %rax, %xmm0
punpckldq 0x16862(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1686a(%rip), %xmm0    # 0x21030
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, 0x20(%rsp)
xorl %ecx, %ecx
leaq 0x90(%rsp), %r12
leaq 0x48(%rsp), %r15
cmpq 0x20(%rsp), %rcx
je 0xa96c
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x28(%rsp)
imulq $0x18, %rcx, %r13
movq (%rax), %rdi
addq %r13, %rdi
callq 0x17a6a
movq %rax, 0x8(%rsp)
movq %rdx, (%rsp)
xorpd %xmm0, %xmm0
movq %r12, %r14
movq %r12, %rdi
pushq $0x1
popq %rdx
movq %rdx, %rsi
callq 0x177ee
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
cmpq %rax, %rbp
jae 0xa8aa
movq (%rcx,%r12), %rdi
addq %r13, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
xorl %ecx, %ecx
movq (%rsp), %r8
callq 0x19b90
movq %r15, %rdi
movq %r15, %rbx
movq %r14, %r15
movq %r14, %rsi
callq 0x180cc
movq %r15, %rdi
movq %rbx, %rsi
callq 0x125b4
movq %rbx, %r15
movq %rbx, %rdi
callq 0x17a9a
incq %rbp
addq $0x18, %r12
jmp 0xa845
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %r12
movq %r14, %rsi
movapd 0x30(%rsp), %xmm0
callq 0x18348
movsd 0x8(%rsp), %xmm1
movsd 0x1674f(%rip), %xmm0    # 0x21020
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x16754(%rip), %xmm0    # 0x21030
subpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
leaq 0x78(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x18348
movsd (%rsp), %xmm1
unpcklps 0x16718(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x16720(%rip), %xmm1    # 0x21030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %r15, %rdi
movq %r14, %rsi
callq 0x18348
movq %r12, %rdi
movq %r15, %rsi
callq 0x125b4
movq %r15, %rdi
callq 0x17a9a
movq %r14, %rdi
callq 0x17a9a
movq %rbx, %rdi
callq 0x17a9a
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x1139c
movq %r12, %rdi
callq 0x17a9a
movq 0x28(%rsp), %rcx
incq %rcx
jmp 0xa7fb
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0xa99f
movq %rax, %rbx
jmp 0xa995
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x17a9a
leaq 0x78(%rsp), %rdi
callq 0x17a9a
leaq 0x60(%rsp), %rdi
jmp 0xa9b2
jmp 0xa9bb
jmp 0xa9bb
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x17a9a
jmp 0xa9be
jmp 0xa9bb
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x17a9a
movq %rbx, %rdi
callq 0x43b0
nop