def test_invalid(): with pytest.raises(TypeError, match="next_raw must be"): UserBitGenerator.from_cfunc("next_raw", "next_64", "next_32", "next_double", "state") with pytest.raises(TypeError, match="next_raw must be"): UserBitGenerator.from_ctypes("next_raw", "next_64", "next_32", "next_double", "state")
def test_no_setter_getter(split_mix): bgf = UserBitGenerator.from_cfunc( split_mix.next_raw, split_mix.next_64, split_mix.next_32, split_mix.next_double, split_mix.state_address, ) gen = Generator(bgf) gen.standard_normal(size=10) gen.standard_normal(size=10, dtype=np.float32) gen.integers(0, 2**63, dtype=np.uint64, size=10) with pytest.raises(NotImplementedError): bgf.state with pytest.raises(NotImplementedError): bgf.state = {"apple"} bgf = UserBitGenerator.from_cfunc( split_mix.next_raw, split_mix.next_64, split_mix.next_32, split_mix.next_double, split_mix.state_address, state_getter=split_mix.state_getter, ) assert isinstance(bgf.state, dict) with pytest.raises(NotImplementedError): bgf.state = {"apple"} bgf = UserBitGenerator.from_cfunc( split_mix.next_raw, split_mix.next_64, split_mix.next_32, split_mix.next_double, split_mix.state_address, state_setter=split_mix.state_setter, ) bgf.state = split_mix.state_getter()
def test_cfunc_smoke(split_mix): bgf = UserBitGenerator.from_cfunc( split_mix.next_raw, split_mix.next_64, split_mix.next_32, split_mix.next_double, split_mix.state_address, state_getter=split_mix.state_getter, state_setter=split_mix.state_setter, ) gen = Generator(bgf) gen.standard_normal(size=10) assert bgf.state == split_mix.state_getter() gen.standard_normal(dtype=np.float32) assert bgf.state == split_mix.state_getter() gen.integers(0, 2**63, dtype=np.uint64, size=10) assert bgf.state == split_mix.state_getter() old_state = bgf.state.copy() old_state["state"] = 1 bgf.state = old_state assert bgf.state == split_mix.state_getter()