// File: /workspace/github_cpp_makefile_star2_O1/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 0x16373
movq 0x8(%r15), %rax
movq 0x30(%r12), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx), %rax
jne 0x163ba
movq (%r15), %rax
cmpq (%r14), %rax
jne 0x16401
movq 0x8(%r14), %rax
movq 0x38(%r12), %rcx
movq -0x8(%rcx), %rcx
cmpq 0x10(%rcx), %rax
jne 0x16448
callq 0x9070
movq %rax, 0x48(%rsp)
movq (%r15), %r13
leaq 0x68(%rsp), %rdi
callq 0x19a38
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %r13, %r13
je 0x1614f
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 0x1a044
movq 0x40(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x16504
movq %r14, %rdi
callq 0x19c8e
movq %r12, %r15
movq %r12, %rdi
callq 0x2acd4
movq %rax, %r12
movl $0x1, %ecx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x1a044
movq %rbp, 0x60(%rsp)
movq %r14, %rdi
callq 0x2acd4
xorl %r13d, %r13d
cmpq %rax, %r12
sete %bpl
movq %r14, %rdi
callq 0x19c8e
movl $0x1, %ecx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x1a044
movq %r14, %rdi
callq 0x2acd4
movq %rax, %r12
movq %r15, %rdi
callq 0x2acd4
testq %r12, %r12
js 0x16069
cvtsi2ss %r12, %xmm0
jmp 0x1607f
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 0x16094
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x160ac
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 0x160ce
movq 0x18(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x28(%rsp)
jmp 0x160dd
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x17ec6
movq %r14, %rdi
callq 0x19c8e
movq 0x40(%rsp), %rax
movq 0x48(%rax), %r12
movl $0x1, %ecx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x1a044
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 0x19c8e
incq %rbx
movq 0x58(%rsp), %r13
cmpq %rbx, %r13
movq 0x50(%rsp), %r15
jne 0x15fc8
jmp 0x16159
xorps %xmm0, %xmm0
movss %xmm0, (%rsp)
xorl %ebp, %ebp
testq %r13, %r13
js 0x16168
xorps %xmm1, %xmm1
cvtsi2ss %r13, %xmm1
jmp 0x16183
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 0x15d7c
movsd %xmm0, 0x8(%rsp)
leaq 0x25e3f(%rip), %rsi     # 0x3bff0
leaq 0x90(%rsp), %rdi
movl $0x6c, %edx
xorl %ecx, %ecx
callq 0x3894e
leaq 0x26055(%rip), %rsi     # 0x3c221
leaq 0x90(%rsp), %rdi
movl $0xd, %edx
callq 0x93b0
leaq 0x90(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
callq 0x9540
leaq 0x25ef2(%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 0x26005(%rip), %rsi     # 0x3c22f
leaq 0x90(%rsp), %rdi
movl $0x3, %edx
callq 0x93b0
leaq 0x90(%rsp), %rdi
movq %rbp, %rsi
callq 0x9200
leaq 0x23fb5(%rip), %rsi     # 0x3a208
leaq 0x90(%rsp), %rdi
movl $0x1, %edx
callq 0x93b0
leaq 0x90(%rsp), %rdi
movq %r13, %rsi
callq 0x9200
leaq 0x25fb7(%rip), %rsi     # 0x3c233
leaq 0x90(%rsp), %rdi
movl $0x7, %edx
callq 0x93b0
testq %rbp, %rbp
js 0x1629d
xorps %xmm0, %xmm0
cvtsi2ss %rbp, %xmm0
jmp 0x162b7
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 0x26172(%rip), %rsi     # 0x3c44b
leaq 0x90(%rsp), %rdi
movl $0x1, %edx
callq 0x93b0
leaq 0x90(%rsp), %rdi
callq 0x38b76
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 0x25f0e(%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 0x16354
callq 0x9350
leaq 0x68(%rsp), %rdi
callq 0x19c8e
movq %rbp, %rax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25c76(%rip), %rsi     # 0x3bff0
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl $0x52, %edx
movl $0x3, %ecx
callq 0x3894e
leaq 0x25da0(%rip), %rsi     # 0x3c13b
movl $0x22, %edx
movq %rbx, %rdi
callq 0x93b0
leaq 0x90(%rsp), %rdi
callq 0x38b76
jmp 0x15f31
leaq 0x25c2f(%rip), %rsi     # 0x3bff0
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl $0x53, %edx
movl $0x3, %ecx
callq 0x3894e
leaq 0x25d7c(%rip), %rsi     # 0x3c15e
movl $0x3d, %edx
movq %rbx, %rdi
callq 0x93b0
leaq 0x90(%rsp), %rdi
callq 0x38b76
jmp 0x15f47
leaq 0x25be8(%rip), %rsi     # 0x3bff0
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl $0x54, %edx
movl $0x3, %ecx
callq 0x3894e
leaq 0x25d73(%rip), %rsi     # 0x3c19c
movl $0x33, %edx
movq %rbx, %rdi
callq 0x93b0
leaq 0x90(%rsp), %rdi
callq 0x38b76
jmp 0x15f53
leaq 0x25ba1(%rip), %rsi     # 0x3bff0
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl $0x55, %edx
movl $0x3, %ecx
callq 0x3894e
leaq 0x25d60(%rip), %rsi     # 0x3c1d0
movl $0x50, %edx
movq %rbx, %rdi
callq 0x93b0
leaq 0x90(%rsp), %rdi
callq 0x38b76
jmp 0x15f6a
jmp 0x16495
jmp 0x16495
jmp 0x16495
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x38b76
jmp 0x164fb
jmp 0x164cb
jmp 0x164ab
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x38b76
jmp 0x164e2
jmp 0x164cb
jmp 0x164d2
jmp 0x164cb
jmp 0x164cb
jmp 0x164d2
jmp 0x164cb
jmp 0x164d2
movq %rax, %rbx
jmp 0x164e2
jmp 0x164d2
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x19c8e
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x164f1
callq 0x9350
leaq 0x68(%rsp), %rdi
callq 0x19c8e
movq %rbx, %rdi
callq 0x95d0
nop