// File: btbujiangjun[P]abcdl/src/algebra/MatrixAlgebra.cpp
// Function: abcdl::algebra::Matrix<int>::argmax(abcdl::algebra::Axis_type) const
Matrix<size_t> Matrix<T>::argmax(Axis_type axis_type) const{
    size_t size = (axis_type == Axis_type::ROW)? _rows : _cols;
   	size_t end_idx = (axis_type == Axis_type::ROW) ? _cols : _rows;
    size_t* idx_data = new size_t[size];
    for(size_t i = 0; i != size; i++){
        T max_value = 0;
        size_t max_idx = 0;
        for(size_t j = 0; j != end_idx; j++){
            T value = (axis_type == Axis_type::ROW) ? _data[i * _cols + j] : _data[j * _cols + i];
            if( j == 0 || value > max_value){
                max_value = value;
                max_idx = j;
            }
        }
        idx_data[i] = max_idx;
    }

    size_t rows = (axis_type == Axis_type::ROW) ? size : 1;
    size_t cols = (axis_type == Axis_type::ROW) ? 1 : size;

	abcdl::algebra::Matrix<size_t> mat;
	mat.set_shallow_data(idx_data, rows, cols);

    return mat;
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0x30(%rsp)
movq %rdi, %rax
movq %rax, 0x38(%rsp)
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movl %edx, 0xb4(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpl $0x0, 0xb4(%rsp)
jne 0x5b9a1
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0x5b9af
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0xa8(%rsp)
cmpl $0x0, 0xb4(%rsp)
jne 0x5b9d6
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x5b9e3
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa8(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x9030
movq %rax, 0x98(%rsp)
movq $0x0, 0x90(%rsp)
movq 0x90(%rsp), %rax
cmpq 0xa8(%rsp), %rax
je 0x5bb45
movl $0x0, 0x8c(%rsp)
movq $0x0, 0x80(%rsp)
movq $0x0, 0x78(%rsp)
movq 0x78(%rsp), %rax
cmpq 0xa0(%rsp), %rax
je 0x5bb10
cmpl $0x0, 0xb4(%rsp)
jne 0x5baa4
movq 0x40(%rsp), %rdx
movq 0x10(%rdx), %rax
movq 0x90(%rsp), %rcx
imulq 0x8(%rdx), %rcx
addq 0x78(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x1c(%rsp)
jmp 0x5bac6
movq 0x40(%rsp), %rdx
movq 0x10(%rdx), %rax
movq 0x78(%rsp), %rcx
imulq 0x8(%rdx), %rcx
addq 0x90(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x74(%rsp)
cmpq $0x0, 0x78(%rsp)
je 0x5bae3
movl 0x74(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jle 0x5bafb
movl 0x74(%rsp), %eax
movl %eax, 0x8c(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x80(%rsp)
jmp 0x5bafd
movq 0x78(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x78(%rsp)
jmp 0x5ba63
movq 0x80(%rsp), %rdx
movq 0x98(%rsp), %rax
movq 0x90(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x90(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x90(%rsp)
jmp 0x5ba2d
cmpl $0x0, 0xb4(%rsp)
jne 0x5bb5e
movq 0xa8(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x5bb6a
movl $0x1, %eax
movq %rax, 0x10(%rsp)
jmp 0x5bb6a
movq 0x10(%rsp), %rax
movq %rax, 0x68(%rsp)
cmpl $0x0, 0xb4(%rsp)
jne 0x5bb8a
movl $0x1, %eax
movq %rax, 0x8(%rsp)
jmp 0x5bb97
movq 0xa8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rax
movq %rax, 0x60(%rsp)
movb $0x0, 0x5f(%rsp)
callq 0x38000
movq 0x30(%rsp), %rdi
movq 0x98(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rcx
callq 0x38a30
jmp 0x5bbce
movb $0x1, 0x5f(%rsp)
testb $0x1, 0x5f(%rsp)
jne 0x5bc00
jmp 0x5bbf6
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
callq 0x38480
jmp 0x5bc0d
movq 0x30(%rsp), %rdi
callq 0x38480
movq 0x38(%rsp), %rax
addq $0xc8, %rsp
retq
movq 0x50(%rsp), %rdi
callq 0x9700
nopw (%rax,%rax)