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

    if(source.size() <= 0) return;
    assert(source[0].OutputImageFromKernel.size() == 1); // for 1D, only one kernel
    auto dim = source[0].OutputImageFromKernel[0].Dimension();
    Matrix tmp(dim, 0);
    for(size_t i=0;i<source.size();i++)
    {
        Matrix & _t = source[i].OutputImageFromKernel[0];
        tmp = tmp + _t;
    }

    double batch_size = source.size();
    tmp = tmp/batch_size;

    res.OutputImageFromKernel.clear();
    res.OutputImageFromKernel.push_back(tmp);
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x1ff40
cmpq $0x0, %rax
ja 0x10d67
jmp 0x10f6c
movq 0xa8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1fd40
movq %rax, %rdi
callq 0x1f9c0
cmpq $0x1, %rax
jne 0x10d88
jmp 0x10da7
leaq 0x41c08(%rip), %rdi     # 0x52997
leaq 0x4143c(%rip), %rsi     # 0x521d2
movl $0x77e, %edx            # imm = 0x77E
leaq 0x41c21(%rip), %rcx     # 0x529c3
callq 0x4170
movq 0xa8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1fd40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdi
callq 0x3bae0
movq %rax, 0x90(%rsp)
movq %rdx, 0x98(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
leaq 0x78(%rsp), %rdi
xorps %xmm0, %xmm0
callq 0x3b680
movq $0x0, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x1ff40
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0x10ed5
movq 0xa8(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x1fd40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rdx
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x3bf90
jmp 0x10e77
leaq 0x78(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1fa20
jmp 0x10e88
leaq 0x40(%rsp), %rdi
callq 0x3bb80
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x10e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
jmp 0x10f8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x3bb80
jmp 0x10f8c
movq 0xa8(%rsp), %rdi
callq 0x1ff40
movq %rax, %xmm0
movaps 0x41172(%rip), %xmm1    # 0x52060
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x41176(%rip), %xmm1    # 0x52070
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x28(%rsp), %xmm0
leaq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x3d140
jmp 0x10f26
leaq 0x78(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1fa20
jmp 0x10f37
leaq 0x10(%rsp), %rdi
callq 0x3bb80
movq 0xa0(%rsp), %rdi
callq 0x1fa00
movq 0xa0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x1fa50
jmp 0x10f62
leaq 0x78(%rsp), %rdi
callq 0x3bb80
addq $0xb8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x3bb80
leaq 0x78(%rsp), %rdi
callq 0x3bb80
movq 0x38(%rsp), %rdi
callq 0x43f0