# Path: dppy/utils.py
# def check_random_state(seed: object) -> np.random.RandomState:
#     """Turn seed into a np.random.RandomState instance
#     Parameters
#     ----------
#     seed : None | int | instance of RandomState
#         If seed is None, return the RandomState singleton used by np.random.
#         If seed is an int, return a new RandomState instance seeded with seed.
#         If seed is already a RandomState instance, return it.
#         Otherwise raise ValueError.
# 
#     Returns
#     -------
#     np.random.RandomState
# 
#     .. seealso::
# 
#         `Scikit learn source code <https://github.com/scikit-learn/scikit-learn/blob/7813f7efb/sklearn/utils/validation.py#L763>`_
#     """
#     if seed is None or seed is np.random:
#         return np.random.mtrand._rand
#     if isinstance(seed, (int, np.integer)):
#         return np.random.RandomState(seed)
#     if isinstance(seed, np.random.RandomState):
#         return seed
#     raise ValueError('%r cannot be used to seed a numpy.random.RandomState'
#                      ' instance' % seed)


import numpy as np
from scipy.optimize import newton, brentq
from scipy.special import logsumexp, airy
from dppy.utils import check_random_state

    def d2_f(x):
        return -(shape - 1.0) / (mode + x)**2 - d2_pol(x)

    a = newton(f, x0_a, fprime=d1_f, fprime2=d2_f)

    return np.array([b, a])  # b < 0 < a


def trunc_gaussian_sampler(b, mu, var, random_state=None):

    rng = check_random_state(random_state)

    it_max = int(1e7)

    for it in range(1, it_max + 1):
        X = rng.normal(loc=b, scale=np.sqrt(var))
        U = rng.rand()
        if (np.log(U) < -(b - mu) * (X - b) / var) and (X > b):
            break
    else:  # if no acceptation
        print('gen_gamma with alpha=1 not accepted\
                after {} iterations'.format(it))
        X = 1e-7

    return X, it


def gen_gamma_alpha_lt_1_sampler(shape, P, random_state=None):


# Path: dppy/utils.py
# def check_random_state(seed: object) -> np.random.RandomState:
#     """Turn seed into a np.random.RandomState instance
#     Parameters
#     ----------
#     seed : None | int | instance of RandomState
#         If seed is None, return the RandomState singleton used by np.random.
#         If seed is an int, return a new RandomState instance seeded with seed.
#         If seed is already a RandomState instance, return it.
#         Otherwise raise ValueError.
# 
#     Returns
#     -------
#     np.random.RandomState
# 
#     .. seealso::
# 
#         `Scikit learn source code <https://github.com/scikit-learn/scikit-learn/blob/7813f7efb/sklearn/utils/validation.py#L763>`_
#     """
#     if seed is None or seed is np.random:
#         return np.random.mtrand._rand
#     if isinstance(seed, (int, np.integer)):
#         return np.random.RandomState(seed)
#     if isinstance(seed, np.random.RandomState):
#         return seed
#     raise ValueError('%r cannot be used to seed a numpy.random.RandomState'
#                      ' instance' % seed)


# Path: dppy/beta_ensemble_polynomial_potential_core.py
import numpy as np
from scipy.optimize import newton, brentq
from scipy.special import logsumexp, airy
from dppy.utils import check_random_state


    def d2_f(x):
        return -(shape - 1.0) / (mode + x)**2 - d2_pol(x)

    a = newton(f, x0_a, fprime=d1_f, fprime2=d2_f)

    return np.array([b, a])  # b < 0 < a


def trunc_gaussian_sampler(b, mu, var, random_state=None):

    rng = check_random_state(random_state)

    it_max = int(1e7)

    for it in range(1, it_max + 1):
        X = rng.normal(loc=b, scale=np.sqrt(var))
        U = rng.rand()
        if (np.log(U) < -(b - mu) * (X - b) / var) and (X > b):
            break
    else:  # if no acceptation
        print('gen_gamma with alpha=1 not accepted\
                after {} iterations'.format(it))
        X = 1e-7

    return X, it


def gen_gamma_alpha_lt_1_sampler(shape, P, random_state=None):


    rng = check_random_state(random_state)