// File: /workspace/github_cpp_makefile_star2_O3/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 0x267d8
leaq 0x48(%rsp), %rdi
callq 0x267d8
movq 0x8(%r14), %rax
movq (%r14), %rcx
subq %rcx, %rax
je 0x23f1c
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 0x242d4
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 0x229f0
movq %r15, %rdi
callq 0x26a2e
movq %r15, %rdi
movq 0x40(%rsp), %rsi
movq %rbx, %rdx
callq 0x242d4
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x37c20
movq %r15, %rdi
movq %r12, %r15
callq 0x26a2e
movq 0x70(%rsp), %r13
testq %r13, %r13
je 0x23ef4
xorl %r12d, %r12d
movq 0x78(%rsp), %rax
movq %rax, %r14
imulq %r12, %r14
imulq 0x70(%rsp), %rax
cmpq %rax, %r14
jae 0x23e70
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 0x23eb2
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 0x23e0a
jmp 0x23ef4
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
leaq 0x23ced(%rip), %rsi     # 0x47b6f
movl $0x44, %edx
movl $0x3, %ecx
callq 0x457ae
movl $0x1f, %edx
movq %rbp, %rdi
leaq 0x23ce8(%rip), %rsi     # 0x47b88
callq 0xa4d0
movq %rbp, %rdi
callq 0x459d6
jmp 0x23e21
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
leaq 0x23cab(%rip), %rsi     # 0x47b6f
movl $0x44, %edx
movl $0x3, %ecx
callq 0x457ae
movl $0x1f, %edx
movq %r14, %rdi
leaq 0x23ca6(%rip), %rsi     # 0x47b88
callq 0xa4d0
movq %r14, %rdi
callq 0x459d6
jmp 0x23e44
movq %r15, %r12
movq %r15, %rdi
callq 0x294c8
incq %rbx
cmpq 0x18(%rsp), %rbx
movq 0x20(%rsp), %r14
leaq 0xc0(%rsp), %r15
jne 0x23d84
jmp 0x23f25
xorps %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x26a2e
leaq 0x98(%rsp), %rdi
callq 0x26a2e
movss 0xc(%rsp), %xmm0
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x23f56
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x459d6
jmp 0x23f6b
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x294c8
jmp 0x23f95
movq %rax, %rbx
jmp 0x23f9f
jmp 0x23f80
jmp 0x23f85
movq %rax, %rbx
jmp 0x23f95
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x26a2e
leaq 0x48(%rsp), %rdi
callq 0x26a2e
leaq 0x98(%rsp), %rdi
callq 0x26a2e
movq %rbx, %rdi
callq 0xa780