src/features/random.c file

Classes

struct normal_stream

Functions

static auto from_bits(const uint64_t bits) -> double
static auto splitmix64_next(vm_rng* rng) -> uint64_t
static auto uniform_open(vm_rng* rng) -> double
static auto ln_positive(const double x) -> double
static auto sin_small(const double x) -> double
static auto cos_small(const double x) -> double
static void sincos_unit(double u, double* sn, double* cs)
static void box_muller(vm_rng* rng, double* z0, double* z1)
static auto standard_normal(normal_stream* stream) -> double
static auto scaled(const double z, const double scale) -> vm_float_t
static void store(const vm_mat* A, const int r, const int c, const vm_float_t v)
static auto square_ready(const vm_mat* A) -> bool
void vm_rng_seed(vm_rng* rng, uint64_t seed)
Seed rng and advance splitmix64 once.
auto vm_goe(const vm_mat* A, vm_rng* rng) -> bool
Overwrite A with a GOE matrix.
auto vm_gue(const vm_mat* Ar, const vm_mat* Ai, vm_rng* rng) -> bool
Overwrite Ar and Ai with the real and imaginary parts of a GUE matrix.

Function documentation

void vm_rng_seed(vm_rng* rng, uint64_t seed)

Seed rng and advance splitmix64 once.

Parameters
rng Generator to seed.
seed Any value, including 0.

The stored counter is seed plus the splitmix64 increment, so seed 0 is a valid state. A null rng is ignored.

bool vm_goe(const vm_mat* A, vm_rng* rng)

Overwrite A with a GOE matrix.

Parameters
A Square column-major matrix. Overwritten on success.
rng Seeded generator.
Returns true on success.

A is square and rows >= 1. Diagonal entries are N(0, 2). Off-diagonal entries are N(0, 1). Row i draws the diagonal first, then columns j > i, and that one value is stored at both (i, j) and (j, i). A Box–Muller partner left over at the end of the call is discarded.

A null rng, a null matrix, a null data pointer, a non-square, or rows < 1 returns false and does not write. rng is left unchanged.

bool vm_gue(const vm_mat* Ar, const vm_mat* Ai, vm_rng* rng)

Overwrite Ar and Ai with the real and imaginary parts of a GUE matrix.

Parameters
Ar Real part. Overwritten on success.
Ai Imaginary part. Overwritten on success.
rng Seeded generator.
Returns true on success.

Both matrices are square and have the same order, at least 1. Diagonal real entries are N(0, 1). Diagonal imaginary entries are 0. Off-diagonal real and imaginary entries are each N(0, 1/2). Row i draws the diagonal real first, then for each j > i the real part and then the imaginary part. The real value is stored at both (i, j) and (j, i). The imaginary value is stored at (i, j) and its negation at (j, i). A Box–Muller partner left over at the end of the call is discarded.

A null rng, a null matrix, a null data pointer, a non-square, rows < 1, or two different orders returns false and does not write. rng is left unchanged.