// File: /workspace/github_cpp_makefile_star2_O1/xbai0624[P]dnn/src/Matrix.cpp
// Function: Matrix::Normalization()
Matrix Matrix::Normalization()
{
    // includes normalization, centering and standarization per sample
    auto dim = Dimension();
    Matrix m(dim);

    // step 1) normalize
    double min = MinInSection(0, dim.first, 0, dim.second);
    double max = MaxInSection(0, dim.first, 0, dim.second);

    double amp = max - min;

    if(amp > 0)
        for(size_t i=0;i<dim.first;i++)
            for(size_t j=0;j<dim.second;j++)
                m[i][j] = (*this)[i][j] / amp;

    // step 2) cenering
    double average = 0;
    // find min, max, mean
    for(size_t i=0;i<dim.first;i++){
        for(size_t j=0;j<dim.second;j++)
        {
            average += m[i][j];
        }
    }
    double N = dim.first * dim.second;
    average /= N;
    if(average != 0)
        for(size_t i=0;i<dim.first;i++){
            for(size_t j=0;j<dim.second;j++)
            {
                m[i][j] = m[i][j] - average;
            }
        }

    // step 3) standardization
    // find sigma
    double sigma = 0;
    for(size_t i=0;i<dim.first;i++){
        for(size_t j=0;j<dim.second;j++)
        {
            double tmp = m[i][j];
            sigma += tmp*tmp;
        }
    }
    sigma = sqrt(sigma);
    if(sigma > 0)
        for(size_t i=0;i<dim.first;i++){
            for(size_t j=0;j<dim.second;j++)
            {
                m[i][j]/=sigma;
            }
        }

    return m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r12
movq (%rsi), %rbx
movq 0x8(%rsi), %rax
movq %rax, (%rsp)
subq %rbx, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %r14 # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %r14
movq (%rbx), %r13
movq 0x8(%rbx), %rbp
movq %rbp, %r15
subq %r13, %r15
sarq $0x3, %r15
movq %rdi, 0x8(%rsp)
movq %r14, %rsi
movq %r15, %rdx
callq 0x1a8c0
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x1c58e
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x1c630
subsd 0x10(%rsp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %al
cmpq %rbx, (%rsp)
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1c3af
movq (%r12), %rax
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
cmpq $0x1, %r15
movq %r15, %rdx
adcq $0x0, %rdx
cmpq $0x1, %r14
movq %r14, %rsi
adcq $0x0, %rsi
xorl %edi, %edi
cmpq %r13, %rbp
je 0x1c3a7
leaq (,%rdi,8), %r8
leaq (%r8,%r8,2), %r9
movq (%rax,%r9), %r8
movq (%rcx,%r9), %r9
xorl %r10d, %r10d
movsd (%r8,%r10,8), %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, (%r9,%r10,8)
incq %r10
cmpq %r10, %rdx
jne 0x1c38f
incq %rdi
cmpq %rsi, %rdi
jne 0x1c373
cmpq %rbx, (%rsp)
movq 0x8(%rsp), %r12
je 0x1c400
movq (%r12), %rax
cmpq $0x1, %r15
movq %r15, %rcx
adcq $0x0, %rcx
cmpq $0x1, %r14
movq %r14, %rdx
adcq $0x0, %rdx
xorpd %xmm1, %xmm1
xorl %esi, %esi
cmpq %r13, %rbp
je 0x1c3f8
leaq (%rsi,%rsi,2), %rdi
movq (%rax,%rdi,8), %rdi
xorl %r8d, %r8d
addsd (%rdi,%r8,8), %xmm1
incq %r8
cmpq %r8, %rcx
jne 0x1c3ea
incq %rsi
cmpq %rdx, %rsi
jne 0x1c3da
movq %r15, %rax
imulq %r14, %rax
movq %rax, %xmm0
punpckldq 0xac2c(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xac34(%rip), %xmm0     # 0x27050
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
divsd %xmm2, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
setp %al
setne %cl
orb %al, %cl
cmpq %rbx, (%rsp)
setne %al
andb %cl, %al
cmpb $0x1, %al
jne 0x1c495
movq (%r12), %rax
cmpq $0x1, %r15
movq %r15, %rcx
adcq $0x0, %rcx
cmpq $0x1, %r14
movq %r14, %rdx
adcq $0x0, %rdx
xorl %esi, %esi
cmpq %r13, %rbp
je 0x1c48d
leaq (%rsi,%rsi,2), %rdi
movq (%rax,%rdi,8), %rdi
xorl %r8d, %r8d
movsd (%rdi,%r8,8), %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rcx
jne 0x1c475
incq %rsi
cmpq %rdx, %rsi
jne 0x1c465
cmpq %rbx, (%rsp)
je 0x1c4e9
movq (%r12), %rax
cmpq $0x1, %r15
movq %r15, %rcx
adcq $0x0, %rcx
cmpq $0x1, %r14
movq %r14, %rdx
adcq $0x0, %rdx
xorpd %xmm0, %xmm0
xorl %esi, %esi
cmpq %r13, %rbp
je 0x1c4e1
leaq (%rsi,%rsi,2), %rdi
movq (%rax,%rdi,8), %rdi
xorl %r8d, %r8d
movsd (%rdi,%r8,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %r8
cmpq %r8, %rcx
jne 0x1c4cb
incq %rsi
cmpq %rdx, %rsi
jne 0x1c4bb
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1c4f9
sqrtsd %xmm0, %xmm0
jmp 0x1c502
callq 0x4438
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %al
cmpq %rbx, (%rsp)
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1c55a
movq (%r12), %rax
cmpq $0x1, %r15
adcq $0x0, %r15
cmpq $0x1, %r14
adcq $0x0, %r14
xorl %ecx, %ecx
cmpq %r13, %rbp
je 0x1c552
leaq (%rcx,%rcx,2), %rdx
movq (%rax,%rdx,8), %rdx
xorl %esi, %esi
movsd (%rdx,%rsi,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %r15
jne 0x1c53c
incq %rcx
cmpq %r14, %rcx
jne 0x1c52d
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c56e
movq %rax, %r14
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1e9ea
movq %rbx, %rdi
callq 0x146b8
movq %r14, %rdi
callq 0x43e0