// File: xbai0624[P]dnn/src/Matrix.cpp
// Function: Matrix::ConcatenateMatrixByI(std::vector<Matrix, std::allocator<Matrix>>&)
Matrix Matrix::ConcatenateMatrixByI(std::vector<Matrix> &A)
{
    // vertically place a vector of matrix together, 

    // method 1: seems pretty slow
    //Matrix C = A[0];

    //for(size_t i=1;i<A.size();i++)
    //{
    //    auto dimAI = A[i].Dimension();
    //    for(size_t ii=0;ii<dimAI.first;ii++)
    //    {
    //        auto dimC = C.Dimension();
    //        assert(dimC.second == dimAI.second);
    //        C.InsertRow(dimC.first, &A[i][ii]);
    //    }
    //}

    // method 2
    auto dim = A[0].Dimension();
    size_t length = A.size();

    Matrix C(dim.first*length, dim.second, 0);

    for(size_t i=0;i<length;i++)
    {
        assert(dim.second == A[i].Dimension().second);
        assert(dim.first == A[i].Dimension().first);

        for(size_t ii=0;ii<dim.first;ii++)
            for(size_t jj=0;jj<dim.second;jj++)
                C[i*dim.first + ii][jj] = (A[i])[ii][jj];
    }

    return C;
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0x48(%rsp)
movq %rdi, %rax
movq %rax, 0x40(%rsp)
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdi
callq 0x3bae0
movq %rax, 0xa8(%rsp)
movq %rdx, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x1f9c0
movq 0x48(%rsp), %rdi
movq %rax, 0xa0(%rsp)
movb $0x0, 0x9f(%rsp)
movq 0xa8(%rsp), %rsi
imulq 0xa0(%rsp), %rsi
movq 0xb0(%rsp), %rdx
xorps %xmm0, %xmm0
callq 0x3b590
movq $0x0, 0x90(%rsp)
movq 0x90(%rsp), %rax
cmpq 0xa0(%rsp), %rax
jae 0x3fd71
movq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xb8(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x1f9e0
movq %rax, %rdi
callq 0x3bae0
movq %rdx, 0x30(%rsp)
movq %rax, 0x38(%rsp)
jmp 0x3fba8
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq %rdx, 0x80(%rsp)
movq %rcx, 0x88(%rsp)
cmpq 0x88(%rsp), %rax
jne 0x3fbd3
jmp 0x3fc0f
leaq 0x1561f(%rip), %rdi     # 0x551f9
leaq 0x152aa(%rip), %rsi     # 0x54e8b
movl $0x3c6, %edx            # imm = 0x3C6
leaq 0x15632(%rip), %rcx     # 0x5521f
callq 0x4170
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
callq 0x3bb80
jmp 0x3fd9a
movq 0xa8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xb8(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x1f9e0
movq %rax, %rdi
callq 0x3bae0
movq %rdx, 0x18(%rsp)
movq %rax, 0x20(%rsp)
jmp 0x3fc45
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, 0x60(%rsp)
movq %rcx, 0x68(%rsp)
cmpq 0x60(%rsp), %rax
jne 0x3fc67
jmp 0x3fc86
leaq 0x155f3(%rip), %rdi     # 0x55261
leaq 0x15216(%rip), %rsi     # 0x54e8b
movl $0x3c7, %edx            # imm = 0x3C7
leaq 0x1559e(%rip), %rcx     # 0x5521f
callq 0x4170
movq $0x0, 0x58(%rsp)
movq 0x58(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jae 0x3fd56
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jae 0x3fd41
movq 0xb8(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x1f9e0
movq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x50(%rsp), %rsi
callq 0x1fd60
movq 0x48(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x90(%rsp), %rsi
imulq 0xa8(%rsp), %rsi
addq 0x58(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x50(%rsp), %rsi
callq 0x1fd60
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x3fcab
jmp 0x3fd43
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x3fc8f
jmp 0x3fd58
movq 0x90(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x90(%rsp)
jmp 0x3fb5c
movb $0x1, 0x9f(%rsp)
testb $0x1, 0x9f(%rsp)
jne 0x3fd8d
movq 0x48(%rsp), %rdi
callq 0x3bb80
movq 0x40(%rsp), %rax
addq $0xc8, %rsp
retq
movq 0x78(%rsp), %rdi
callq 0x43f0
nopw %cs:(%rax,%rax)