// File: /workspace/github_cpp_makefile_star2_O2/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 $0x208, %rsp            # imm = 0x208
movq %rcx, 0x18(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
cmpq $0x0, (%rsi)
movq %rdx, 0x8(%rsp)
je 0x14c36
movq 0x8(%r14), %rax
movq 0x30(%r15), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx), %rax
jne 0x14c79
movq (%r14), %rax
cmpq (%rbx), %rax
jne 0x14cbc
movq 0x8(%rbx), %rax
movq 0x38(%r15), %rcx
movq -0x8(%rcx), %rcx
cmpq 0x10(%rcx), %rax
jne 0x14cff
movq %r15, 0x10(%rsp)
callq 0x9060
movq %rax, 0x28(%rsp)
movq %r14, 0x38(%rsp)
movq (%r14), %r12
leaq 0x58(%rsp), %rdi
callq 0x17dac
leaq 0x40(%rsp), %rax
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
xorps %xmm0, %xmm0
movss %xmm0, 0x4(%rsp)
xorl %ebp, %ebp
leaq 0x80(%rsp), %r15
xorl %r14d, %r14d
movq %r12, 0x30(%rsp)
cmpq %r14, %r12
je 0x14a81
movq %r15, %rdi
movq 0x38(%rsp), %rsi
movq %r14, %rdx
pushq $0x1
popq %rcx
callq 0x18278
movq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %r12
movq %r12, %rsi
movq %r15, %rdx
callq 0x14db4
movq %r15, %rdi
callq 0x17fd6
movq %r12, %rdi
callq 0x23ee8
movq %rax, %r12
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
pushq $0x1
popq %rcx
callq 0x18278
movq %r15, %rdi
callq 0x23ee8
xorl %r13d, %r13d
cmpq %rax, %r12
sete %bl
movq %r15, %rdi
callq 0x17fd6
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
pushq $0x1
popq %rcx
callq 0x18278
movq %r15, %rdi
callq 0x23ee8
movq %rax, %r12
leaq 0x58(%rsp), %rdi
callq 0x23ee8
testq %r12, %r12
js 0x149c9
cvtsi2ss %r12, %xmm0
jmp 0x149df
movq %r12, %rcx
shrq %rcx
andl $0x1, %r12d
orq %rcx, %r12
cvtsi2ss %r12, %xmm0
addss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
testq %rax, %rax
js 0x149f1
cvtsi2ss %rax, %xmm0
jmp 0x14a06
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x16328
movq %r15, %rdi
callq 0x17fd6
movq 0x10(%rsp), %rax
movq 0x48(%rax), %r12
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
pushq $0x1
popq %rcx
callq 0x18278
movq (%r12), %rax
movq %r12, %rdi
movq %r15, %rsi
leaq 0x58(%rsp), %rdx
callq *0x10(%rax)
movb %bl, %r13b
addq %r13, %rbp
movss 0x4(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x4(%rsp)
movq %r15, %rdi
callq 0x17fd6
incq %r14
movq 0x30(%rsp), %r12
movq 0x8(%rsp), %rbx
jmp 0x14927
testq %r12, %r12
js 0x14a8d
cvtsi2ss %r12, %xmm1
jmp 0x14aa5
movq %r12, %rax
shrq %rax
movl %r12d, %ecx
andl $0x1, %ecx
orq %rax, %rcx
cvtsi2ss %rcx, %xmm1
addss %xmm1, %xmm1
movss 0x4(%rsp), %xmm0
movss %xmm1, 0x10(%rsp)
divss %xmm1, %xmm0
movq 0x18(%rsp), %rax
movss %xmm0, (%rax)
leaq 0x40(%rsp), %rsi
callq 0x1473a
movsd %xmm0, 0x8(%rsp)
leaq 0x1d4fb(%rip), %rsi     # 0x31fd0
leaq 0x80(%rsp), %rdi
pushq $0x6c
popq %rdx
xorl %ecx, %ecx
callq 0x2ee18
leaq 0x1d713(%rip), %rsi     # 0x32201
leaq 0x80(%rsp), %rdi
callq 0x9370
leaq 0x80(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
callq 0x9550
leaq 0x1d5b5(%rip), %rsi     # 0x320ca
leaq 0x80(%rsp), %rdi
callq 0x9370
leaq 0x80(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x15884
movq %rax, %rbx
leaq 0x1d6d1(%rip), %rsi     # 0x3220f
movq %rax, %rdi
callq 0x9370
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x9210
leaq 0x1b6b0(%rip), %rsi     # 0x30208
movq %rbx, %rdi
callq 0x9370
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9210
leaq 0x1d6a1(%rip), %rsi     # 0x32213
movq %rbx, %rdi
callq 0x9370
testq %rbp, %rbp
js 0x14b86
cvtsi2ss %rbp, %xmm0
jmp 0x14b9d
movq %rbp, %rax
shrq %rax
movl %ebp, %ecx
andl $0x1, %ecx
orq %rax, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
divss 0x10(%rsp), %xmm0
movq %rbx, %rdi
movss %xmm0, 0x4(%rsp)
callq 0x9270
leaq 0x1d873(%rip), %rsi     # 0x3242b
movq %rbx, %rdi
callq 0x9370
leaq 0x80(%rsp), %rdi
callq 0x2f054
callq 0x9060
subq 0x28(%rsp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
cvtss2sd 0x4(%rsp), %xmm2
movq 0x18(%rsp), %rcx
cvtss2sd (%rcx), %xmm1
leaq 0x1d624(%rip), %rdi     # 0x3221b
movsd 0x8(%rsp), %xmm0
movq %rbp, %rsi
movq %r12, %rdx
movq %rax, %rcx
movb $0x3, %al
callq 0x9050
leaq 0x40(%rsp), %rdi
callq 0x1631a
leaq 0x58(%rsp), %rdi
callq 0x17fd6
movq %rbp, %rax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d393(%rip), %rsi     # 0x31fd0
leaq 0x80(%rsp), %rbx
pushq $0x52
popq %rdx
pushq $0x3
popq %rcx
movq %rbx, %rdi
callq 0x2ee18
leaq 0x1d4c1(%rip), %rsi     # 0x3211b
movq %rbx, %rdi
callq 0x9370
leaq 0x80(%rsp), %rdi
callq 0x2f054
movq 0x8(%rsp), %rbx
jmp 0x148a4
leaq 0x1d350(%rip), %rsi     # 0x31fd0
leaq 0x80(%rsp), %rbx
pushq $0x53
popq %rdx
pushq $0x3
popq %rcx
movq %rbx, %rdi
callq 0x2ee18
leaq 0x1d4a1(%rip), %rsi     # 0x3213e
movq %rbx, %rdi
callq 0x9370
leaq 0x80(%rsp), %rdi
callq 0x2f054
movq 0x8(%rsp), %rbx
jmp 0x148b9
leaq 0x1d30d(%rip), %rsi     # 0x31fd0
leaq 0x80(%rsp), %rbx
pushq $0x54
popq %rdx
pushq $0x3
popq %rcx
movq %rbx, %rdi
callq 0x2ee18
leaq 0x1d49c(%rip), %rsi     # 0x3217c
movq %rbx, %rdi
callq 0x9370
leaq 0x80(%rsp), %rdi
callq 0x2f054
movq 0x8(%rsp), %rbx
jmp 0x148c5
leaq 0x1d2ca(%rip), %rsi     # 0x31fd0
leaq 0x80(%rsp), %rbx
pushq $0x55
popq %rdx
pushq $0x3
popq %rcx
movq %rbx, %rdi
callq 0x2ee18
leaq 0x1d48d(%rip), %rsi     # 0x321b0
movq %rbx, %rdi
callq 0x9370
leaq 0x80(%rsp), %rdi
callq 0x2f054
movq 0x8(%rsp), %rbx
jmp 0x148db
jmp 0x14d48
jmp 0x14d48
jmp 0x14d48
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x2f054
jmp 0x14dab
jmp 0x14d80
jmp 0x14d80
jmp 0x14d60
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x2f054
jmp 0x14d97
jmp 0x14d80
jmp 0x14d80
jmp 0x14d87
jmp 0x14d87
jmp 0x14d80
jmp 0x14d80
jmp 0x14d87
movq %rax, %rbx
jmp 0x14d97
jmp 0x14d87
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x17fd6
leaq 0x40(%rsp), %rdi
callq 0x1631a
leaq 0x58(%rsp), %rdi
callq 0x17fd6
movq %rbx, %rdi
callq 0x95e0
nop