// File: /workspace/github_cpp_makefile_star2_O1/btbujiangjun[P]abcdl/src/algebra/MatrixAlgebra.cpp
// Function: abcdl::algebra::Matrix<int>::mean(abcdl::algebra::Axis_type) const
Matrix<real> Matrix<T>::mean(Axis_type type) const{
    size_t size = 0;
    real count = 0;
    size_t mean_row = 0;
    size_t mean_col = 0;
    if(type == Axis_type::ROW){
        size = _rows;
        count = _cols;
        mean_row = _rows;
        mean_col = 1;
    }else{
        size = _cols;
        count = _rows;
        mean_row = 1;
        mean_col = _cols;
    }
    real* data = new real[size];

    if(type == Axis_type::ROW){
        for(size_t i = 0; i < _rows; i++){
            real total = 0;
            for(size_t j = 0; j < _cols; j++){
                total += get_data(i, j);
            }
            data[i] = total/count;
        }
    }else if(type == Axis_type::COL){
        for(size_t i = 0; i < _cols; i++){
            real total = 0;
            for(size_t j = 0; j < _rows; j++){
                total += get_data(j, i);
            }
            data[i] =  total/count;
        }
    }

    Matrix<real> mean_mat;
    mean_mat.set_shallow_data(data, mean_row, mean_col);
    return mean_mat;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
testl %edx, %edx
je 0x29ff4
movq 0x8(%r12), %rax
movl $0x1, %ecx
movq %rcx, 0x10(%rsp)
movq %r12, %rcx
movq %rax, 0x18(%rsp)
jmp 0x2a00f
movq (%r12), %rdx
leaq 0x8(%r12), %rcx
movl $0x1, %eax
movq %rax, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rdx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
js 0x2a01e
cvtsi2ss %rcx, %xmm0
jmp 0x2a033
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
movq %rax, %rcx
shrq $0x3e, %rcx
shlq $0x2, %rax
xorl %edi, %edi
negq %rcx
sbbq %rdi, %rdi
orq %rax, %rdi
callq 0x9030
movq %rax, %r13
testl %ebp, %ebp
je 0x2a140
cmpl $0x1, %ebp
movss 0x8(%rsp), %xmm1
jne 0x2a212
cmpq $0x0, 0x8(%r12)
je 0x2a212
xorl %ebp, %ebp
leaq 0x123ca(%rip), %rsi     # 0x3c44d
leaq 0x20(%rsp), %rcx
movq (%r12), %rax
xorps %xmm2, %xmm2
testq %rax, %rax
je 0x2a122
xorl %r15d, %r15d
movq 0x8(%r12), %r14
imulq %r14, %rax
imulq %r15, %r14
addq %rbp, %r14
cmpq %rax, %r14
jae 0x2a0d0
movq 0x10(%r12), %rax
xorps %xmm0, %xmm0
cvtsi2ssl (%rax,%r14,4), %xmm0
movq (%r12), %rax
addss %xmm0, %xmm2
incq %r15
cmpq %rax, %r15
jb 0x2a09b
jmp 0x2a122
movss %xmm2, 0xc(%rsp)
movq %rcx, %rdi
movl $0x44, %edx
movl $0x3, %ecx
callq 0x3894e
movl $0x1f, %edx
leaq 0x20(%rsp), %rdi
leaq 0x12427(%rip), %rsi     # 0x3c520
callq 0x93b0
leaq 0x20(%rsp), %rdi
callq 0x38b76
movss 0x8(%rsp), %xmm1
leaq 0x12338(%rip), %rsi     # 0x3c44d
leaq 0x20(%rsp), %rcx
movss 0xc(%rsp), %xmm2
jmp 0x2a0b0
divss %xmm1, %xmm2
movss %xmm2, (%r13,%rbp,4)
incq %rbp
cmpq 0x8(%r12), %rbp
jb 0x2a088
jmp 0x2a212
cmpq $0x0, (%r12)
movss 0x8(%rsp), %xmm1
je 0x2a212
xorl %r14d, %r14d
leaq 0x122f2(%rip), %rsi     # 0x3c44d
leaq 0x20(%rsp), %rcx
movq 0x8(%r12), %rax
xorps %xmm2, %xmm2
testq %rax, %rax
je 0x2a1fa
xorl %r15d, %r15d
movq %r14, %rbp
imulq %rax, %rbp
addq %r15, %rbp
imulq (%r12), %rax
cmpq %rax, %rbp
jae 0x2a1a8
movq 0x10(%r12), %rax
xorps %xmm0, %xmm0
cvtsi2ssl (%rax,%rbp,4), %xmm0
movq 0x8(%r12), %rax
addss %xmm0, %xmm2
incq %r15
cmpq %rax, %r15
jb 0x2a174
jmp 0x2a1fa
movss %xmm2, 0xc(%rsp)
movq %rcx, %rdi
movl $0x44, %edx
movl $0x3, %ecx
callq 0x3894e
movl $0x1f, %edx
leaq 0x20(%rsp), %rdi
leaq 0x1234f(%rip), %rsi     # 0x3c520
callq 0x93b0
leaq 0x20(%rsp), %rdi
callq 0x38b76
movss 0x8(%rsp), %xmm1
leaq 0x12260(%rip), %rsi     # 0x3c44d
leaq 0x20(%rsp), %rcx
movss 0xc(%rsp), %xmm2
jmp 0x2a188
divss %xmm1, %xmm2
movss %xmm2, (%r13,%r14,4)
incq %r14
cmpq (%r12), %r14
jb 0x2a160
movq %rbx, %rdi
callq 0x19a38
movq %rbx, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0x1a00a
movq %rbx, %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a246
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x38b76
jmp 0x2a260
movq %rax, %r14
movq %rbx, %rdi
callq 0x19c8e
movq %r14, %rdi
callq 0x95d0