// File: /workspace/github_cpp_makefile_star2_O3/btbujiangjun[P]abcdl/src/fnn/FNN.cpp
// Function: abcdl::fnn::FNN::evaluate(abcdl::algebra::Matrix<float> const&, abcdl::algebra::Matrix<float> const&, float*)
size_t FNN::evaluate(const abcdl::algebra::Mat& test_data,
                     const abcdl::algebra::Mat& test_label,
                     real* loss){
    CHECK(test_data.rows() > 0);
    CHECK(test_data.cols() == _layers[0]->get_input_dim());
    CHECK(test_data.rows() == test_label.rows());
    CHECK(test_label.cols() == _layers[_layers.size() - 1]->get_output_dim());

    auto now = []{return std::chrono::system_clock::now();};
    auto start_time = now();
    
    size_t rows = test_data.rows();
    size_t predict_num = 0;
    abcdl::algebra::Mat mat;

    real total_loss = 0;
    std::vector<std::pair<real, real>> auc_evaluate_vec;

    for(size_t i = 0; i < rows; i++){
        predict(mat, test_data.get_row(i));
		if(mat.argmax() == test_label.get_row(i).argmax()){
            ++ predict_num; 
        }
        auc_evaluate_vec.push_back(std::make_pair(test_label.get_row(i).argmax(), mat.argmax()));
        total_loss += _loss->loss(test_label.get_row(i), mat);
    }

    *loss = total_loss / rows;
    double auc_score = auc(auc_evaluate_vec); 
    LOG(INFO) << "evaluate auc[" << auc_score << "] loss[" << *loss << "] ["<< predict_num <<"/" << rows << "] rate[" << predict_num/(real)rows << "]";
    auto predict_time = now();
    printf("evaluate auc[%lf] loss[%f] rate[%f] [%zu/%zu]predict run time:[%lld]ms\n", auc_score, *loss, predict_num/(real)rows, predict_num, rows, (long long int)std::chrono::duration_cast<std::chrono::milliseconds>(predict_time - start_time).count());
    return predict_num;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rcx, 0x10(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
cmpq $0x0, (%rsi)
je 0x160af
movq 0x8(%r15), %rax
movq 0x30(%r12), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx), %rax
jne 0x160f6
movq (%r15), %rax
cmpq (%r14), %rax
jne 0x1613d
movq 0x8(%r14), %rax
movq 0x38(%r12), %rcx
movq -0x8(%rcx), %rcx
cmpq 0x10(%rcx), %rax
jne 0x16184
callq 0x9070
movq %rax, 0x48(%rsp)
movq (%r15), %r13
leaq 0x68(%rsp), %rdi
callq 0x197e0
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %r13, %r13
je 0x15e8b
movq %r12, 0x40(%rsp)
movq %r14, 0x8(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, (%rsp)
xorl %ebx, %ebx
leaq 0x90(%rsp), %r14
leaq 0x68(%rsp), %r12
xorl %ebp, %ebp
movq %r13, 0x58(%rsp)
movq %r15, 0x50(%rsp)
movl $0x1, %ecx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x19dec
movq 0x40(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x16240
movq %r14, %rdi
callq 0x19a36
movq %r12, %r15
movq %r12, %rdi
callq 0x2ab7a
movq %rax, %r12
movl $0x1, %ecx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x19dec
movq %rbp, 0x60(%rsp)
movq %r14, %rdi
callq 0x2ab7a
xorl %r13d, %r13d
cmpq %rax, %r12
sete %bpl
movq %r14, %rdi
callq 0x19a36
movl $0x1, %ecx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x19dec
movq %r14, %rdi
callq 0x2ab7a
movq %rax, %r12
movq %r15, %rdi
callq 0x2ab7a
testq %r12, %r12
js 0x15da5
cvtsi2ss %r12, %xmm0
jmp 0x15dbb
movq %r12, %rcx
shrq %rcx
andl $0x1, %r12d
orq %rcx, %r12
cvtsi2ss %r12, %xmm0
addss %xmm0, %xmm0
movss %xmm0, 0x18(%rsp)
testq %rax, %rax
js 0x15dd0
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x15de8
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x15e0a
movq 0x18(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x28(%rsp)
jmp 0x15e19
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x17c6c
movq %r14, %rdi
callq 0x19a36
movq 0x40(%rsp), %rax
movq 0x48(%rax), %r12
movl $0x1, %ecx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x19dec
movq (%r12), %rax
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %r12
movq %r15, %rdx
callq *0x10(%rax)
movb %bpl, %r13b
movq 0x60(%rsp), %rbp
addq %r13, %rbp
movss (%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, (%rsp)
movq %r14, %rdi
callq 0x19a36
incq %rbx
movq 0x58(%rsp), %r13
cmpq %rbx, %r13
movq 0x50(%rsp), %r15
jne 0x15d04
jmp 0x15e95
xorps %xmm0, %xmm0
movss %xmm0, (%rsp)
xorl %ebp, %ebp
testq %r13, %r13
js 0x15ea4
xorps %xmm1, %xmm1
cvtsi2ss %r13, %xmm1
jmp 0x15ebf
movq %r13, %rax
shrq %rax
movl %r13d, %ecx
andl $0x1, %ecx
orq %rax, %rcx
xorps %xmm1, %xmm1
cvtsi2ss %rcx, %xmm1
addss %xmm1, %xmm1
movss (%rsp), %xmm0
movss %xmm1, (%rsp)
divss %xmm1, %xmm0
movq 0x10(%rsp), %rax
movss %xmm0, (%rax)
leaq 0x20(%rsp), %rsi
callq 0x15a9e
movsd %xmm0, 0x8(%rsp)
leaq 0x26103(%rip), %rsi     # 0x3bff0
leaq 0x90(%rsp), %rdi
movl $0x6c, %edx
xorl %ecx, %ecx
callq 0x387b6
leaq 0x26319(%rip), %rsi     # 0x3c221
leaq 0x90(%rsp), %rdi
movl $0xd, %edx
callq 0x93b0
leaq 0x90(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
callq 0x9540
leaq 0x261b6(%rip), %rsi     # 0x3c0ea
leaq 0x90(%rsp), %rdi
movl $0x7, %edx
callq 0x93b0
movq 0x10(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
leaq 0x90(%rsp), %rdi
callq 0x9540
leaq 0x262c9(%rip), %rsi     # 0x3c22f
leaq 0x90(%rsp), %rdi
movl $0x3, %edx
callq 0x93b0
leaq 0x90(%rsp), %rdi
movq %rbp, %rsi
callq 0x9200
leaq 0x24279(%rip), %rsi     # 0x3a208
leaq 0x90(%rsp), %rdi
movl $0x1, %edx
callq 0x93b0
leaq 0x90(%rsp), %rdi
movq %r13, %rsi
callq 0x9200
leaq 0x2627b(%rip), %rsi     # 0x3c233
leaq 0x90(%rsp), %rdi
movl $0x7, %edx
callq 0x93b0
testq %rbp, %rbp
js 0x15fd9
xorps %xmm0, %xmm0
cvtsi2ss %rbp, %xmm0
jmp 0x15ff3
movq %rbp, %rax
shrq %rax
movl %ebp, %ecx
andl $0x1, %ecx
orq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
divss (%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x90(%rsp), %rdi
movsd %xmm0, (%rsp)
callq 0x9540
leaq 0x26436(%rip), %rsi     # 0x3c44b
leaq 0x90(%rsp), %rdi
movl $0x1, %edx
callq 0x93b0
leaq 0x90(%rsp), %rdi
callq 0x389de
callq 0x9070
subq 0x48(%rsp), %rax
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
imulq %rcx
movq %rdx, %rcx
shrq $0x3f, %rcx
sarq $0x12, %rdx
addq %rdx, %rcx
movq 0x10(%rsp), %rax
cvtss2sd (%rax), %xmm1
leaq 0x261d2(%rip), %rdi     # 0x3c23b
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm2
movq %rbp, %rsi
movq %r13, %rdx
movb $0x3, %al
callq 0x9060
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x16090
callq 0x9350
leaq 0x68(%rsp), %rdi
callq 0x19a36
movq %rbp, %rax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25f3a(%rip), %rsi     # 0x3bff0
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl $0x52, %edx
movl $0x3, %ecx
callq 0x387b6
leaq 0x26064(%rip), %rsi     # 0x3c13b
movl $0x22, %edx
movq %rbx, %rdi
callq 0x93b0
leaq 0x90(%rsp), %rdi
callq 0x389de
jmp 0x15c6d
leaq 0x25ef3(%rip), %rsi     # 0x3bff0
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl $0x53, %edx
movl $0x3, %ecx
callq 0x387b6
leaq 0x26040(%rip), %rsi     # 0x3c15e
movl $0x3d, %edx
movq %rbx, %rdi
callq 0x93b0
leaq 0x90(%rsp), %rdi
callq 0x389de
jmp 0x15c83
leaq 0x25eac(%rip), %rsi     # 0x3bff0
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl $0x54, %edx
movl $0x3, %ecx
callq 0x387b6
leaq 0x26037(%rip), %rsi     # 0x3c19c
movl $0x33, %edx
movq %rbx, %rdi
callq 0x93b0
leaq 0x90(%rsp), %rdi
callq 0x389de
jmp 0x15c8f
leaq 0x25e65(%rip), %rsi     # 0x3bff0
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl $0x55, %edx
movl $0x3, %ecx
callq 0x387b6
leaq 0x26024(%rip), %rsi     # 0x3c1d0
movl $0x50, %edx
movq %rbx, %rdi
callq 0x93b0
leaq 0x90(%rsp), %rdi
callq 0x389de
jmp 0x15ca6
jmp 0x161d1
jmp 0x161d1
jmp 0x161d1
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x389de
jmp 0x16237
jmp 0x16207
jmp 0x161e7
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x389de
jmp 0x1621e
jmp 0x16207
jmp 0x1620e
jmp 0x16207
jmp 0x16207
jmp 0x1620e
jmp 0x16207
jmp 0x1620e
movq %rax, %rbx
jmp 0x1621e
jmp 0x1620e
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x19a36
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1622d
callq 0x9350
leaq 0x68(%rsp), %rdi
callq 0x19a36
movq %rbx, %rdi
callq 0x95d0
nop