# Path: thejoker/logging.py
# class JokerHandler(StreamHandler):
# class JokerLogger(logging.getLoggerClass()):
#     def emit(self, record):
#     def _set_defaults(self):


import numpy as np
from .logging import logger
    from .samples import JokerSamples
                         "the prior samples cache file. You have, or have "
                         f"limited to, {n_total_samples} samples.")

    all_idx = np.arange(0, n_total_samples, 1)

    all_marg_lls = np.array([])
    start_idx = 0
    for i in range(maxiter):
        logger.log(1, f"iteration {i}, computing {n_process} likelihoods")

        marg_lls = marginal_ln_likelihood_inmem(
            joker_helper, prior_samples_batch[start_idx:start_idx + n_process])
        all_marg_lls = np.concatenate((all_marg_lls, marg_lls))

        if np.any(~np.isfinite(all_marg_lls)):
            return RuntimeError("There are NaN or Inf likelihood values in "
                                f"iteration step {i}!")
        elif len(all_marg_lls) == 0:
            return RuntimeError("No likelihood values returned in iteration "
                                f"step {i}")

        # get indices of samples that pass rejection step
        uu = random_state.uniform(size=len(all_marg_lls))
        aa = np.exp(all_marg_lls - all_marg_lls.max())
        good_samples_idx = np.where(aa > uu)[0]

        if len(good_samples_idx) == 0:
            raise RuntimeError("Failed to find any good samples!")

        n_good = len(good_samples_idx)

# Path: thejoker/logging.py
# class JokerHandler(StreamHandler):
# class JokerLogger(logging.getLoggerClass()):
#     def emit(self, record):
#     def _set_defaults(self):


# Path: thejoker/likelihood_helpers.py
import numpy as np
from .logging import logger
    from .samples import JokerSamples

                         "the prior samples cache file. You have, or have "
                         f"limited to, {n_total_samples} samples.")

    all_idx = np.arange(0, n_total_samples, 1)

    all_marg_lls = np.array([])
    start_idx = 0
    for i in range(maxiter):
        logger.log(1, f"iteration {i}, computing {n_process} likelihoods")

        marg_lls = marginal_ln_likelihood_inmem(
            joker_helper, prior_samples_batch[start_idx:start_idx + n_process])
        all_marg_lls = np.concatenate((all_marg_lls, marg_lls))

        if np.any(~np.isfinite(all_marg_lls)):
            return RuntimeError("There are NaN or Inf likelihood values in "
                                f"iteration step {i}!")
        elif len(all_marg_lls) == 0:
            return RuntimeError("No likelihood values returned in iteration "
                                f"step {i}")

        # get indices of samples that pass rejection step
        uu = random_state.uniform(size=len(all_marg_lls))
        aa = np.exp(all_marg_lls - all_marg_lls.max())
        good_samples_idx = np.where(aa > uu)[0]

        if len(good_samples_idx) == 0:
            raise RuntimeError("Failed to find any good samples!")

        n_good = len(good_samples_idx)

        logger.log(1, f"{n_good} good samples after rejection sampling")