// File: /workspace/github_cpp_makefile_star2_O2/xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::SaveTrainedWeightsAndBias()
void ConstructLayer::SaveTrainedWeightsAndBias()
{
    int layer_id = GetID();
    LayerType layer_type = GetType();
    LayerDimension layer_dimension = GetLayerDimension();

    // parse file name
    std::ostringstream oss;
    oss<<"weights_and_bias_trained/LayerID=";
    oss<<layer_id;
    oss<<layer_type;
    oss<<layer_dimension;
    oss<<"_weights_and_bias.txt";

    // save weights and bias
    std::fstream ff(oss.str(), std::ios::out);
    std::cout<<__func__<<"(): Saving trained weights and bias from layer: "<<layer_id<<" to files."<<std::endl;
    if(!ff.is_open())
    {
        std::cout<<__func__<<" Error: cannot open file: "<<oss.str()<<" to save weights and bias."
            <<std::endl;
        std::cout<<"           please make sure you have 'weights_and_bias_trained' folder exsit."
            <<std::endl;
        exit(0);
    }
    for(size_t i=0;i<__weightMatrix.size();i++)
    {
        ff<<"weight "<<i<<":"<<std::endl;
        //cout<<"weight "<<i<<":"<<std::endl;
        ff<<__weightMatrix[i]<<std::endl;
        //cout<<__weightMatrix[i]<<endl;
        ff<<"bias "<<i<<":"<<std::endl;
        //cout<<"bias: "<<i<<":"<<std::endl;
        ff<<__biasVector[i]<<std::endl;
        //cout<<__biasVector[i]<<endl;
    }
    ff.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3b8, %rsp            # imm = 0x3B8
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x298(%rax)
movl %eax, %ebp
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x250(%rax)
movl %eax, 0xc(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x258(%rax)
movl %eax, 0x8(%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x4290
leaq 0x13768(%rip), %rsi     # 0x23081
movq %r14, %rdi
callq 0x4240
leaq 0x30(%rsp), %rdi
movl %ebp, %esi
callq 0x43a0
leaq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x172e0
leaq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x17337
leaq 0x13751(%rip), %rsi     # 0x230a3
leaq 0x30(%rsp), %rdi
callq 0x4240
leaq 0x38(%rsp), %r14
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x4310
leaq 0x1a8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x4360
leaq 0x10(%rsp), %rdi
callq 0x4100
movq 0x23644(%rip), %rdi     # 0x32fd8
leaq 0x1371e(%rip), %rsi     # 0x230b9
callq 0x4240
leaq 0x1372c(%rip), %rsi     # 0x230d3
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
movl %ebp, %esi
callq 0x43a0
leaq 0x13744(%rip), %rsi     # 0x23104
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4130
leaq 0x228(%rsp), %rdi
callq 0x4080
testb %al, %al
je 0xfadd
leaq 0x1b8(%rsp), %r14
xorl %r15d, %r15d
pushq $0x18
popq %r13
leaq 0x14521(%rip), %r12     # 0x23f1c
xorl %ebp, %ebp
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
cqto
idivq %r13
cmpq %rax, %rbp
jae 0xfaa7
movq %r14, %rdi
leaq 0x13776(%rip), %rsi     # 0x23193
callq 0x4240
movq %rax, %rdi
movq %rbp, %rsi
callq 0x41a0
movq %rax, %rdi
movq %r12, %rsi
callq 0x4240
movq %rax, %rdi
callq 0x4130
movq 0x60(%rbx), %rsi
addq %r15, %rsi
movq %r14, %rdi
callq 0x18551
movq %rax, %rdi
callq 0x4130
movq %r14, %rdi
leaq 0x1373a(%rip), %rsi     # 0x2319b
callq 0x4240
movq %rax, %rdi
movq %rbp, %rsi
callq 0x41a0
movq %rax, %rdi
movq %r12, %rsi
callq 0x4240
movq %rax, %rdi
callq 0x4130
movq 0x78(%rbx), %rsi
addq %r15, %rsi
movq %r14, %rdi
callq 0x18551
movq %rax, %rdi
callq 0x4130
incq %rbp
addq $0x18, %r15
jmp 0xf9fd
leaq 0x1a8(%rsp), %rdi
callq 0x4050
leaq 0x1a8(%rsp), %rdi
callq 0x4070
leaq 0x30(%rsp), %rdi
callq 0x40a0
addq $0x3b8, %rsp            # imm = 0x3B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x234f4(%rip), %rdi     # 0x32fd8
leaq 0x135ce(%rip), %rsi     # 0x230b9
callq 0x4240
leaq 0x13618(%rip), %rsi     # 0x2310f
movq %rax, %rdi
callq 0x4240
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x4310
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x41f0
leaq 0x13607(%rip), %rsi     # 0x2312a
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4130
leaq 0x10(%rsp), %rdi
callq 0x4100
movq 0x23494(%rip), %rdi     # 0x32fd8
leaq 0x135fa(%rip), %rsi     # 0x23145
callq 0x4240
movq %rax, %rdi
callq 0x4130
xorl %edi, %edi
callq 0x4260
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4100
jmp 0xfb8b
jmp 0xfb88
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4100
jmp 0xfb98
jmp 0xfb81
movq %rax, %rbx
jmp 0xfb98
jmp 0xfb88
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x4070
leaq 0x30(%rsp), %rdi
callq 0x40a0
movq %rbx, %rdi
callq 0x43b0