// File: /workspace/github_c_makefile_star2_O0/stonezwr[P]SpiKL-IP/network.C
// Function: Network::LSMPushResults(std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>> const&, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>> const&, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>> const&, int)
void Network::LSMPushResults(const vector<pair<int, int> >& correct, const vector<pair<int, int> >& wrong, const vector<pair<int, int> >& even, int iter_n){
    assert(iter_n < _readout_correct.size());
    _readout_correct[iter_n] += correct.size();
    _readout_wrong[iter_n] += wrong.size();
    _readout_even[iter_n] += even.size();

    for(auto & p : correct){
        assert(p.second < _readout_correct_breakdown[iter_n].size());
        _readout_correct_breakdown[iter_n][p.second]++;
    }
}

//* log the test error into the corresponding vector:
//* test error defined: \sum_j 1/2*(o_j - y_j)^2, where o_j = spike_j /max_k(spike_k)
void Network::LogTestError(const vector<double>& each_sample_errors, int iter_n){
    assert(iter_n < _readout_test_error.size());
    double error_sum = 0;
    for(double e : each_sample_errors)  error_sum += e;
    _readout_test_error[iter_n] = error_sum;
}

//* merge the readout results from the network
void Network::MergeReadoutResults(vector<int>& r_correct, vector<int>& r_wrong, vector<int>& r_even, vector<vector<int> >& r_correct_bd){
    assert(!r_correct.empty() &&
            r_correct.size() == _readout_correct.size() &&
            r_wrong.size() == _readout_wrong.size() &&
            r_even.size() == _readout_even.size() &&
            _readout_correct.size() == _readout_wrong.size() &&
            _readout_correct.size() == _readout_correct_breakdown.size());

    for(size_t i = 0; i < r_correct.size(); ++i){
        r_correct[i] += _readout_correct[i];
        r_wrong[i] += _readout_wrong[i];
        r_even[i] += _readout_even[i];
        r_correct_bd[i] = r_correct_bd[i] + _readout_correct_breakdown[i];  
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x58(%rbp)
movslq -0x24(%rbp), %rax
movq %rax, -0x50(%rbp)
addq $0x190, %rdi            # imm = 0x190
callq 0x5600
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jae 0x20ab9
jmp 0x20ad8
leaq 0x15195(%rip), %rdi     # 0x35c55
leaq 0x14853(%rip), %rsi     # 0x3531a
movl $0x34a, %edx            # imm = 0x34A
leaq 0x151a3(%rip), %rcx     # 0x35c76
callq 0x4210
movq -0x10(%rbp), %rdi
callq 0x13890
movq -0x58(%rbp), %rdi
movq %rax, -0x70(%rbp)
addq $0x190, %rdi            # imm = 0x190
movslq -0x24(%rbp), %rsi
callq 0x5620
movq -0x70(%rbp), %rdx
movslq (%rax), %rcx
addq %rdx, %rcx
movl %ecx, (%rax)
movq -0x18(%rbp), %rdi
callq 0x13890
movq -0x58(%rbp), %rdi
movq %rax, -0x68(%rbp)
addq $0x1a8, %rdi            # imm = 0x1A8
movslq -0x24(%rbp), %rsi
callq 0x5620
movq -0x68(%rbp), %rdx
movslq (%rax), %rcx
addq %rdx, %rcx
movl %ecx, (%rax)
movq -0x20(%rbp), %rdi
callq 0x13890
movq -0x58(%rbp), %rdi
movq %rax, -0x60(%rbp)
addq $0x1c0, %rdi            # imm = 0x1C0
movslq -0x24(%rbp), %rsi
callq 0x5620
movq -0x60(%rbp), %rdx
movslq (%rax), %rcx
addq %rdx, %rcx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x24660
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x24690
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x246c0
testb $0x1, %al
jne 0x20b97
jmp 0x20c32
leaq -0x38(%rbp), %rdi
callq 0x24700
movq -0x58(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movslq 0x4(%rax), %rax
movq %rax, -0x78(%rbp)
addq $0x1d8, %rdi            # imm = 0x1D8
movslq -0x24(%rbp), %rsi
callq 0x24720
movq %rax, %rdi
callq 0x5600
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x20bda
jmp 0x20bf9
leaq 0x15117(%rip), %rdi     # 0x35cf8
leaq 0x14732(%rip), %rsi     # 0x3531a
movl $0x350, %edx            # imm = 0x350
leaq 0x15082(%rip), %rcx     # 0x35c76
callq 0x4210
movq -0x58(%rbp), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movslq -0x24(%rbp), %rsi
callq 0x24720
movq %rax, %rdi
movq -0x48(%rbp), %rax
movslq 0x4(%rax), %rsi
callq 0x5620
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
leaq -0x38(%rbp), %rdi
callq 0x24740
jmp 0x20b81
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)