// File: 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:
subq $0x4b8, %rsp            # imm = 0x4B8
movq %rdi, 0x4b0(%rsp)
movq 0x4b0(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
movq (%rdi), %rax
movq 0x298(%rax), %rax
callq *%rax
movq 0xb0(%rsp), %rdi
movl %eax, 0x4ac(%rsp)
movq (%rdi), %rax
movq 0x250(%rax), %rax
callq *%rax
movq 0xb0(%rsp), %rdi
movl %eax, 0x4a8(%rsp)
movq (%rdi), %rax
movq 0x258(%rax), %rax
callq *%rax
movl %eax, 0x4a4(%rsp)
leaq 0x328(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x42d0
movq 0xb8(%rsp), %rdi
leaq 0x390bc(%rip), %rsi     # 0x53bb8
callq 0x4230
jmp 0x1ab03
movl 0x4ac(%rsp), %esi
leaq 0x328(%rsp), %rdi
callq 0x43e0
jmp 0x1ab19
leaq 0x328(%rsp), %rdi
leaq 0x4a8(%rsp), %rsi
callq 0x3aa10
jmp 0x1ab30
leaq 0x328(%rsp), %rdi
leaq 0x4a4(%rsp), %rsi
callq 0x3aba0
jmp 0x1ab47
leaq 0x3908c(%rip), %rsi     # 0x53bda
leaq 0x328(%rsp), %rdi
callq 0x4230
jmp 0x1ab5d
leaq 0xe8(%rsp), %rdi
leaq 0x328(%rsp), %rsi
callq 0x4250
jmp 0x1ab74
leaq 0x108(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
movl $0x10, %edx
callq 0x4390
jmp 0x1ab90
leaq 0xe8(%rsp), %rdi
callq 0x4160
movq 0x50434(%rip), %rdi     # 0x6afd8
leaq 0x39045(%rip), %rsi     # 0x53bf0
callq 0x4230
movq %rax, 0xa8(%rsp)
jmp 0x1abba
movq 0xa8(%rsp), %rdi
leaq 0x39041(%rip), %rsi     # 0x53c0a
callq 0x4230
movq %rax, 0xa0(%rsp)
jmp 0x1abd8
movq 0xa0(%rsp), %rdi
movl 0x4ac(%rsp), %esi
callq 0x43e0
movq %rax, 0x98(%rsp)
jmp 0x1abf6
movq 0x98(%rsp), %rdi
leaq 0x39036(%rip), %rsi     # 0x53c3b
callq 0x4230
movq %rax, 0x90(%rsp)
jmp 0x1ac14
movq 0x90(%rsp), %rdi
movq 0x5038d(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x1ac2a
leaq 0x108(%rsp), %rdi
callq 0x43d0
movb %al, 0x8f(%rsp)
jmp 0x1ac40
movb 0x8f(%rsp), %al
testb $0x1, %al
jne 0x1ada3
jmp 0x1ac51
movq 0x50380(%rip), %rdi     # 0x6afd8
leaq 0x38f91(%rip), %rsi     # 0x53bf0
callq 0x4230
movq %rax, 0x80(%rsp)
jmp 0x1ac6e
movq 0x80(%rsp), %rdi
leaq 0x38fc9(%rip), %rsi     # 0x53c46
callq 0x4230
movq %rax, 0x78(%rsp)
jmp 0x1ac89
leaq 0xc8(%rsp), %rdi
leaq 0x328(%rsp), %rsi
callq 0x4250
jmp 0x1aca0
movq 0x78(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x41f0
movq %rax, 0x70(%rsp)
jmp 0x1acb9
movq 0x70(%rsp), %rdi
leaq 0x38f9c(%rip), %rsi     # 0x53c61
callq 0x4230
movq %rax, 0x68(%rsp)
jmp 0x1acd1
movq 0x68(%rsp), %rdi
movq 0x502d3(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x1ace4
leaq 0xc8(%rsp), %rdi
callq 0x4160
movq 0x502e0(%rip), %rdi     # 0x6afd8
leaq 0x38f7d(%rip), %rsi     # 0x53c7c
callq 0x4230
movq %rax, 0x60(%rsp)
jmp 0x1ad0b
movq 0x60(%rsp), %rdi
movq 0x50299(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x1ad1e
xorl %edi, %edi
callq 0x4290
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x320(%rsp)
movl %eax, 0x31c(%rsp)
jmp 0x1af8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x320(%rsp)
movl %eax, 0x31c(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x4160
jmp 0x1af8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x320(%rsp)
movl %eax, 0x31c(%rsp)
jmp 0x1af82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x320(%rsp)
movl %eax, 0x31c(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x4160
jmp 0x1af82
movq $0x0, 0xc0(%rsp)
movq 0xb0(%rsp), %rdi
movq 0xc0(%rsp), %rax
movq %rax, 0x58(%rsp)
addq $0x60, %rdi
callq 0x1f9c0
movq %rax, %rcx
movq 0x58(%rsp), %rax
cmpq %rcx, %rax
jae 0x1af51
leaq 0x118(%rsp), %rdi
leaq 0x38edd(%rip), %rsi     # 0x53cca
callq 0x4230
movq %rax, 0x50(%rsp)
jmp 0x1adf9
movq 0x50(%rsp), %rdi
movq 0xc0(%rsp), %rsi
callq 0x4080
movq %rax, 0x48(%rsp)
jmp 0x1ae12
movq 0x48(%rsp), %rdi
leaq 0x3a039(%rip), %rsi     # 0x54e57
callq 0x4230
movq %rax, 0x40(%rsp)
jmp 0x1ae2a
movq 0x40(%rsp), %rdi
movq 0x5017a(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x1ae3d
movq 0xb0(%rsp), %rdi
leaq 0x118(%rsp), %rax
movq %rax, 0x30(%rsp)
addq $0x60, %rdi
movq 0xc0(%rsp), %rsi
callq 0x1f9e0
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x3d640
movq %rax, 0x38(%rsp)
jmp 0x1ae77
movq 0x38(%rsp), %rdi
movq 0x5012d(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x1ae8a
leaq 0x118(%rsp), %rdi
leaq 0x38e39(%rip), %rsi     # 0x53cd2
callq 0x4230
movq %rax, 0x28(%rsp)
jmp 0x1aea5
movq 0x28(%rsp), %rdi
movq 0xc0(%rsp), %rsi
callq 0x4080
movq %rax, 0x20(%rsp)
jmp 0x1aebe
movq 0x20(%rsp), %rdi
leaq 0x39f8d(%rip), %rsi     # 0x54e57
callq 0x4230
movq %rax, 0x18(%rsp)
jmp 0x1aed6
movq 0x18(%rsp), %rdi
movq 0x500ce(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x1aee9
movq 0xb0(%rsp), %rdi
leaq 0x118(%rsp), %rax
movq %rax, 0x8(%rsp)
addq $0x78, %rdi
movq 0xc0(%rsp), %rsi
callq 0x1f9e0
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x3d640
movq %rax, 0x10(%rsp)
jmp 0x1af23
movq 0x10(%rsp), %rdi
movq 0x50081(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x1af36
jmp 0x1af38
movq 0xc0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc0(%rsp)
jmp 0x1adaf
leaq 0x108(%rsp), %rdi
callq 0x4050
jmp 0x1af60
leaq 0x108(%rsp), %rdi
callq 0x4070
leaq 0x328(%rsp), %rdi
callq 0x4090
addq $0x4b8, %rsp            # imm = 0x4B8
retq
leaq 0x108(%rsp), %rdi
callq 0x4070
leaq 0x328(%rsp), %rdi
callq 0x4090
movq 0x320(%rsp), %rdi
callq 0x43f0
nopl (%rax)