// File: 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:
subq $0xc8, %rsp
movq %rdi, 0x28(%rsp)
movq %rdi, %rax
movq %rax, 0x30(%rsp)
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movl %edx, 0xb4(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq $0x0, 0xa8(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0xa4(%rsp)
movq $0x0, 0x98(%rsp)
movq $0x0, 0x90(%rsp)
cmpl $0x0, 0xb4(%rsp)
jne 0x6192c
movq 0x38(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0xa8(%rsp)
movq 0x8(%rax), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x20(%rsp)
testq %rax, %rax
movss %xmm0, 0x24(%rsp)
js 0x618ff
movss 0x20(%rsp), %xmm0
movss %xmm0, 0x24(%rsp)
movq 0x38(%rsp), %rax
movss 0x24(%rsp), %xmm0
movss %xmm0, 0xa4(%rsp)
movq (%rax), %rax
movq %rax, 0x98(%rsp)
movq $0x1, 0x90(%rsp)
jmp 0x619a5
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0xa8(%rsp)
movq (%rax), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x18(%rsp)
testq %rax, %rax
movss %xmm0, 0x1c(%rsp)
js 0x61979
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
movq 0x38(%rsp), %rax
movss 0x1c(%rsp), %xmm0
movss %xmm0, 0xa4(%rsp)
movq $0x1, 0x98(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x90(%rsp)
movq 0xa8(%rsp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x9030
movq %rax, 0x88(%rsp)
cmpl $0x0, 0xb4(%rsp)
jne 0x61ae2
movq $0x0, 0x80(%rsp)
movq 0x38(%rsp), %rcx
movq 0x80(%rsp), %rax
cmpq (%rcx), %rax
jae 0x61add
xorps %xmm0, %xmm0
movss %xmm0, 0x7c(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x38(%rsp), %rcx
movq 0x70(%rsp), %rax
cmpq 0x8(%rcx), %rax
jae 0x61aa0
movq 0x38(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x38600
movq (%rax), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x10(%rsp)
testq %rax, %rax
movss %xmm0, 0x14(%rsp)
js 0x61a7b
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movss 0x14(%rsp), %xmm0
addss 0x7c(%rsp), %xmm0
movss %xmm0, 0x7c(%rsp)
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x61a18
movss 0x7c(%rsp), %xmm0
divss 0xa4(%rsp), %xmm0
movq 0x88(%rsp), %rax
movq 0x80(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq 0x80(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x80(%rsp)
jmp 0x619f0
jmp 0x61bdb
cmpl $0x1, 0xb4(%rsp)
jne 0x61bd9
movq $0x0, 0x68(%rsp)
movq 0x38(%rsp), %rcx
movq 0x68(%rsp), %rax
cmpq 0x8(%rcx), %rax
jae 0x61bd7
xorps %xmm0, %xmm0
movss %xmm0, 0x64(%rsp)
movq $0x0, 0x58(%rsp)
movq 0x38(%rsp), %rcx
movq 0x58(%rsp), %rax
cmpq (%rcx), %rax
jae 0x61ba3
movq 0x38(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x68(%rsp), %rdx
callq 0x38600
movq (%rax), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x8(%rsp)
testq %rax, %rax
movss %xmm0, 0xc(%rsp)
js 0x61b7e
movss 0x8(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0xc(%rsp), %xmm0
addss 0x64(%rsp), %xmm0
movss %xmm0, 0x64(%rsp)
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x61b1f
movss 0x64(%rsp), %xmm0
divss 0xa4(%rsp), %xmm0
movq 0x88(%rsp), %rax
movq 0x68(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x61af9
jmp 0x61bd9
jmp 0x61bdb
movq 0x28(%rsp), %rdi
movb $0x0, 0x57(%rsp)
callq 0x33a40
movq 0x28(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq 0x98(%rsp), %rdx
movq 0x90(%rsp), %rcx
callq 0x34360
jmp 0x61c0e
movb $0x1, 0x57(%rsp)
testb $0x1, 0x57(%rsp)
jne 0x61c40
jmp 0x61c36
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
callq 0x33e80
jmp 0x61c4d
movq 0x28(%rsp), %rdi
callq 0x33e80
movq 0x30(%rsp), %rax
addq $0xc8, %rsp
retq
movq 0x48(%rsp), %rdi
callq 0x9700
nopw (%rax,%rax)