// File: xbai0624[P]dnn/src/Matrix.cpp
// Function: Matrix::CombineMatrix(std::vector<Matrix, std::allocator<Matrix>>&, unsigned long, unsigned long)
Matrix Matrix::CombineMatrix(std::vector<Matrix> &vec, size_t R, size_t C)
{
    // combine a vector of matrix'es to one big matrix,
    // the big matrix dimension is R, C
    Matrix _m(R, C);
    size_t N = vec.size();
    auto dim = vec[0].Dimension();
    if(R*C != N * dim.first * dim.second ) {
        std::cout<<"Error: combining matrix dimension not match."<<std::endl;
        exit(0);
    }

    size_t index = 0;
    for(auto &m: vec){
        for(size_t i=0;i<dim.first;i++){
            for(size_t j=0;j<dim.second;j++){
                _m.FillElementByRow(index, m[i][j]);
                index++;
            }
        }
    }

    if(index != R*C) {
        std::cout<<"Error: combining matrix dimension not match."<<std::endl;
        exit(0);
    }

    return _m;
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0x20(%rsp)
movq %rdi, %rax
movq %rax, 0x28(%rsp)
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movq %rdx, 0xb0(%rsp)
movq %rcx, 0xa8(%rsp)
movb $0x0, 0xa7(%rsp)
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
callq 0x3b3b0
movq 0xb8(%rsp), %rdi
callq 0x1f9c0
movq %rax, 0x98(%rsp)
movq 0xb8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdi
callq 0x3bae0
movq %rdx, 0x30(%rsp)
movq %rax, 0x38(%rsp)
jmp 0x3f43b
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq %rax, 0x90(%rsp)
movq 0xb0(%rsp), %rax
imulq 0xa8(%rsp), %rax
movq 0x98(%rsp), %rcx
imulq 0x88(%rsp), %rcx
imulq 0x90(%rsp), %rcx
cmpq %rcx, %rax
je 0x3f4d9
movq 0x2bb4c(%rip), %rdi     # 0x6afd8
leaq 0x15ccb(%rip), %rsi     # 0x5515e
callq 0x4230
movq %rax, 0x18(%rsp)
jmp 0x3f49f
movq 0x18(%rsp), %rdi
movq 0x2bb05(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x3f4b2
xorl %edi, %edi
callq 0x4290
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
callq 0x3bb80
jmp 0x3f65f
movq $0x0, 0x70(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdi
callq 0x1fe00
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rdi
callq 0x1fe30
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x1fe60
testb $0x1, %al
jne 0x3f525
jmp 0x3f5e7
leaq 0x60(%rsp), %rdi
callq 0x1fea0
movq %rax, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq 0x88(%rsp), %rax
jae 0x3f5d6
movq $0x0, 0x40(%rsp)
movq 0x40(%rsp), %rax
cmpq 0x90(%rsp), %rax
jae 0x3f5c1
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x40(%rsp), %rsi
callq 0x1fd60
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movsd (%rax), %xmm0
callq 0x3ebf0
jmp 0x3f5a3
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x3f559
jmp 0x3f5c3
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x3f53d
jmp 0x3f5d8
leaq 0x60(%rsp), %rdi
callq 0x1ff20
jmp 0x3f50d
movq 0x70(%rsp), %rax
movq 0xb0(%rsp), %rcx
imulq 0xa8(%rsp), %rcx
cmpq %rcx, %rax
je 0x3f636
movq 0x2b9cf(%rip), %rdi     # 0x6afd8
leaq 0x15b4e(%rip), %rsi     # 0x5515e
callq 0x4230
movq %rax, 0x8(%rsp)
jmp 0x3f61c
movq 0x8(%rsp), %rdi
movq 0x2b988(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x3f62f
xorl %edi, %edi
callq 0x4290
movb $0x1, 0xa7(%rsp)
testb $0x1, 0xa7(%rsp)
jne 0x3f652
movq 0x20(%rsp), %rdi
callq 0x3bb80
movq 0x28(%rsp), %rax
addq $0xc8, %rsp
retq
movq 0x80(%rsp), %rdi
callq 0x43f0
nopl (%rax)