How to use the randomgen.PCG64 function in randomgen

To help you get started, we’ve selected a few randomgen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github firedrakeproject / firedrake / tests / randomfunctiongen / test_randomfunction.py View on Github external
def test_randomfunc_parallel_pcg64():

    mesh = UnitSquareMesh(10, 10)
    V0 = VectorFunctionSpace(mesh, "CG", 1)
    V1 = FunctionSpace(mesh, "CG", 1)
    V = V0 * V1

    seed = 123456789

    # original
    from mpi4py import MPI
    rg_base = randomgen.PCG64(seed=seed, inc=MPI.COMM_WORLD.rank).generator

    # Firedrake wrapper
    rg_wrap = PCG64(seed=seed).generator

    for i in range(1, 10):
        f = rg_wrap.beta(V, 0.3, 0.5)
        with f.dat.vec_ro as v:
            assert np.allclose(rg_base.beta(0.3, 0.5, size=(v.local_size,)), v.array[:])

    rg_base.seed(seed=12345678910, inc=MPI.COMM_WORLD.rank)
    rg_wrap.seed(seed=12345678910)
    for i in range(1, 10):
        f = rg_wrap.beta(V, 0.3, 0.5)
        with f.dat.vec_ro as v:
            assert np.allclose(rg_base.beta(0.3, 0.5, size=(v.local_size,)), v.array[:])
github bashtage / randomgen / doc / source / performance.py View on Github external
def __init__(self, *args, **kwargs):
        if "width" in kwargs:
            del kwargs["width"]
        super().__init__(*args, width=32, **kwargs)


class ThreeFry2x64(ThreeFry):
    canonical_repr = "ThreeFry(n=2, w=64)"

    def __init__(self, *args, **kwargs):
        if "number" in kwargs:
            del kwargs["number"]
        super().__init__(*args, number=2, **kwargs)


class PCG64DXSM128(PCG64):
    canonical_repr = 'PCG64(variant="dxsm-128")'

    def __init__(self, *args, **kwargs):
        if "variant" in kwargs:
            del kwargs["variant"]
        super().__init__(*args, variant="dxsm-128", **kwargs)


try:
    RDRAND()
    HAS_RDRND = True
except RuntimeError:
    HAS_RDRND = False

NUMBER = 100
REPEAT = 10
github bashtage / randomgen / doc / source / performance.py View on Github external
HAS_RDRND = False

NUMBER = 100
REPEAT = 10
SIZE = 25000
PRNGS = [
    ChaCha8,
    JSF32,
    Philox4x32,
    ThreeFry2x64,
    ThreeFry4x32,
    Philox2x64,
    DSFMT,
    MT64,
    MT19937,
    PCG64,
    PCG64DXSM128,
    PCG64DXSM,
    LXM,
    SFMT,
    AESCounter,
    ChaCha,
    Philox,
    ThreeFry,
    Xoshiro256,
    Xoshiro512,
    JSF,
    Romu,
    RomuTrio,
    HC128,
    SPECK128,
    SFC64,
github bashtage / randomgen / tools / configuration.py View on Github external
SFC64,
    SFMT,
    SPECK128,
    ThreeFry,
    Xoshiro256,
    Xoshiro512,
    Romu,
]
JUMPABLE = [bg for bg in ALL_BIT_GENS if hasattr(bg, "jumped")]

SPECIALS = {
    ChaCha: {"rounds": [8, 20]},
    JSF: {"seed_size": [1, 3]},
    SFC64: {"k": [1, 3394385948627484371, "weyl"]},
    LCG128Mix: {"output": ["upper"]},
    PCG64: {"variant": ["dxsm", "dxsm-128", "xsl-rr"]},
    Romu: {"variant": ["quad", "trio"]},
}
OUTPUT = defaultdict(lambda: 64)
OUTPUT.update({MT19937: 32, DSFMT: 32})
with open("templates/configuration.jinja") as tmpl:
    TEMPLATE = jinja2.Template(tmpl.read())

DSFMT_WRAPPER = """\

class Wrapper32:
    def __init__(self, seed, **kwargs):
        if isinstance(seed, rg.DSFMT):
            self._bit_gen = seed
        else:
            self._bit_gen = rg.DSFMT(seed)
github bashtage / randomgen / tools / practrand-driver.py View on Github external
import os
import sys

import numpy as np

import randomgen as rg

BUFFER_SIZE = 256 * 2 ** 20

DESCRIPTION = """
A driver that simplifies testing bit generators using PractRand.
"""

CONFIG = {
    rg.PCG32: {"output": 32, "seed": 64, "seed_size": 64},
    rg.PCG64: {"output": 64, "seed": 128, "seed_size": 128},
    rg.ThreeFry: {"output": 64, "seed": 256, "seed_size": 64},
    rg.Xoshiro256: {"output": 64, "seed": 256, "seed_size": 64},
    rg.Philox: {"output": 64, "seed": 256, "seed_size": 64},
    rg.SFMT: {"output": 64, "seed": 128, "seed_size": 32},
    rg.LXM: {"output": 64, "seed": 128, "seed_size": 32},
    rg.SFC64: {"output": 64, "seed": 128, "seed_size": 32},
    rg.AESCounter: {"output": 64, "seed": 128, "seed_size": 32},
}


def reorder_bytes(a):
    dtype = a.dtype
    assert dtype in (np.uint32, np.uint64)
    cols = 8 if dtype == np.uint64 else 4
    a = a.view(np.uint8).reshape((-1, cols))
    return a.ravel("F").view(dtype)