MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
random.hpp File Reference
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <random>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <mtl/concepts/matrix.hpp>
#include <mtl/concepts/vector.hpp>
#include <mtl/mat/dense2D.hpp>
#include <mtl/vec/dense_vector.hpp>

Namespaces

namespace  mtl
namespace  mtl::detail
 mat*vec multiply into pre-allocated y: y = A * x.

Functions

std::mt19937_64 mtl::detail::random_engine ()
 A std::mt19937_64 seeded from std::random_device, for the calls without a seed.
double mtl::detail::random_unit (std::mt19937_64 &gen)
 Uniform on [0, 1): the top 53 bits of one 64-bit draw.
template<typename T>
void mtl::detail::check_random_bounds (const T &lo, const T &hi, const char *who)
 Throws unless lo and hi are finite and lo <= hi.
template<typename T>
T mtl::detail::random_uniform (std::mt19937_64 &gen, const T &lo, const T &hi)
 One value uniform on [lo, hi), or lo when lo == hi. Bounds already checked.
template<Vector V>
void mtl::fill_random (V &v, typename V::value_type lo, typename V::value_type hi, std::mt19937_64 &gen)
 Fill a vector with uniform random values in [lo, hi), drawn from gen.
template<Matrix M>
void mtl::fill_random (M &A, typename M::value_type lo, typename M::value_type hi, std::mt19937_64 &gen)
 Fill a matrix with uniform random values in [lo, hi), drawn from gen row by row.
template<Vector V>
void mtl::fill_random (V &v, typename V::value_type lo, typename V::value_type hi, std::uint64_t seed)
 Fill a vector with uniform random values in [lo, hi), reproducibly from seed.
template<Matrix M>
void mtl::fill_random (M &A, typename M::value_type lo, typename M::value_type hi, std::uint64_t seed)
 Fill a matrix with uniform random values in [lo, hi), reproducibly from seed.
template<Vector V>
void mtl::fill_random (V &v, typename V::value_type lo=typename V::value_type(0), typename V::value_type hi=typename V::value_type(1))
 Fill a vector with uniform random values in [lo, hi), non-deterministically.
template<Matrix M>
void mtl::fill_random (M &A, typename M::value_type lo=typename M::value_type(0), typename M::value_type hi=typename M::value_type(1))
 Fill a matrix with uniform random values in [lo, hi), non-deterministically.
template<typename T = double>
auto mtl::random_vector (std::size_t n, T lo, T hi, std::mt19937_64 &gen)
 A dense_vector of size n with uniform values in [lo, hi), drawn from gen.
template<typename T = double>
auto mtl::random_vector (std::size_t n, T lo, T hi, std::uint64_t seed)
 A dense_vector of size n with uniform values in [lo, hi), reproducibly from seed.
template<typename T = double>
auto mtl::random_vector (std::size_t n, T lo=T(0), T hi=T(1))
 A dense_vector of size n with uniform values in [lo, hi), non-deterministically.
template<typename T = double>
auto mtl::random_matrix (std::size_t m, std::size_t n, T lo, T hi, std::mt19937_64 &gen)
 An m x n dense2D with uniform values in [lo, hi), drawn from gen row by row.
template<typename T = double>
auto mtl::random_matrix (std::size_t m, std::size_t n, T lo, T hi, std::uint64_t seed)
 An m x n dense2D with uniform values in [lo, hi), reproducibly from seed.
template<typename T = double>
auto mtl::random_matrix (std::size_t m, std::size_t n, T lo=T(0), T hi=T(1))
 An m x n dense2D with uniform values in [lo, hi), non-deterministically.