#pragma once #include //uint64_t //#include // std::runtime_error #include #include #include "utils/vector.h" #include "utils/matrix.h" namespace numerics::detail{ // Shared engine inline std::mt19937& rng() { static std::random_device rd; static std::mt19937 gen(rd()); return gen; } // Integral overload template < typename T, typename std::enable_if::value, int>::type = 0 > inline T random(const T low, const T high) { std::uniform_int_distribution dist(low, high); return dist(rng()); } // Floating-point overload template < typename T, typename std::enable_if::value, int>::type = 0 > inline T random(const T low, const T high) { std::uniform_real_distribution dist(low, high); return dist(rng()); } // ---------------- Matrix ---------------- template inline void inplace_random_serial(utils::Matrix& A, const T low, const T high) { const uint64_t rows = A.rows(); const uint64_t cols = A.cols(); for (uint64_t i = 0; i < rows; ++i){ for (uint64_t j = 0; j < cols; ++j){ A(i,j) = random(low, high); } } } // ---------------- Vector ---------------- template inline void inplace_random_serial(utils::Vector& v, const T low, const T high) { const uint64_t N = v.size(); for (uint64_t i = 0; i < N; ++i){ v[i] = random(low, high); } } } // namespace numerics