// File: /workspace/github_cpp_makefile_star2_O3/btbujiangjun[P]abcdl/src/algebra/MatrixAlgebra.cpp
// Function: abcdl::algebra::Matrix<unsigned long>::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
testl %edx, %edx
je 0x2d96f
movq 0x8(%r12), %rax
movl $0x1, %ecx
movq %rcx, 0x8(%rsp)
movq %r12, %rcx
movq %rax, 0x10(%rsp)
jmp 0x2d98a
movq (%r12), %rdx
leaq 0x8(%r12), %rcx
movl $0x1, %eax
movq %rax, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rdx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
movq %rdi, 0x18(%rsp)
js 0x2d99e
cvtsi2ss %rcx, %xmm0
jmp 0x2d9b3
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
movss %xmm0, (%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 0x2daeb
cmpl $0x1, %ebp
movss (%rsp), %xmm1
jne 0x2dbea
movq 0x8(%r12), %rdx
testq %rdx, %rdx
je 0x2dbea
movq (%r12), %rax
xorl %ebp, %ebp
leaq 0xea46(%rip), %rsi      # 0x3c44d
leaq 0x20(%rsp), %rbx
movq %rax, %rcx
xorps %xmm2, %xmm2
testq %rcx, %rcx
je 0x2dacd
xorl %r15d, %r15d
movq 0x8(%r12), %r14
imulq %r14, %rcx
imulq %r15, %r14
addq %rbp, %r14
cmpq %rcx, %r14
jae 0x2da74
movq 0x10(%r12), %rcx
movq (%rcx,%r14,8), %rcx
testq %rcx, %rcx
js 0x2da4b
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
jmp 0x2da63
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
addss %xmm0, %xmm2
incq %r15
movq %rax, %rcx
cmpq %rax, %r15
jb 0x2da1e
jmp 0x2dac3
movss %xmm2, 0x4(%rsp)
movq %rbx, %rdi
movl $0x44, %edx
movl $0x3, %ecx
callq 0x387b6
movl $0x1f, %edx
movq %rbx, %rdi
leaq 0xea85(%rip), %rsi      # 0x3c520
callq 0x93b0
movq %rbx, %rdi
callq 0x389de
movq (%r12), %rax
movss (%rsp), %xmm1
leaq 0xe995(%rip), %rsi      # 0x3c44d
movss 0x4(%rsp), %xmm2
jmp 0x2da33
movq 0x8(%r12), %rdx
movq %rax, %rcx
jmp 0x2dacf
xorl %ecx, %ecx
divss %xmm1, %xmm2
movss %xmm2, (%r13,%rbp,4)
incq %rbp
cmpq %rdx, %rbp
jb 0x2da0f
jmp 0x2dbea
movq (%r12), %rdx
testq %rdx, %rdx
movss (%rsp), %xmm1
je 0x2dbea
movq 0x8(%r12), %rax
xorl %r14d, %r14d
leaq 0xe941(%rip), %rsi      # 0x3c44d
leaq 0x20(%rsp), %rbx
movq %rax, %rcx
xorps %xmm2, %xmm2
testq %rcx, %rcx
je 0x2dbd1
xorl %r15d, %r15d
movq %r14, %rbp
imulq %rcx, %rbp
addq %r15, %rbp
imulq (%r12), %rcx
cmpq %rcx, %rbp
jae 0x2db78
movq 0x10(%r12), %rcx
movq (%rcx,%rbp,8), %rcx
testq %rcx, %rcx
js 0x2db4f
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
jmp 0x2db67
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
addss %xmm0, %xmm2
incq %r15
movq %rax, %rcx
cmpq %rax, %r15
jb 0x2db23
jmp 0x2dbc8
movss %xmm2, 0x4(%rsp)
movq %rbx, %rdi
movl $0x44, %edx
movl $0x3, %ecx
callq 0x387b6
movl $0x1f, %edx
movq %rbx, %rdi
leaq 0xe981(%rip), %rsi      # 0x3c520
callq 0x93b0
movq %rbx, %rdi
callq 0x389de
movq 0x8(%r12), %rax
movss (%rsp), %xmm1
leaq 0xe890(%rip), %rsi      # 0x3c44d
movss 0x4(%rsp), %xmm2
jmp 0x2db37
movq (%r12), %rdx
movq %rax, %rcx
jmp 0x2dbd3
xorl %ecx, %ecx
divss %xmm1, %xmm2
movss %xmm2, (%r13,%r14,4)
incq %r14
cmpq %rdx, %r14
jb 0x2db14
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x197e0
movq %rbx, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x19db2
movq %rbx, %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2dc23
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x389de
jmp 0x2dc3d
movq %rax, %r14
movq %rbx, %rdi
callq 0x19a36
movq %r14, %rdi
callq 0x95d0
nop