// File: /workspace/github_cpp_makefile_star2_O2/xbai0624[P]dnn/src/UnitTest.cpp
// Function: UnitTest::TestCNNWeightAndBiasEvolution()
void UnitTest::TestCNNWeightAndBiasEvolution()
{
    cout<<"ooooooooo000000000oooooooooo000000000ooooooooooo00000000oooooooooo0000000000000ooooooooooooo"<<endl;
    DataInterface *data_interface = new DataInterface("simulation_data/data_signal_train.dat", "simulation_data/data_cosmic_train.dat", LayerDimension::_2D, std::pair<int, int>(10, 10), 200);

    TrainingType resume_or_new_training = TrainingType::NewTraining;
    double learning_rate = 0.06;
    double regularization_factor = 0.01;

    // 3) input layer   ID=0
    LayerParameterList p_list0(LayerType::input, LayerDimension::_2D, data_interface, 0, 0, 
            std::pair<size_t, size_t>(0, 0), learning_rate, false, 0, 0, Regularization::Undefined, 0, ActuationFuncType::Undefined, resume_or_new_training, false);
    Layer* layer_input = new ConstructLayer(p_list0);
    layer_input->Init();

    // 4) middle layer 3 : cnn layer ID=1
    LayerParameterList p_list1(LayerType::cnn, LayerDimension::_2D, data_interface, 0, 1, 
            std::pair<size_t, size_t>(4, 4), learning_rate, false, 0, 0.5, Regularization::L2, regularization_factor, ActuationFuncType::Relu, resume_or_new_training, false);
    Layer *l1 = new ConstructLayer(p_list1);
    l1->SetPrevLayer(layer_input);
    l1->Init();

    // 4) middle layer 3 : cnn layer ID=3
    LayerParameterList p_list3(LayerType::cnn, LayerDimension::_2D, data_interface, 0, 1, 
            std::pair<size_t, size_t>(4, 4), learning_rate, false, 0, 0.5, Regularization::L2, regularization_factor, ActuationFuncType::Relu, resume_or_new_training, false);
    Layer *l3 = new ConstructLayer(p_list3);
    l3->SetPrevLayer(l1);
    l3->Init();

    // 5) output layer ID = 6
    LayerParameterList p_list6(LayerType::output, LayerDimension::_1D, data_interface, 2, 0, 
            std::pair<size_t, size_t>(0, 0), learning_rate, false, 0, 0., Regularization::L2, regularization_factor, ActuationFuncType::SoftMax, resume_or_new_training, false);
    Layer* layer_output = new ConstructLayer(p_list6);
    layer_output -> SetPrevLayer(l3);
    layer_output -> Init();

    l1->SetNextLayer(l3);
    l3->SetNextLayer(layer_output); // This line is ugly, to be improved

    cout<<"ooooooooo000000000oooooooooo000000000ooooooooooo00000000oooooooooo0000000000000ooooooooooooo"<<endl;
    int numEpoch = 50;
    for(int e=0;e<numEpoch;e++)
    {
        cout<<"...............Epoch: "<<e<<endl;
        data_interface -> Reset();
        data_interface -> Shuffle();

        int nBatch = 1;
        for(int i = 0; i< nBatch;i++)
        {
            l1 -> BatchInit();
            l3 -> BatchInit();
            layer_output -> BatchInit();

            data_interface -> GetNewBatchData();
            data_interface -> GetNewBatchLabel();

            layer_input -> FillBatchDataToInputLayerA();

            int nSample = data_interface -> GetBatchSize();

            // forward propagation
            for(int sample_index = 0; sample_index < nSample;sample_index++)
            {
                l1 -> ForwardPropagate_Z_ForSample(sample_index);
                l1 -> ForwardPropagate_SigmaPrimeAndA_ForSample(sample_index);

                l3 -> ForwardPropagate_Z_ForSample(sample_index);
                l3 -> ForwardPropagate_SigmaPrimeAndA_ForSample(sample_index);

                layer_output -> ForwardPropagate_Z_ForSample(sample_index);
                layer_output -> ForwardPropagate_SigmaPrimeAndA_ForSample(sample_index);
            }

            // backward propagation
            for(int sample_index = 0; sample_index < nSample;sample_index++)
            {
                layer_output -> BackwardPropagateForSample(sample_index);
                l3 -> BackwardPropagateForSample(sample_index);
                l1 -> BackwardPropagateForSample(sample_index);
            }

            // update weights and bias
            l1->UpdateWeightsAndBias();
            l3->UpdateWeightsAndBias();
            layer_output->UpdateWeightsAndBias();
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq 0x12afc(%rip), %rdi     # 0x32fd8
leaq 0x5241(%rip), %rsi      # 0x25724
callq 0x4240
movq %rax, %rdi
callq 0x4130
movl $0xc8, %edi
callq 0x4250
movq %rax, %rbx
leaq 0x4497(%rip), %rsi      # 0x2499b
leaq 0x44b6(%rip), %rdx      # 0x249c1
pushq $0x1
popq %rcx
movabsq $0xa0000000a, %r8       # imm = 0xA0000000A
movq %rax, %rdi
movl $0xc8, %r9d
callq 0x16a22
movl $0x490, %edi            # imm = 0x490
callq 0x4250
movabsq $0x100000003, %rcx      # imm = 0x100000003
leaq 0x1b0(%rsp), %rsi
movq %rcx, (%rsi)
movq %rbx, 0x8(%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsi)
movups %xmm0, 0x20(%rsi)
movabsq $0x3faeb851eb851eb8, %r13 # imm = 0x3FAEB851EB851EB8
movq %r13, 0x30(%rsi)
xorl %ecx, %ecx
movb %cl, 0x38(%rsi)
andl $0x0, 0x3c(%rsi)
andq $0x0, 0x40(%rsi)
movl $0x2, 0x48(%rsi)
andq $0x0, 0x50(%rsi)
movq %rax, %r15
movq $0x4, 0x58(%rsi)
movb %cl, 0x60(%rsi)
pushq $0xd
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x4762
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
movl $0x490, %edi            # imm = 0x490
callq 0x4250
movabsq $0x100000001, %rbp      # imm = 0x100000001
leaq 0x148(%rsp), %rsi
movq %rbp, (%rsi)
movq %rbx, 0x8(%rsi)
andq $0x0, 0x10(%rsi)
movq %r15, %r14
movq %rax, %r15
movq $0x1, 0x18(%rsi)
pushq $0x4
popq %r12
movq %r12, 0x20(%rsi)
movq %r12, 0x28(%rsi)
movq %r13, 0x30(%rsi)
xorl %eax, %eax
movb %al, 0x38(%rsi)
andl $0x0, 0x3c(%rsi)
movabsq $0x3fe0000000000000, %r13 # imm = 0x3FE0000000000000
movq %r13, 0x40(%rsi)
andl $0x0, 0x48(%rsi)
movabsq $0x3f847ae147ae147b, %rcx # imm = 0x3F847AE147AE147B
movq %rcx, 0x50(%rsi)
movq $0x3, 0x58(%rsi)
movb %al, 0x60(%rsi)
pushq $0xd
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
callq 0x4762
movq (%r15), %rax
movq %r15, %rdi
movq %r14, 0x70(%rsp)
movq %r14, %rsi
callq *0x1e8(%rax)
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
movl $0x490, %edi            # imm = 0x490
callq 0x4250
leaq 0xe0(%rsp), %rsi
movq %rbp, (%rsi)
movq %rbx, 0x8(%rsi)
andq $0x0, 0x10(%rsi)
movq $0x1, 0x18(%rsi)
movq %r12, 0x20(%rsi)
movq %r12, 0x28(%rsi)
movabsq $0x3faeb851eb851eb8, %rcx # imm = 0x3FAEB851EB851EB8
movq %rcx, 0x30(%rsi)
xorl %ecx, %ecx
movb %cl, 0x38(%rsi)
andl $0x0, 0x3c(%rsi)
movq %r13, 0x40(%rsi)
andl $0x0, 0x48(%rsi)
movq %rax, %r12
movabsq $0x3f847ae147ae147b, %r14 # imm = 0x3F847AE147AE147B
movq %r14, 0x50(%rsi)
movq $0x3, 0x58(%rsi)
movb %cl, 0x60(%rsi)
pushq $0xd
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x4762
movq (%r12), %rax
movq %r12, %rdi
movq %r15, %rsi
callq *0x1e8(%rax)
movq (%r12), %rax
movq %r12, %rdi
callq *0x10(%rax)
movl $0x490, %edi            # imm = 0x490
callq 0x4250
movq %rax, %r13
leaq 0x78(%rsp), %rsi
movq $0x4, (%rsi)
movq %rbx, 0x8(%rsi)
movq $0x2, 0x10(%rsi)
xorps %xmm0, %xmm0
andq $0x0, 0x28(%rsi)
movups %xmm0, 0x18(%rsi)
movabsq $0x3faeb851eb851eb8, %rax # imm = 0x3FAEB851EB851EB8
movq %rax, 0x30(%rsi)
xorl %ebp, %ebp
movb %bpl, 0x38(%rsi)
movups %xmm0, 0x3c(%rsi)
movq %r14, 0x50(%rsi)
movq $0x1, 0x58(%rsi)
movb %bpl, 0x60(%rsi)
pushq $0xd
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r13, %rdi
callq 0x4762
movq (%r13), %rax
movq %r13, %rdi
movq %r12, %rsi
callq *0x1e8(%rax)
movq (%r13), %rax
movq %r13, %rdi
callq *0x10(%rax)
movq (%r15), %rax
movq %r15, %rdi
movq %r12, %rsi
callq *0x1f0(%rax)
movq (%r12), %rax
movq %r12, %rdi
movq %r13, %rsi
callq *0x1f0(%rax)
movq 0x1284e(%rip), %rdi     # 0x32fd8
leaq 0x4f93(%rip), %rsi      # 0x25724
callq 0x4240
movq %rax, %rdi
callq 0x4130
movq %rbx, 0x68(%rsp)
cmpl $0x32, %ebp
je 0x208e2
movq 0x12825(%rip), %rdi     # 0x32fd8
leaq 0x4fc7(%rip), %rsi      # 0x25781
callq 0x4240
movq %rax, %rdi
movl %ebp, %esi
callq 0x43a0
movq %rax, %rdi
callq 0x4130
movq %rbx, %rdi
callq 0x17004
movq %rbx, %rdi
callq 0x1700a
movq (%r15), %rax
movq %r15, %rdi
callq *0x88(%rax)
movq (%r12), %rax
movq %r12, %rdi
callq *0x88(%rax)
movq (%r13), %rax
movq %r13, %rdi
callq *0x88(%rax)
movq %rbx, %rdi
callq 0x16b9a
movq %rbx, %rdi
callq 0x16e5e
movq 0x70(%rsp), %rdi
movq (%rdi), %rax
callq *0x180(%rax)
movl (%rbx), %ebx
xorl %r14d, %r14d
testl %ebx, %ebx
cmovlel %r14d, %ebx
cmpl %r14d, %ebx
je 0x20886
movq (%r15), %rax
movq %r15, %rdi
movl %r14d, %esi
callq *0x28(%rax)
movq (%r15), %rax
movq %r15, %rdi
movl %r14d, %esi
callq *0x30(%rax)
movq (%r12), %rax
movq %r12, %rdi
movl %r14d, %esi
callq *0x28(%rax)
movq (%r12), %rax
movq %r12, %rdi
movl %r14d, %esi
callq *0x30(%rax)
movq (%r13), %rax
movq %r13, %rdi
movl %r14d, %esi
callq *0x28(%rax)
movq (%r13), %rax
movq %r13, %rdi
movl %r14d, %esi
callq *0x30(%rax)
incl %r14d
jmp 0x20830
xorl %r14d, %r14d
cmpl %r14d, %ebx
je 0x208b9
movq (%r13), %rax
movq %r13, %rdi
movl %r14d, %esi
callq *0x38(%rax)
movq (%r12), %rax
movq %r12, %rdi
movl %r14d, %esi
callq *0x38(%rax)
movq (%r15), %rax
movq %r15, %rdi
movl %r14d, %esi
callq *0x38(%rax)
incl %r14d
jmp 0x20889
movq (%r15), %rax
movq %r15, %rdi
callq *0x50(%rax)
movq (%r12), %rax
movq %r12, %rdi
callq *0x50(%rax)
movq (%r13), %rax
movq %r13, %rdi
callq *0x50(%rax)
incl %ebp
movq 0x68(%rsp), %rbx
jmp 0x207a3
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq %r13, %rdi
jmp 0x20914
movq %rax, %r14
movq %r12, %rdi
jmp 0x20914
jmp 0x20906
movq %rax, %r14
movq %r15, %rdi
jmp 0x20914
movq %rbx, %rdi
movq %rax, %r14
callq 0x4220
movq %r14, %rdi
callq 0x43b0
nop