// File: /workspace/github_cpp_makefile_star2_O1/CastellanZhang[P]lambdaFM/./src/FTRL/ftrl_trainer.h
// Function: ftrl_trainer::trainPairFastMode(fm_sample&, fm_sample&, double&, double&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<double, std::allocator<double>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::vector<double, std::allocator<double>>>>>&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<double, std::allocator<double>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::vector<double, std::allocator<double>>>>>&, double)
void ftrl_trainer::trainPairFastMode(fm_sample& sample1, fm_sample& sample2, double& pred1, double& pred2,
    map<string, vector<double> >& grad1, map<string, vector<double> >& grad2, const double deltaNDCG)
{
    unordered_map<string, ftrl_model_unit*> theta;
    for(unordered_map<string, double>::iterator iter = sample1.x.begin(); iter != sample1.x.end(); ++iter)
    {
        const string& index = iter->first;
        if(theta.find(index) == theta.end())
        {
            theta[index] = pModel->getOrInitModelUnit(index);
        }
    }
    for(unordered_map<string, double>::iterator iter = sample2.x.begin(); iter != sample2.x.end(); ++iter)
    {
        const string& index = iter->first;
        if(theta.find(index) == theta.end())
        {
            theta[index] = pModel->getOrInitModelUnit(index);
        }
    }
    //update w via FTRL
    if(k1)
    {
        for(unordered_map<string, ftrl_model_unit*>::iterator iter = theta.begin(); iter != theta.end(); ++iter)
        {
            ftrl_model_unit& mu = *(iter->second);
            mu.mtx.lock();
            if(fabs(mu.w_zi) <= w_l1)
            {
                mu.wi = 0.0;
            }
            else
            {
                if(force_v_sparse && mu.w_ni > 0 && 0.0 == mu.wi)
                {
                    mu.reinit_vi(pModel->init_mean, pModel->init_stdev);
                }
                mu.wi = (-1) *
                    (1 / (w_l2 + (w_beta + sqrt(mu.w_ni)) / w_alpha)) *
                    (mu.w_zi - utils::sgn(mu.w_zi) * w_l1);
            }
            mu.mtx.unlock();
        }
    }
    //update v via FTRL
    for(unordered_map<string, ftrl_model_unit*>::iterator iter = theta.begin(); iter != theta.end(); ++iter)
    {
        ftrl_model_unit& mu = *(iter->second);
        for(int f = 0; f < pModel->factor_num; ++f)
        {
            mu.mtx.lock();
            double& vif = mu.vi[f];
            double& v_nif = mu.v_ni[f];
            double& v_zif = mu.v_zi[f];
            if(v_nif > 0)
            {
                if(force_v_sparse && 0.0 == mu.wi)
                {
                    vif = 0.0;
                }
                else if(fabs(v_zif) <= v_l1)
                {
                    vif = 0.0;
                }
                else
                {
                    vif = (-1) *
                        (1 / (v_l2 + (v_beta + sqrt(v_nif)) / v_alpha)) *
                        (v_zif - utils::sgn(v_zif) * v_l1);
                }
            }
            mu.mtx.unlock();
        }
    }
    double lambda12 = -1 / (1 + exp(pred1 - pred2)) * deltaNDCG;
    //update w_n, w_z
    if(k1)
    {
        for(unordered_map<string, ftrl_model_unit*>::iterator iter = theta.begin(); iter != theta.end(); ++iter)
        {
            ftrl_model_unit& mu = *(iter->second);
            const string& index = iter->first;
            unordered_map<string, double>::iterator iter_x1 = sample1.x.find(index);
            double xi1 = (iter_x1 == sample1.x.end()) ? 0 : iter_x1->second;
            unordered_map<string, double>::iterator iter_x2 = sample2.x.find(index);
            double xi2 = (iter_x2 == sample2.x.end()) ? 0 : iter_x2->second;
            double xi = xi1 - xi2;
            if(xi != 0)
            {
                mu.mtx.lock();
                double w_gi = lambda12 * xi;
                double w_si = 1 / w_alpha * (sqrt(mu.w_ni + w_gi * w_gi) - sqrt(mu.w_ni));
                mu.w_zi += w_gi - w_si * mu.wi;
                mu.w_ni += w_gi * w_gi;
                mu.mtx.unlock();
            }
        }
    }
    //update v_n, v_z
    vector<double> vecZero(pModel->factor_num, 0);
    for(unordered_map<string, ftrl_model_unit*>::iterator iter = theta.begin(); iter != theta.end(); ++iter)
    {
        ftrl_model_unit& mu = *(iter->second);
        const string& index = iter->first;
        unordered_map<string, double>::iterator iter_x1 = sample1.x.find(index);
        double xi1 = (iter_x1 == sample1.x.end()) ? 0 : iter_x1->second;
        unordered_map<string, double>::iterator iter_x2 = sample2.x.find(index);
        double xi2 = (iter_x2 == sample2.x.end()) ? 0 : iter_x2->second;
        vector<double>* pGrad1Index = &vecZero;
        map<string, vector<double> >::iterator gradIter1 = grad1.find(index);
        if(gradIter1 != grad1.end())
        {
            pGrad1Index = &(gradIter1->second);
        }
        vector<double>* pGrad2Index = &vecZero;
        map<string, vector<double> >::iterator gradIter2 = grad2.find(index);
        if(gradIter2 != grad2.end())
        {
            pGrad2Index = &(gradIter2->second);
        }
        for(int f = 0; f < pModel->factor_num; ++f)
        {
            mu.mtx.lock();
            double& vif = mu.vi[f];
            double& v_nif = mu.v_ni[f];
            double& v_zif = mu.v_zi[f];
            double v_gif = lambda12 * ((*pGrad1Index)[f] - (*pGrad2Index)[f]);
            double v_sif = 1 / v_alpha * (sqrt(v_nif + v_gif * v_gif) - sqrt(v_nif));
            v_zif += v_gif - v_sif * vif;
            v_nif += v_gif * v_gif;
            //有的特征在整个训练集中只出现一次，这里还需要对vif做一次处理
            if(force_v_sparse && v_nif > 0 && 0.0 == mu.wi)
            {
                vif = 0.0;
            }
            mu.mtx.unlock();
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movsd %xmm0, 0x68(%rsp)
movq %r9, 0x70(%rsp)
movq %r8, 0x60(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rdi, 0x28(%rsp)
leaq 0xc8(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movupd %xmm0, -0x8(%rax)
movq %rsi, 0x58(%rsp)
movq 0x38(%rsi), %r15
testq %r15, %r15
je 0x5695
leaq 0x100(%rsp), %r12
leaq 0x98(%rsp), %rbx
leaq 0xf0(%rsp), %r13
leaq 0x8(%r15), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x853c
testq %rax, %rax
jne 0x568d
movq 0x28(%rsp), %rax
movq 0x8(%rax), %r14
movq %r12, 0xf0(%rsp)
movq 0x8(%r15), %rsi
movq 0x10(%r15), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x8304
movq %r14, %rdi
movq %r13, %rsi
callq 0x387e
movq %rax, %r14
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x8968
movq %r14, (%rax)
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
je 0x568d
callq 0x32a0
movq (%r15), %r15
testq %r15, %r15
jne 0x5627
movq 0x48(%rsp), %rax
movq 0x38(%rax), %r15
testq %r15, %r15
je 0x572d
leaq 0xe0(%rsp), %r12
leaq 0x98(%rsp), %rbx
leaq 0xd0(%rsp), %r13
leaq 0x8(%r15), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x853c
testq %rax, %rax
jne 0x5725
movq 0x28(%rsp), %rax
movq 0x8(%rax), %r14
movq %r12, 0xd0(%rsp)
movq 0x8(%r15), %rsi
movq 0x10(%r15), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x8304
movq %r14, %rdi
movq %r13, %rsi
callq 0x387e
movq %rax, %r14
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x8968
movq %r14, (%rax)
movq 0xd0(%rsp), %rdi
cmpq %r12, %rdi
je 0x5725
callq 0x32a0
movq (%r15), %r15
testq %r15, %r15
jne 0x56bf
movq 0x28(%rsp), %rbp
cmpb $0x0, 0x50(%rbp)
je 0x586f
movq 0xa8(%rsp), %r14
testq %r14, %r14
je 0x586f
movq 0x28(%r14), %r13
leaq 0x60(%r13), %rbx
movq %rbx, %rdi
callq 0x33a0
testl %eax, %eax
jne 0x5e08
movsd 0x10(%r13), %xmm0
andpd 0x68bd(%rip), %xmm0     # 0xc030
movsd 0x20(%rbp), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm1
jae 0x5859
cmpb $0x1, 0x51(%rbp)
jne 0x57c4
movsd 0x8(%r13), %xmm0
ucomisd 0x6886(%rip), %xmm0     # 0xc020
jbe 0x57c4
movsd (%r13), %xmm0
ucomisd 0x6876(%rip), %xmm0     # 0xc020
jne 0x57c4
jp 0x57c4
movq 0x8(%rbp), %rax
movsd 0x40(%rax), %xmm1
movsd 0x48(%rax), %xmm0
movq %r13, %rdi
callq 0x6a82
movsd 0x18(%rbp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x28(%rbp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%r13), %xmm0
ucomisd 0x6838(%rip), %xmm0     # 0xc020
jb 0x57f0
sqrtsd %xmm0, %xmm0
jmp 0x57f5
callq 0x3220
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rbp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x10(%r13), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0xb406
movsd 0x20(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x67dd(%rip), %xmm0     # 0xc018
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x20(%rbp), %xmm1
movsd 0x18(%rsp), %xmm2
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, (%r13)
movq %rbx, %rdi
callq 0x31f0
movq (%r14), %r14
jmp 0x5744
movq 0xa8(%rsp), %rax
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x59f1
movq 0x28(%rsp), %r14
movq 0x8(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jle 0x59db
movq 0x38(%rsp), %rax
movq 0x28(%rax), %r15
leaq 0x60(%r15), %rbx
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x33a0
testl %eax, %eax
jne 0x5dfa
movq 0x30(%r15), %rax
movsd (%rax,%r13,8), %xmm0
ucomisd 0x6756(%rip), %xmm0     # 0xc020
jbe 0x59bf
movq 0x18(%r15), %r12
movq %rbp, %rax
movq 0x48(%r15), %rbp
cmpb $0x1, 0x51(%rax)
jne 0x58f6
movsd (%r15), %xmm1
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm1
jne 0x58f6
jnp 0x59b4
movsd (%rbp,%r13,8), %xmm1
andpd 0x672b(%rip), %xmm1     # 0xc030
movq 0x28(%rsp), %rax
movsd 0x40(%rax), %xmm2
xorpd %xmm3, %xmm3
ucomisd %xmm1, %xmm2
jae 0x59b4
movq 0x28(%rsp), %rax
movsd 0x38(%rax), %xmm1
movsd %xmm1, 0x18(%rsp)
movsd 0x48(%rax), %xmm1
movsd %xmm1, 0x20(%rsp)
ucomisd 0x66e0(%rip), %xmm0     # 0xc020
jb 0x5948
sqrtsd %xmm0, %xmm0
jmp 0x594d
callq 0x3220
movsd %xmm0, 0x10(%rsp)
movsd 0x30(%r14), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd (%rbp,%r13,8), %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0xb406
movsd 0x18(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x6683(%rip), %xmm0     # 0xc018
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x40(%r14), %xmm1
movsd 0x8(%rsp), %xmm3
subsd %xmm1, %xmm3
mulsd %xmm0, %xmm3
movsd %xmm3, (%r12,%r13,8)
movq 0x28(%rsp), %rbp
movq %rbx, %rdi
callq 0x31f0
incq %r13
movq 0x8(%rbp), %rax
movslq 0x38(%rax), %rax
cmpq %rax, %r13
jl 0x58a8
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
testq %rax, %rax
jne 0x588a
addq $0x28, 0x58(%rsp)
addq $0x28, 0x48(%rsp)
movq 0x50(%rsp), %rax
movsd (%rax), %xmm0
movq 0x60(%rsp), %rax
subsd (%rax), %xmm0
callq 0x3490
addsd 0x65f4(%rip), %xmm0     # 0xc010
movsd 0x65f4(%rip), %xmm1     # 0xc018
divsd %xmm0, %xmm1
mulsd 0x68(%rsp), %xmm1
movsd %xmm1, 0x38(%rsp)
cmpb $0x0, 0x50(%rbp)
je 0x5b96
movq 0xa8(%rsp), %r14
testq %r14, %r14
je 0x5b96
leaq 0x8(%r14), %rbx
movq 0x28(%r14), %r15
movq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x8424
testq %rax, %rax
je 0x5a70
movsd 0x28(%rax), %xmm0
jmp 0x5a74
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x8424
testq %rax, %rax
je 0x5a93
movsd 0x28(%rax), %xmm0
jmp 0x5a97
xorpd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
ucomisd 0x6571(%rip), %xmm1     # 0xc020
jne 0x5ab7
jnp 0x5b8e
leaq 0x60(%r15), %rbx
movq %rbx, %rdi
callq 0x33a0
testl %eax, %eax
jne 0x5e0f
movsd 0x8(%rsp), %xmm0
mulsd 0x38(%rsp), %xmm0
movsd 0x10(%rbp), %xmm2
movsd %xmm0, 0x8(%rsp)
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd 0x8(%r15), %xmm0
addsd %xmm1, %xmm0
ucomisd 0x6524(%rip), %xmm0     # 0xc020
movsd %xmm1, 0x20(%rsp)
movsd %xmm2, 0x18(%rsp)
jb 0x5b13
xorps %xmm3, %xmm3
sqrtsd %xmm0, %xmm3
jmp 0x5b1c
callq 0x3220
movapd %xmm0, %xmm3
movsd 0x8(%r15), %xmm0
ucomisd 0x64f6(%rip), %xmm0     # 0xc020
jb 0x5b32
sqrtsd %xmm0, %xmm0
jmp 0x5b43
movsd %xmm3, 0x10(%rsp)
callq 0x3220
movsd 0x10(%rsp), %xmm3
movsd 0x20(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
subsd %xmm0, %xmm3
movsd 0x64bd(%rip), %xmm0     # 0xc018
divsd %xmm2, %xmm0
mulsd %xmm3, %xmm0
mulsd (%r15), %xmm0
addsd 0x8(%rsp), %xmm0
addsd 0x10(%r15), %xmm0
movsd %xmm0, 0x10(%r15)
addsd 0x8(%r15), %xmm1
movsd %xmm1, 0x8(%r15)
movq %rbx, %rdi
callq 0x31f0
movq (%r14), %r14
jmp 0x5a46
movq 0x8(%rbp), %rax
movslq 0x38(%rax), %rsi
leaq 0x110(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x80(%rsp), %rdi
leaq 0x37(%rsp), %rcx
callq 0x6cd2
movq 0xa8(%rsp), %rcx
testq %rcx, %rcx
je 0x5dc9
movq 0x150(%rsp), %rdx
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x50(%rsp)
leaq 0x8(%rdx), %rax
movq %rax, 0x78(%rsp)
leaq 0x8(%rcx), %rbx
movq %rcx, 0x60(%rsp)
movq 0x28(%rcx), %r13
movq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x8424
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x8424
leaq 0x80(%rsp), %r14
movq 0x70(%rsp), %rdi
movq %rbx, %rsi
callq 0x8f28
leaq 0x40(%rax), %rcx
cmpq 0x50(%rsp), %rax
cmoveq %r14, %rcx
movq %rcx, 0x10(%rsp)
movq 0x150(%rsp), %rdi
movq %rbx, %rsi
callq 0x8f28
leaq 0x40(%rax), %rcx
cmpq 0x78(%rsp), %rax
cmoveq %r14, %rcx
movq %rcx, 0x40(%rsp)
movq 0x8(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jle 0x5db8
leaq 0x60(%r13), %rbx
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x33a0
testl %eax, %eax
jne 0x5e01
movq 0x18(%r13), %r12
movq %rbp, %rcx
movq 0x30(%r13), %rbp
movq 0x48(%r13), %r15
movq 0x10(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r14,8), %xmm2
movq 0x40(%rsp), %rax
movq (%rax), %rax
subsd (%rax,%r14,8), %xmm2
mulsd 0x38(%rsp), %xmm2
movsd 0x30(%rcx), %xmm3
movapd %xmm2, %xmm1
mulsd %xmm2, %xmm1
movsd (%rbp,%r14,8), %xmm0
addsd %xmm1, %xmm0
ucomisd 0x634b(%rip), %xmm0     # 0xc020
movsd %xmm1, 0x8(%rsp)
movsd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x18(%rsp)
jb 0x5cf2
xorps %xmm4, %xmm4
sqrtsd %xmm0, %xmm4
jmp 0x5cfb
callq 0x3220
movapd %xmm0, %xmm4
movsd (%rbp,%r14,8), %xmm0
ucomisd 0x6316(%rip), %xmm0     # 0xc020
jb 0x5d12
sqrtsd %xmm0, %xmm0
jmp 0x5d23
movsd %xmm4, 0x68(%rsp)
callq 0x3220
movsd 0x68(%rsp), %xmm4
movsd 0x8(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
subsd %xmm0, %xmm4
movsd 0x62d7(%rip), %xmm0     # 0xc018
divsd %xmm3, %xmm0
mulsd %xmm4, %xmm0
mulsd (%r12,%r14,8), %xmm0
addsd %xmm2, %xmm0
addsd (%r15,%r14,8), %xmm0
movsd %xmm0, (%r15,%r14,8)
addsd (%rbp,%r14,8), %xmm1
movsd %xmm1, (%rbp,%r14,8)
movq 0x28(%rsp), %rbp
cmpb $0x1, 0x51(%rbp)
jne 0x5d9c
ucomisd 0x62a0(%rip), %xmm1     # 0xc020
jbe 0x5d9c
movsd (%r13), %xmm0
ucomisd 0x6290(%rip), %xmm0     # 0xc020
jne 0x5d9c
jp 0x5d9c
movq $0x0, (%r12,%r14,8)
movq %rbx, %rdi
callq 0x31f0
incq %r14
movq 0x8(%rbp), %rax
movslq 0x38(%rax), %rax
cmpq %rax, %r14
jl 0x5c74
movq 0x60(%rsp), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x5bef
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x5ddb
callq 0x32a0
leaq 0x98(%rsp), %rdi
callq 0x7e72
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x31a0
movl %eax, %edi
callq 0x31a0
movl %eax, %edi
callq 0x31a0
movl %eax, %edi
callq 0x31a0
jmp 0x5e6a
jmp 0x5e6a
jmp 0x5e6a
jmp 0x5e6a
jmp 0x5e6a
jmp 0x5e6a
jmp 0x5e6a
jmp 0x5e6a
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
jmp 0x5e3e
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
jne 0x5e63
jmp 0x5e6d
jmp 0x5e53
jmp 0x5e53
jmp 0x5e53
jmp 0x5e53
jmp 0x5e6a
jmp 0x5e6a
jmp 0x5e6a
movq %rax, %rbx
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x5e6d
callq 0x32a0
jmp 0x5e6d
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x7e72
movq %rbx, %rdi
callq 0x3470