// File: btbujiangjun[P]abcdl/src/algebra/MatrixBase.cpp
// Function: abcdl::algebra::RandomMatrix<float>::reset()
void RandomMatrix<T>::reset(){
    T scale = _max - _min;
    T min   = _min;
    T max   = _max;

    size_t size = this->_rows * this->_cols;
    T* data = this->_data;
    size_t block_size = this->_po.get_block_size(size);
    size_t num_thread = this->_po.get_num_thread(size, block_size);
    std::vector<std::thread> threads(num_thread);
    std::default_random_engine engine(std::chrono::system_clock::now().time_since_epoch().count());
    std::normal_distribution<T> distribution(_mean_value, _stddev);

    for(size_t i = 0; i != num_thread; i++){
        threads[i] = std::thread(
            [&data, max, min, scale, &distribution, &engine](size_t start_idx, size_t end_idx){
                for(size_t ti = start_idx; ti != end_idx; ti++){
                    T value = static_cast<T>(distribution(engine));
                    if(max == min || value == max || value == min){
                        data[ti] = value;
                    }else if(value > max){
                        real step = (value - min)/scale;
                        value = min + (step - (int)step) * scale;
                    }else{
                        real step = (max - value)/scale;
                        value = min + (step - (int)step) * scale;
                    }
                }
            }, i * block_size, std::min(size, (i + 1) * block_size)
        );
    }

    for(auto& thread : threads){
        thread.join();
    }
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x130(%rsp)
movq 0x130(%rsp), %rdi
movq %rdi, 0x20(%rsp)
movss 0x30(%rdi), %xmm1
movss 0x34(%rdi), %xmm0
subss %xmm1, %xmm0
movss %xmm0, 0x12c(%rsp)
movss 0x30(%rdi), %xmm0
movss %xmm0, 0x128(%rsp)
movss 0x34(%rdi), %xmm0
movss %xmm0, 0x124(%rsp)
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
imulq %rcx, %rax
movq %rax, 0x118(%rsp)
movq 0x10(%rdi), %rax
movq %rax, 0x110(%rsp)
addq $0x18, %rdi
movq %rdi, 0x28(%rsp)
movq 0x118(%rsp), %rsi
callq 0xd830
movq 0x28(%rsp), %rdi
movq %rax, 0x108(%rsp)
movq 0x118(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0xd8c0
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0xe7(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0xa9f0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0xe8(%rsp), %rdi
callq 0xaa00
jmp 0x3a716
leaq 0xe7(%rsp), %rdi
callq 0xaa80
callq 0x9070
movq %rax, 0xb8(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x2dab0
movq %rax, 0x18(%rsp)
jmp 0x3a744
movq 0x18(%rsp), %rax
movq %rax, 0xc0(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x2da10
movq %rax, 0x10(%rsp)
jmp 0x3a765
movq 0x10(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x3a9b0
jmp 0x3a779
movq 0x20(%rsp), %rax
movss 0x28(%rax), %xmm0
movss 0x2c(%rax), %xmm1
leaq 0xa8(%rsp), %rdi
callq 0x3a9e0
jmp 0x3a797
movq $0x0, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
cmpq 0x100(%rsp), %rax
je 0x3a916
leaq 0x110(%rsp), %rax
movq %rax, 0x70(%rsp)
movss 0x124(%rsp), %xmm0
movss %xmm0, 0x78(%rsp)
movss 0x128(%rsp), %xmm0
movss %xmm0, 0x7c(%rsp)
movss 0x12c(%rsp), %xmm0
movss %xmm0, 0x80(%rsp)
leaq 0xa8(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0xc8(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0xa0(%rsp), %rax
movq 0x108(%rsp), %rcx
imulq %rcx, %rax
movq %rax, 0x68(%rsp)
movq 0xa0(%rsp), %rax
incq %rax
movq 0x108(%rsp), %rcx
imulq %rcx, %rax
movq %rax, 0x60(%rsp)
leaq 0x118(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xaa90
movq %rax, 0x8(%rsp)
jmp 0x3a864
movq 0x8(%rsp), %rcx
leaq 0x98(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0x3aa30
jmp 0x3a882
movq 0xa0(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0xaba0
movq %rax, %rdi
leaq 0x98(%rsp), %rsi
callq 0xabc0
leaq 0x98(%rsp), %rdi
callq 0xac00
movq 0xa0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
jmp 0x3a7a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0xe7(%rsp), %rdi
callq 0xaa80
jmp 0x3a994
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xacf0
jmp 0x3a994
leaq 0xe8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rdi
callq 0xac20
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rdi
callq 0xac50
movq %rax, 0x48(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0xac80
testb $0x1, %al
jne 0x3a956
jmp 0x3a97f
leaq 0x50(%rsp), %rdi
callq 0xacc0
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
callq 0x96c0
jmp 0x3a971
jmp 0x3a973
leaq 0x50(%rsp), %rdi
callq 0xacd0
jmp 0x3a941
leaq 0xe8(%rsp), %rdi
callq 0xacf0
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xd8(%rsp), %rdi
callq 0x9700
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)