// File: xbai0624[P]dnn/src/Neuron.cpp
// Function: Neuron::UpdateA(int)
void Neuron::UpdateA(int sample_index)
{
    // update a for current training sample
    double v = __z[sample_index];
    //cout<<"debug: sample_id: "<<sample_index<<": z = "<<v<<endl;
    double a = -100.; // theorectially, a>=-1
    if(__funcType == ActuationFuncType::Sigmoid)
    {
        a = __sigmoid(v);
        //cout<<"sigmoid"<<endl;
    }
    else if(__funcType == ActuationFuncType::SoftMax)
    {
        auto & images  = __layer->GetImagesActiveZ();
        assert(images[sample_index].OutputImageFromKernel.size() == 1); // make sure it is 1D layer
        Matrix & m_z = images[sample_index].OutputImageFromKernel[0];

        a = __softmax(m_z);
    }
    else if(__funcType == ActuationFuncType::Tanh)
    {
        a = __tanh(v);
        //cout<<"tanh"<<endl;
    }
    else if(__funcType == ActuationFuncType::Relu)
    {
        a = __relu(v);
        //cout<<"relu"<<endl;
    }
    else
        std::cout<<"Error: unsupported actuation function type."<<std::endl;

    if(a < -1) 
    {
        std::cout<<"Error: Neuron::UpdateA(int sample_index), a<-1? something wrong."
            <<endl;
        exit(0);
    }
    //cout<<"debug: sample_id: "<<sample_index<<": a = "<<a<<endl;
    //getchar();
    //__a.push_back(a);
    __a[sample_index] = a;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movl %esi, 0x3c(%rsp)
movq 0x40(%rsp), %rdi
movq %rdi, 0x10(%rsp)
addq $0x48, %rdi
movslq 0x3c(%rsp), %rsi
callq 0x1fd60
movq %rax, %rcx
movq 0x10(%rsp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0xe1f1(%rip), %xmm0     # 0x55980
movsd %xmm0, 0x28(%rsp)
cmpl $0x0, 0x84(%rax)
jne 0x477b9
movq 0x10(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
callq 0x47d50
movsd %xmm0, 0x28(%rsp)
jmp 0x478cb
movq 0x10(%rsp), %rax
cmpl $0x1, 0x84(%rax)
jne 0x47857
movq 0x10(%rsp), %rax
movq 0x78(%rax), %rdi
movq (%rdi), %rax
callq *0xd8(%rax)
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movslq 0x3c(%rsp), %rsi
callq 0x1fd40
movq %rax, %rdi
callq 0x1f9c0
cmpq $0x1, %rax
jne 0x47801
jmp 0x47820
leaq 0xe3e7(%rip), %rdi      # 0x55bef
leaq 0xe1c7(%rip), %rsi      # 0x559d6
movl $0x167, %edx            # imm = 0x167
leaq 0xe40b(%rip), %rcx      # 0x55c26
callq 0x4170
movq 0x20(%rsp), %rdi
movslq 0x3c(%rsp), %rsi
callq 0x1fd40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq 0x10(%rsp), %rdi
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rsi
callq 0x47da0
movsd %xmm0, 0x28(%rsp)
jmp 0x478c9
movq 0x10(%rsp), %rax
cmpl $0x2, 0x84(%rax)
jne 0x4787d
movq 0x10(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
callq 0x47f10
movsd %xmm0, 0x28(%rsp)
jmp 0x478c7
movq 0x10(%rsp), %rax
cmpl $0x3, 0x84(%rax)
jne 0x478a3
movq 0x10(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
callq 0x47f60
movsd %xmm0, 0x28(%rsp)
jmp 0x478c5
movq 0x2372e(%rip), %rdi     # 0x6afd8
leaq 0xe38f(%rip), %rsi      # 0x55c40
callq 0x4230
movq %rax, %rdi
movq 0x236f0(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x478c7
jmp 0x478c9
jmp 0x478cb
movsd 0xa755(%rip), %xmm0     # 0x52028
ucomisd 0x28(%rsp), %xmm0
jbe 0x47904
movq 0x236f6(%rip), %rdi     # 0x6afd8
leaq 0xe383(%rip), %rsi      # 0x55c6c
callq 0x4230
movq %rax, %rdi
movq 0x236b8(%rip), %rsi     # 0x6afb0
callq 0x4260
xorl %edi, %edi
callq 0x4290
movq 0x10(%rsp), %rdi
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
addq $0x18, %rdi
movslq 0x3c(%rsp), %rsi
callq 0x1fd60
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)