random.h#
-
namespace ONNX_LIGHT_NAMESPACE
-
namespace onnx_backend_test
Functions
-
std::pair<uint64_t, uint64_t> NextUint64(uint64_t state)#
Computes the next SplitMix64 state and the corresponding random 64-bit value. The implementation matches the canonical SplitMix64 generator and is bit-identical to the Python reference in
onnx_light.backend.random.- Parameters:
state – Current 64-bit state.
- Returns:
std::pair{next_state, random_value}.
-
std::vector<double> Rand(const std::vector<int64_t> &shape, std::optional<uint64_t> seed = std::nullopt)#
Generates deterministic uniform random values in
[0, 1)shaped asshape. An emptyshapeproduces a single value (count 1).- Parameters:
shape – Output shape; dimensions must be non-negative.
seed – Optional 64-bit seed.
std::nulloptselects the default seed (0).
- Throws:
std::invalid_argument – when any dimension is negative.
- Returns:
Flat row-major
std::vector<double>of lengthprod(shape).
-
std::vector<int64_t> RandInt(int64_t low, int64_t high, const std::vector<int64_t> &shape, std::optional<uint64_t> seed = std::nullopt)#
Generates deterministic pseudo-random integers in the half-open interval
[low, high)using rejection sampling on the SplitMix64 output to obtain an unbiased distribution.- Parameters:
low – Inclusive lower bound.
high – Exclusive upper bound. Must be strictly greater than
low.shape – Output shape; dimensions must be non-negative.
seed – Optional 64-bit seed.
std::nulloptselects the default seed.
- Throws:
std::invalid_argument – when
high <= lowor any dimension is negative.- Returns:
Flat row-major
std::vector<int64_t>of lengthprod(shape).
-
std::vector<double> Randn(const std::vector<int64_t> &shape, std::optional<uint64_t> seed = std::nullopt)#
Generates deterministic pseudo-random values with an approximate normal distribution using the Irwin-Hall approximation (sum of 12 uniform values minus 6).
- Parameters:
shape – Output shape; dimensions must be non-negative.
seed – Optional 64-bit seed.
std::nulloptselects the default seed.
- Throws:
std::invalid_argument – when any dimension is negative.
- Returns:
Flat row-major
std::vector<double>of lengthprod(shape).
-
Tensor RandBool(const std::vector<int64_t> &shape, std::optional<uint64_t> seed = std::nullopt)#
Generates a deterministic
BOOLTensorof the requested shape by drawing approximately-normal values from :cpp:func:Randnand thresholding at 0. Mirrors the upstream ONNX test pattern(np.random.randn(...) > 0).astype(bool)used byonnx.backend.test.case.nodecases (e.g.And/Or/Xor).- Parameters:
shape – Output tensor shape; dimensions must be non-negative.
seed – Optional 64-bit seed.
std::nulloptselects the default seed.
- Throws:
std::invalid_argument – when any dimension is negative.
- Returns:
A
Tensorwithdata_type == BOOLwhosedatais a flat row-major buffer of one byte per element (0or1).
Variables
-
constexpr uint64_t kDefaultSeed = 0#
Default seed used when no explicit seed is provided.
-
std::pair<uint64_t, uint64_t> NextUint64(uint64_t state)#
-
namespace onnx_backend_test