// File: /workspace/github_cpp_makefile_star2_O1/btbujiangjun[P]abcdl/src/rnn/RNN.cpp
// Function: abcdl::rnn::RNN::total_loss(abcdl::algebra::MatrixSet<float> const&, abcdl::algebra::MatrixSet<float> const&)
real RNN::total_loss(const abcdl::algebra::MatSet& train_seq_data,
                     const abcdl::algebra::MatSet& train_seq_label){

	real loss_value = 0;
    abcdl::algebra::Mat state;
    abcdl::algebra::Mat activation;
	
    size_t num_train_data = train_seq_data.size();
	for(size_t j = 0; j != num_train_data; j++){
		_layer->farward(train_seq_data[j], _U, _W, _V, state, activation);

		auto mat_label = train_seq_label[j].argmax(abcdl::algebra::Axis_type::ROW);
        size_t rows = mat_label.rows();
        for(size_t row = 0; row != rows; row++){
            loss_value -= std::log(activation.get_data(row, mat_label.get_data(row, 0)));
        }
	}

	return loss_value;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rdx, 0x40(%rsp)
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x26b6c
leaq 0x48(%rsp), %rdi
callq 0x26b6c
movq 0x8(%r14), %rax
movq (%r14), %rcx
subq %rcx, %rax
je 0x242b4
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq 0x10(%rsp), %rax
leaq 0x70(%rax), %rcx
movq %rcx, 0x38(%rsp)
leaq 0xa8(%rax), %rcx
movq %rcx, 0x30(%rsp)
addq $0xe0, %rax
movq %rax, 0x28(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
xorl %ebx, %ebx
leaq 0xc0(%rsp), %r15
leaq 0x70(%rsp), %r12
movq %r14, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x118(%rax), %r13
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2465a
leaq 0x48(%rsp), %rax
movq %rax, (%rsp)
movq %r13, %rdi
movq %r15, %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %r8
leaq 0x98(%rsp), %r9
callq 0x22d70
movq %r15, %rdi
callq 0x26dc2
movq %r15, %rdi
movq 0x40(%rsp), %rsi
movq %rbx, %rdx
callq 0x2465a
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x37eb6
movq %r15, %rdi
movq %r12, %r15
callq 0x26dc2
movq 0x70(%rsp), %r13
testq %r13, %r13
je 0x2428c
xorl %r12d, %r12d
movq 0x78(%rsp), %rax
movq %rax, %r14
imulq %r12, %r14
imulq 0x70(%rsp), %rax
cmpq %rax, %r14
jae 0x24208
movq 0x80(%rsp), %rax
movq 0x50(%rsp), %rcx
movq %rcx, %rbp
imulq %r12, %rbp
addq (%rax,%r14,8), %rbp
imulq 0x48(%rsp), %rcx
cmpq %rcx, %rbp
jae 0x2424a
movq 0x58(%rsp), %rax
movss (%rax,%rbp,4), %xmm0
callq 0xa830
movss 0xc(%rsp), %xmm1
subss %xmm0, %xmm1
movss %xmm1, 0xc(%rsp)
incq %r12
cmpq %r12, %r13
jne 0x241a2
jmp 0x2428c
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
leaq 0x23955(%rip), %rsi     # 0x47b6f
movl $0x44, %edx
movl $0x3, %ecx
callq 0x45a82
movl $0x1f, %edx
movq %rbp, %rdi
leaq 0x23950(%rip), %rsi     # 0x47b88
callq 0xa4d0
movq %rbp, %rdi
callq 0x45caa
jmp 0x241b9
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
leaq 0x23913(%rip), %rsi     # 0x47b6f
movl $0x44, %edx
movl $0x3, %ecx
callq 0x45a82
movl $0x1f, %edx
movq %r14, %rdi
leaq 0x2390e(%rip), %rsi     # 0x47b88
callq 0xa4d0
movq %r14, %rdi
callq 0x45caa
jmp 0x241dc
movq %r15, %r12
movq %r15, %rdi
callq 0x2985e
incq %rbx
cmpq 0x18(%rsp), %rbx
movq 0x20(%rsp), %r14
leaq 0xc0(%rsp), %r15
jne 0x2411c
jmp 0x242bd
xorps %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x26dc2
leaq 0x98(%rsp), %rdi
callq 0x26dc2
movss 0xc(%rsp), %xmm0
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x242ee
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x45caa
jmp 0x24303
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2985e
jmp 0x2432d
movq %rax, %rbx
jmp 0x24337
jmp 0x24318
jmp 0x2431d
movq %rax, %rbx
jmp 0x2432d
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x26dc2
leaq 0x48(%rsp), %rdi
callq 0x26dc2
leaq 0x98(%rsp), %rdi
callq 0x26dc2
movq %rbx, %rdi
callq 0xa780