// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r12
movss 0x30(%rdi), %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x34(%rdi), %xmm0
movss %xmm0, 0xc(%rsp)
movq 0x8(%rdi), %r14
imulq (%rdi), %r14
movq %r14, 0x18(%rsp)
movq 0x10(%rdi), %rax
movq %rax, 0x50(%rsp)
leaq 0x18(%rdi), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xb81c
movq %rax, %rbx
cmpq %rax, 0x20(%r12)
jae 0x1b674
movq (%r15), %r14
jmp 0x1b687
movq %r14, %rax
xorl %edx, %edx
divq %rbx
movq %rax, %r14
cmpq $0x1, %rdx
sbbq $-0x1, %r14
movss 0xc(%rsp), %xmm0
subss 0x10(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x58(%rsp), %rdx
movq %r14, %rsi
callq 0xa09c
callq 0x9060
xorl %ebp, %ebp
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
divq %rcx
cmpq $0x1, %rdx
adcq $0x0, %rdx
leaq 0x30(%rsp), %rax
movq %rdx, (%rax)
movsd 0x28(%r12), %xmm0
leaq 0x88(%rsp), %rax
movsd %xmm0, (%rax)
andl $0x0, 0x8(%rax)
movb $0x0, 0xc(%rax)
leaq 0x80(%rsp), %r12
leaq 0x28(%rsp), %r13
xorl %r15d, %r15d
subq $0x1, %r14
jb 0x1b797
leaq 0x50(%rsp), %rax
movq %rax, 0x58(%rsp)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x60(%rsp)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x64(%rsp)
movss 0x14(%rsp), %xmm0
movss %xmm0, 0x68(%rsp)
leaq 0x88(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x78(%rsp)
movq %rbp, 0x28(%rsp)
addq %rbx, %rbp
cmpq 0x18(%rsp), %rbp
movq %rbp, 0x20(%rsp)
leaq 0x18(%rsp), %rcx
leaq 0x20(%rsp), %rax
cmovbq %rax, %rcx
movq %r12, %rdi
leaq 0x58(%rsp), %rsi
movq %r13, %rdx
callq 0x1b7e8
movq 0x38(%rsp), %rdi
addq %r15, %rdi
movq %r12, %rsi
callq 0xa174
movq %r12, %rdi
callq 0xa18e
addq $0x8, %r15
jmp 0x1b6f7
movq 0x38(%rsp), %rbx
movq 0x40(%rsp), %r14
cmpq %r14, %rbx
je 0x1b7b4
movq %rbx, %rdi
callq 0x95b0
addq $0x8, %rbx
jmp 0x1b7a1
leaq 0x38(%rsp), %rdi
callq 0xa19c
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1b7d2
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xa19c
movq %rbx, %rdi
callq 0x95e0
nop