// File: CastellanZhang[P]lambdaFM/./src/FTRL/ftrl_trainer.h
// Function: ftrl_trainer::trainGroupFastMode(std::vector<fm_sample, std::allocator<fm_sample>>&)
void ftrl_trainer::trainGroupFastMode(vector<fm_sample>& sampleGrp)
{
    int size = sampleGrp.size();
    variable_NDCG v_NDCG;
    if("ndcg" == rank)
    {
        v_NDCG.init(size);
        calcVariables4NDCG(sampleGrp, v_NDCG);
    }
    int factor_num = pModel->factor_num;
    vector<double> vecPred(size);
    vector<map<string, vector<double> > > vecGradPred2v(size);
    unordered_map<string, ftrl_model_unit*> theta;
    for(int i = 0; i < size; ++i)
    {
        for(unordered_map<string, double>::iterator iter = sampleGrp[i].x.begin(); iter != sampleGrp[i].x.end(); ++iter)
        {
            const string& index = iter->first;
            if(theta.find(index) == theta.end())
            {
                theta[index] = pModel->getOrInitModelUnit(index);
            }
        }
        vector<double> sum(factor_num);
        vecPred[i] = pModel->predict(sampleGrp[i].x, theta, sum);
        for(unordered_map<string, double>::iterator iter = sampleGrp[i].x.begin(); iter != sampleGrp[i].x.end(); ++iter)
        {
            const string& index = iter->first;
            const double& xi = iter->second;
            vector<double>& vi = theta[index]->vi;
            vecGradPred2v[i][index] = vector<double>(factor_num);
            for(int f = 0; f < factor_num; ++f)
            {
                vecGradPred2v[i][index][f] = sum[f] * xi - vi[f] * xi * xi;
            }
        }
    }
    for(int i = 0; i < size - 1; ++i)
    {
        for(int j = i + 1; j < size; ++j)
        {
            if(sampleGrp[i].y == sampleGrp[j].y)
            {
                continue;
            }
            double deltaNDCG = 1.0;
            if("ndcg" == rank)
            {
                deltaNDCG = calcDeltaNDCG(i, j, v_NDCG);
            }
            if(sampleGrp[i].y > sampleGrp[j].y)
            {
                trainPairFastMode(sampleGrp[i], sampleGrp[j], vecPred[i], vecPred[j], vecGradPred2v[i], vecGradPred2v[j], deltaNDCG);
            }
            else if(sampleGrp[i].y < sampleGrp[j].y)
            {
                trainPairFastMode(sampleGrp[j], sampleGrp[i], vecPred[j], vecPred[i], vecGradPred2v[j], vecGradPred2v[i], deltaNDCG);
            }
        }
    }
}

// Assembly:
subq $0x318, %rsp            # imm = 0x318
movq %rdi, 0x310(%rsp)
movq %rsi, 0x308(%rsp)
movq 0x310(%rsp), %rax
movq %rax, 0x148(%rsp)
movq 0x308(%rsp), %rdi
callq 0x8f60
movl %eax, 0x304(%rsp)
leaq 0x2a8(%rsp), %rdi
callq 0x8f80
movq 0x148(%rsp), %rsi
addq $0x58, %rsi
leaq 0x1693b(%rip), %rdi     # 0x1b046
callq 0x8fc0
movb %al, 0x157(%rsp)
jmp 0x4719
movb 0x157(%rsp), %al
testb $0x1, %al
jne 0x4726
jmp 0x4776
movl 0x304(%rsp), %esi
leaq 0x2a8(%rsp), %rdi
callq 0x8ff0
jmp 0x473c
movq 0x148(%rsp), %rdi
movq 0x308(%rsp), %rsi
leaq 0x2a8(%rsp), %rdx
callq 0x5550
jmp 0x475b
jmp 0x4776
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a0(%rsp)
movl %eax, 0x29c(%rsp)
jmp 0x526e
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x38(%rax), %eax
movl %eax, 0x298(%rsp)
movslq 0x304(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0x27f(%rsp), %rdi
movq %rdi, 0x140(%rsp)
callq 0x9240
movq 0x138(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x280(%rsp), %rdi
callq 0x9250
jmp 0x47d0
leaq 0x27f(%rsp), %rdi
callq 0x92d0
movslq 0x304(%rsp), %rax
movq %rax, 0x128(%rsp)
leaq 0x25f(%rsp), %rdi
movq %rdi, 0x130(%rsp)
callq 0x9340
movq 0x128(%rsp), %rsi
movq 0x130(%rsp), %rdx
leaq 0x260(%rsp), %rdi
callq 0x9350
jmp 0x4821
leaq 0x25f(%rsp), %rdi
callq 0x93d0
leaq 0x220(%rsp), %rdi
callq 0x8360
movl $0x0, 0x21c(%rsp)
movl 0x21c(%rsp), %eax
cmpl 0x304(%rsp), %eax
jge 0x4e8f
movq 0x308(%rsp), %rdi
movslq 0x21c(%rsp), %rsi
callq 0x9040
movq %rax, %rdi
addq $0x28, %rdi
callq 0x8690
movq %rax, 0x210(%rsp)
movq 0x308(%rsp), %rdi
movslq 0x21c(%rsp), %rsi
callq 0x9040
movq %rax, %rdi
addq $0x28, %rdi
callq 0x86e0
movq %rax, 0x208(%rsp)
leaq 0x210(%rsp), %rdi
leaq 0x208(%rsp), %rsi
callq 0x86c0
testb $0x1, %al
jne 0x48ca
jmp 0x4a6e
leaq 0x210(%rsp), %rdi
callq 0x8710
movq %rax, 0x200(%rsp)
movq 0x200(%rsp), %rsi
leaq 0x220(%rsp), %rdi
callq 0x8380
movq %rax, 0x120(%rsp)
jmp 0x48fe
movq 0x120(%rsp), %rax
movq %rax, 0x1f8(%rsp)
leaq 0x220(%rsp), %rdi
callq 0x83d0
movq %rax, 0x1f0(%rsp)
leaq 0x1f8(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x83b0
testb $0x1, %al
jne 0x4941
jmp 0x4a5a
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x118(%rsp)
movq 0x200(%rsp), %rsi
leaq 0x1d0(%rsp), %rdi
callq 0x3120
jmp 0x496c
movq 0x118(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x3960
movq %rax, 0x110(%rsp)
jmp 0x498b
movq 0x200(%rsp), %rsi
leaq 0x220(%rsp), %rdi
callq 0x8730
movq %rax, 0x108(%rsp)
jmp 0x49aa
movq 0x108(%rsp), %rax
movq 0x110(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x1d0(%rsp), %rdi
callq 0x3518
jmp 0x4a5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a0(%rsp)
movl %eax, 0x29c(%rsp)
leaq 0x27f(%rsp), %rdi
callq 0x92d0
jmp 0x526e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a0(%rsp)
movl %eax, 0x29c(%rsp)
leaq 0x25f(%rsp), %rdi
callq 0x93d0
jmp 0x5261
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a0(%rsp)
movl %eax, 0x29c(%rsp)
jmp 0x5247
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a0(%rsp)
movl %eax, 0x29c(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x3518
jmp 0x5247
jmp 0x4a5c
leaq 0x210(%rsp), %rdi
callq 0x8760
jmp 0x4883
movslq 0x298(%rsp), %rax
movq %rax, 0xf8(%rsp)
leaq 0x1b7(%rsp), %rdi
movq %rdi, 0x100(%rsp)
callq 0x9240
movq 0xf8(%rsp), %rsi
movq 0x100(%rsp), %rdx
leaq 0x1b8(%rsp), %rdi
callq 0x9250
jmp 0x4ab2
leaq 0x1b7(%rsp), %rdi
callq 0x92d0
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xe8(%rsp)
movq 0x308(%rsp), %rdi
movslq 0x21c(%rsp), %rsi
callq 0x9040
movq 0xe8(%rsp), %rdi
movq %rax, %rsi
addq $0x28, %rsi
leaq 0x220(%rsp), %rdx
leaq 0x1b8(%rsp), %rcx
callq 0x3ae0
movsd %xmm0, 0xf0(%rsp)
jmp 0x4b17
movslq 0x21c(%rsp), %rsi
leaq 0x280(%rsp), %rdi
callq 0x8790
movsd 0xf0(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x308(%rsp), %rdi
movslq 0x21c(%rsp), %rsi
callq 0x9040
movq %rax, %rdi
addq $0x28, %rdi
callq 0x8690
movq %rax, 0x1a8(%rsp)
movq 0x308(%rsp), %rdi
movslq 0x21c(%rsp), %rsi
callq 0x9040
movq %rax, %rdi
addq $0x28, %rdi
callq 0x86e0
movq %rax, 0x1a0(%rsp)
leaq 0x1a8(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x86c0
testb $0x1, %al
jne 0x4ba9
jmp 0x4e5a
leaq 0x1a8(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0x8710
movq 0xd8(%rsp), %rdi
movq %rax, 0x198(%rsp)
callq 0x8710
addq $0x20, %rax
movq %rax, 0x190(%rsp)
movq 0x198(%rsp), %rsi
leaq 0x220(%rsp), %rdi
callq 0x8730
movq %rax, 0xe0(%rsp)
jmp 0x4bfe
movq 0xe0(%rsp), %rax
movq (%rax), %rax
addq $0x18, %rax
movq %rax, 0x188(%rsp)
movslq 0x298(%rsp), %rax
movq %rax, 0xc8(%rsp)
leaq 0x16f(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
callq 0x9240
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
leaq 0x170(%rsp), %rdi
callq 0x9250
jmp 0x4c59
movslq 0x21c(%rsp), %rsi
leaq 0x260(%rsp), %rdi
callq 0x93e0
movq %rax, %rdi
movq 0x198(%rsp), %rsi
callq 0x9400
movq %rax, 0xc0(%rsp)
jmp 0x4c88
movq 0xc0(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x94f0
leaq 0x170(%rsp), %rdi
callq 0x8ec0
leaq 0x16f(%rsp), %rdi
callq 0x92d0
movl $0x0, 0x168(%rsp)
movl 0x168(%rsp), %eax
cmpl 0x298(%rsp), %eax
jge 0x4e46
movslq 0x168(%rsp), %rsi
leaq 0x1b8(%rsp), %rdi
callq 0x8790
movsd (%rax), %xmm0
movsd %xmm0, 0xa0(%rsp)
movq 0x190(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0xa8(%rsp)
movq 0x188(%rsp), %rdi
movslq 0x168(%rsp), %rsi
callq 0x8790
movsd 0xa0(%rsp), %xmm0
movsd 0xa8(%rsp), %xmm2
movsd (%rax), %xmm1
movq 0x190(%rsp), %rax
movsd (%rax), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0xb0(%rsp)
movslq 0x21c(%rsp), %rsi
leaq 0x260(%rsp), %rdi
callq 0x93e0
movq %rax, %rdi
movq 0x198(%rsp), %rsi
callq 0x9400
movq %rax, 0xb8(%rsp)
jmp 0x4d8c
movq 0xb8(%rsp), %rdi
movslq 0x168(%rsp), %rsi
callq 0x8790
movsd 0xb0(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x168(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x168(%rsp)
jmp 0x4cc2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a0(%rsp)
movl %eax, 0x29c(%rsp)
leaq 0x1b7(%rsp), %rdi
callq 0x92d0
jmp 0x5247
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a0(%rsp)
movl %eax, 0x29c(%rsp)
jmp 0x4e7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a0(%rsp)
movl %eax, 0x29c(%rsp)
jmp 0x4e37
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a0(%rsp)
movl %eax, 0x29c(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x8ec0
leaq 0x16f(%rsp), %rdi
callq 0x92d0
jmp 0x4e7d
jmp 0x4e48
leaq 0x1a8(%rsp), %rdi
callq 0x8760
jmp 0x4b62
leaq 0x1b8(%rsp), %rdi
callq 0x8ec0
movl 0x21c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x21c(%rsp)
jmp 0x4846
leaq 0x1b8(%rsp), %rdi
callq 0x8ec0
jmp 0x5247
movl $0x0, 0x164(%rsp)
movl 0x164(%rsp), %eax
movl 0x304(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x520b
movl 0x164(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x160(%rsp)
movl 0x160(%rsp), %eax
cmpl 0x304(%rsp), %eax
jge 0x51f3
movq 0x308(%rsp), %rdi
movslq 0x164(%rsp), %rsi
callq 0x9040
movl (%rax), %eax
movl %eax, 0x9c(%rsp)
movq 0x308(%rsp), %rdi
movslq 0x160(%rsp), %rsi
callq 0x9040
movq %rax, %rcx
movl 0x9c(%rsp), %eax
cmpl (%rcx), %eax
jne 0x4f1e
jmp 0x51dd
movq 0x148(%rsp), %rsi
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x158(%rsp)
addq $0x58, %rsi
leaq 0x16103(%rip), %rdi     # 0x1b046
callq 0x8fc0
movb %al, 0x9b(%rsp)
jmp 0x4f51
movb 0x9b(%rsp), %al
testb $0x1, %al
jne 0x4f5e
jmp 0x4f9e
movq 0x148(%rsp), %rdi
movl 0x164(%rsp), %esi
movl 0x160(%rsp), %edx
leaq 0x2a8(%rsp), %rcx
callq 0x9060
movsd %xmm0, 0x90(%rsp)
jmp 0x4f8c
movsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x158(%rsp)
movq 0x308(%rsp), %rdi
movslq 0x164(%rsp), %rsi
callq 0x9040
movl (%rax), %eax
movl %eax, 0x8c(%rsp)
movq 0x308(%rsp), %rdi
movslq 0x160(%rsp), %rsi
callq 0x9040
movq %rax, %rcx
movl 0x8c(%rsp), %eax
cmpl (%rcx), %eax
jle 0x50c3
movq 0x308(%rsp), %rdi
movslq 0x164(%rsp), %rsi
callq 0x9040
movq %rax, 0x60(%rsp)
movq 0x308(%rsp), %rdi
movslq 0x160(%rsp), %rsi
callq 0x9040
movq %rax, 0x68(%rsp)
movslq 0x164(%rsp), %rsi
leaq 0x280(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x8790
movq 0x50(%rsp), %rdi
movq %rax, 0x70(%rsp)
movslq 0x160(%rsp), %rsi
callq 0x8790
movq %rax, 0x78(%rsp)
movslq 0x164(%rsp), %rsi
leaq 0x260(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x93e0
movq 0x58(%rsp), %rdi
movq %rax, 0x80(%rsp)
movslq 0x160(%rsp), %rsi
callq 0x93e0
movq 0x148(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %r8
movq 0x80(%rsp), %r9
movq %rax, %r10
movsd 0x158(%rsp), %xmm0
movq %rsp, %rax
movq %r10, (%rax)
callq 0x6a80
jmp 0x50be
jmp 0x51db
movq 0x308(%rsp), %rdi
movslq 0x164(%rsp), %rsi
callq 0x9040
movl (%rax), %eax
movl %eax, 0x4c(%rsp)
movq 0x308(%rsp), %rdi
movslq 0x160(%rsp), %rsi
callq 0x9040
movq %rax, %rcx
movl 0x4c(%rsp), %eax
cmpl (%rcx), %eax
jge 0x51d9
movq 0x308(%rsp), %rdi
movslq 0x160(%rsp), %rsi
callq 0x9040
movq %rax, 0x20(%rsp)
movq 0x308(%rsp), %rdi
movslq 0x164(%rsp), %rsi
callq 0x9040
movq %rax, 0x28(%rsp)
movslq 0x160(%rsp), %rsi
leaq 0x280(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x8790
movq 0x10(%rsp), %rdi
movq %rax, 0x30(%rsp)
movslq 0x164(%rsp), %rsi
callq 0x8790
movq %rax, 0x38(%rsp)
movslq 0x160(%rsp), %rsi
leaq 0x260(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x93e0
movq 0x18(%rsp), %rdi
movq %rax, 0x40(%rsp)
movslq 0x164(%rsp), %rsi
callq 0x93e0
movq 0x148(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %r8
movq 0x40(%rsp), %r9
movq %rax, %r10
movsd 0x158(%rsp), %xmm0
movq %rsp, %rax
movq %r10, (%rax)
callq 0x6a80
jmp 0x51d7
jmp 0x51d9
jmp 0x51db
jmp 0x51dd
movl 0x160(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x160(%rsp)
jmp 0x4ec4
jmp 0x51f5
movl 0x164(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x164(%rsp)
jmp 0x4e9a
leaq 0x220(%rsp), %rdi
callq 0x9330
leaq 0x260(%rsp), %rdi
callq 0x9530
leaq 0x280(%rsp), %rdi
callq 0x8ec0
leaq 0x2a8(%rsp), %rdi
callq 0x9170
addq $0x318, %rsp            # imm = 0x318
retq
leaq 0x220(%rsp), %rdi
callq 0x9330
leaq 0x260(%rsp), %rdi
callq 0x9530
leaq 0x280(%rsp), %rdi
callq 0x8ec0
leaq 0x2a8(%rsp), %rdi
callq 0x9170
movq 0x2a0(%rsp), %rdi
callq 0x3490
nopl (%rax,%rax)