// File: /workspace/github_cpp_makefile_star2_O3/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 0x1a800
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x1c49e
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x1c540
subsd 0x10(%rsp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %al
cmpq %rbx, (%rsp)
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1c2bd
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 0x1c2b5
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 0x1c29d
incq %rdi
cmpq %rsi, %rdi
jne 0x1c281
cmpq %rbx, (%rsp)
movq 0x8(%rsp), %r12
je 0x1c30e
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 0x1c306
leaq (%rsi,%rsi,2), %rdi
movq (%rax,%rdi,8), %rdi
xorl %r8d, %r8d
addsd (%rdi,%r8,8), %xmm1
incq %r8
cmpq %r8, %rcx
jne 0x1c2f8
incq %rsi
cmpq %rdx, %rsi
jne 0x1c2e8
cmpq %rbx, (%rsp)
setne %al
movq %r15, %rcx
imulq %r14, %rcx
movq %rcx, %xmm0
punpckldq 0xad17(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xad1f(%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 %cl
setne %dl
orb %cl, %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x1c3a4
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 0x1c39c
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 0x1c384
incq %rsi
cmpq %rdx, %rsi
jne 0x1c374
cmpq %rbx, (%rsp)
je 0x1c3f8
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 0x1c3f0
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 0x1c3da
incq %rsi
cmpq %rdx, %rsi
jne 0x1c3ca
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1c408
sqrtsd %xmm0, %xmm0
jmp 0x1c411
callq 0x4438
xorpd %xmm1, %xmm1
cmpq %rbx, (%rsp)
setne %al
ucomisd %xmm1, %xmm0
seta %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1c469
movq (%r12), %rax
cmpq $0x1, %r15
adcq $0x0, %r15
cmpq $0x1, %r14
adcq $0x0, %r14
xorl %ecx, %ecx
cmpq %r13, %rbp
je 0x1c461
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 0x1c44b
incq %rcx
cmpq %r14, %rcx
jne 0x1c43c
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c47d
movq %rax, %r14
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1e8dc
movq %rbx, %rdi
callq 0x14578
movq %r14, %rdi
callq 0x43e0
nop