text:
Ogbonnaya makes most of big chance
Chris Ogbonnaya looked around in the first quarter of Monday night's preseason opener against the New York Jets and noticed that he was the only healthy Texans running back.
He didn't blink. While the rest of the bruised running backs watched, Ogbonnaya made the most of his big opportunity.
"You just play hard because you never know what's going to happen," Ogbonnaya said. "Hopefully, we get D. Ward (Derrick Ward), and Arian (Foster) and Steve (Slaton) back and soon and we get back to work."
Ogbonnaya was signed to the Texans practice squad last September and faced long odds at the start of training camp. He was well behind Foster, the NFL's leading rusher last season, and veterans Ward and Slaton.
Even 2010 second-round pick Ben Tate, who missed all of last season with a broken leg, had an edge over the former University of Texas runner.
Foster, Slaton and Tate were sidelined by injuries before the game started. Ward left with a head injury in the first quarter, leaving Ogbonnaya to carry the running back load.
"He's a warrior," quarterback Matt Schaub said. "There weren't many guys to go in and play his position. He really strapped it on and played hard all night. He made some plays for us in the passing game as well as the running game."
Schaub also appreciated Ogbonnaya's blocking.
"He picked up a few blitzes after several big runs and to pick up a guy coming off the edge screaming, he did a great job stepping up for us quarterbacks," Schaub said. "He played really big tonight."
Ogbonnaya ran big from the start. He finished with 37 yards on 17 carries and a one-yard touchdown run. He caught seven passes for 67 yards and had a touchdown catch.
It was quite a performance for a guy who started out at the bottom of the depth chart. He hadn't played as much since his rookie year with the Rams.
"Arizona my rookie year when I was playing for the Rams," he said. "It's a great opportunity here. Some guys go down and some guys have to step up and that's my job right now. Hopefully, I can do enough to make this team.
"You've got to play tough. This offense is a downhill, wide-zone scheme. I try my best to do that and get north and get up field when I have the opportunity."
Ogbonnaya didn't have time to get tired as his long even progressed.
"I'd say I got stronger," Ogbonnaya said. "It's a grind. It's like training camp and I go to practice every day with that mindset that I have to do something to make this team and to make this team better. I hadn't been in the end zone since I've been in the NFL."
Ogbonnaya gained 50 yards on 11 carries with the Rams in 2009. He signed with the Texans last September and had been stuck on the practice squad.
Ogbonnaya's receiving was a big factor.
"I've always taken pride in that," Ogbonnaya said. "That was one of my big jobs at Texas, being a third-down back and just as a receiver coming out of high school, it is important to me. I anticipated Derrick not playing as much. You've got to go and keep plugging."
Ogbonnaya rushed 597 yards on 140 carries and eight touchdowns at Texas. He added 75 passes for 792 yards for three touchdowns.
Quarterback Matt Leinart also got a big chance to play for the first time in a year. He appreciated having Ogbonnaya's help.
"Chris had a big game tonight," Leinart said. "He took the load out there and showed us what he's made of. We all knew he was a great back, and he's getting a chance to show what he can do.
"It's tough, you got to go more one-back stuff. It makes it harder to call plays in certain personnel groups, but we got through it and T.J. (Yates) had a great drive at the end to win the game. Everybody stepped up."
Yates, the rookie quarterback from North Carolina, completed a 27-yard pass to Lestar Jean and then handed off to Ogbonnaya for the one-yard winning touchdown with 1:53 to play.
"We knew going into the game we were short on running backs, and when D. Ward got hurt, Chris stepped up," Yates said. "He's been doing that all camp for us. He gets a chance and he steps in there and did a great job."
EDITOR'S NOTE: Michael A. Lutz worked for The Associated Press for 38 years covering news and sports in Louisville, Ky. Dallas and Houston. Most of that time was spent in Houston covering the Oilers, Astros, Texans and other college and pro sports.
J.J. Watt named 2017 Walter Payton Man of the Year | Moments That Make You Smile Champion
Houston Texans defensive end J.J. Watt was named the 2017 Walter Payton NFL Man of the Year.
Bob, Janice McNair help students pay for college
Bob and his wife Janice McNair awarded over $1.1 million to graduating seniors in Rutherford County, North Carolina.
Breakfast: Watt ranked on ESPN World Fame 100
DE J.J. Watt was ranked 72nd on ESPN's World Fame 100 list.


EGL: How Do We Complete The Chartfield Configuration Integration From Financials To Other Environments?
Qn1:Looking for more information for the FSCM_FS_CONFIG Service Operation.
Qn2:We have re-labeled 'Chartfield1' to 'Component' in our Financials environment, then ran the Chartfield Configuration Process. The IB Service Op FSCM_CF_CONFIG was active and routed to Campus Solutions.
If I go to navigation "Setup HRMS > Common Definitions > Chartfield Configuration > Standard Configuration", I can see the chartfield labeled as "Component" as I would expect.
However if I navigate to "Set Up SACR > Product Related > Student Financials > General Ledger Interface > SpeedTypes", I still see 'Chartfield1'.
Should that not have relabeled? It's also still showing when we go to where the Cashiers pull up a SpeedType where they post payments for students.


Well, Lance did it: 2:59:36! Absolutely amazing considering that this was his first marathon and he did not even do a single training run longer than 16 miles. However, it did not come without pain.
It seems that even for cycling's Superman—who is probably in the top 99.99 percentile in terms of VO2 max, resting heart rate, lung capacity, etc.—the marathon was no cakewalk (unless the caked was laced with lactic acid). It appeared he was beginning to slow after Mile 20.
"That was without a doubt the hardest physical thing I've ever done," Lance reported.
Oh, he'll change his mind eventually all right. Just ask any other marathoner.
I ran New York on Sunday. The buzz surrounding Lance was huge. As you know this was also Dean Karnazes last marathon in his 50 series – he also ran a 3.00. Incredible achievement.
BTW – the blogs are great. I don't know how you have done it but congrats on getting out of the corporate race and into a better work/life balance in Colorado.


text:
University Medical Center: Traveling nurse's story of neglect of COVID-19 patients refuted
Cristina Carreon
Special to the El Paso Times
University Medical Center of El Paso says an investigation has refuted allegations of negligence toward COVID-19 patients recently posted on social media by a traveling nurse.
Traveling nurse Lawanna Rivers, who was at UMC for two and a half weeks this fall, said she experienced emotional scarring while caring for COVID-19 patients at the hospital, alleging doctors did not encourage staff to exhaust all options to treat the patients and even resisted seeing the patients.
The Texas Department of Health and Human Services visited UMC unannounced to investigate whether Rivers' experiences could be substantiated. The department could be not be reached for comment.
However, UMC said in a news release that a survey and inspection by the department found no evidence of the issues raised by Rivers.
"Unfortunately, the views expressed by this travel nurse who worked briefly at our hospital caused many people in our community and media to rush to judgement about the accuracy of what was being expressed," Ryan Mielke, UMC director of public affairs, said in the news release Monday.
The survey included interviews with staff, including permanent and travel nurses, as well as a review of records and a review of UMC's COVID-19 care unit.
"No violations (were) found. Additionally, there was zero confirmation of comments made by the social media post that had generated much media attention," the release states.
The Facebook Live video, which was over 50 minutes long, still was up Tuesday morning. Rivers was soft-spoken and appeared in the video with a mask hanging over her chin, saying she was trying to quarantine after recently getting tested for the virus.
"This last assignment was horrific for me," Rivers says in the video. "For some reason, the doctors there did not aggressively treat those COVID patients as they should have, as I have experienced before."
More:On the front lines of a war, one COVID-19 nurse confronts life and death in the pandemic
More:COVID-19 crisis: El Paso County seeks workers to move 200-plus bodies at morgue, trailers
More:Texas National Guard to provide aid to El Paso morgues during COVID-19 crisis
More:El Paso County Jail inmates help with overflow of bodies awaiting autopsy amid pandemic
Rivers was told by staff that the doctors were not aggressive before the pandemic, she said in the video.
"So, I saw a lot of people die that I feel like shouldn't have died," Rivers says. "That assignment there broke me."
Doctors wrote progress notes about patients, but Rivers said she never saw doctors interact closely with COVID-19 patients and when she asked one doctor to assist a patient who was bleeding profusely, the doctor refused.
"It's OK for us to sit in there for 12 hours, but it ain't OK to come in there for a few minutes to assess these patients?" she says.
Rivers says she was assigned to an area of the hospital designated as the "pit" with three other nurses to treat eight COVID-19 positive patients who were on ventilators. She said she did not see a doctor come into the area to treat those COVID-19 patients directly.
Mielke said in an email Tuesday that the "majority of the floors at UMC have been dedicated to treatment and care of COVID-19 patients."
The open bay areas described in Rivers' video were areas where COVID-19 patients were receiving "an elevated level of care," according to the UMC release.
"These patients are the most serious cases of COVID-19 and require 24/7 immediate, visual observation and attention," the release states.
On her first day of orientation, Rivers said she was told patients who come out of the area with COVID-19 patients only come out in body bags.
Rivers said she and other nursing staff were discouraged from performing more aggressive CPR to reduce their risk of exposure to the virus, and that she was discouraged from performing more than six minutes of CPR on COVID patients.
"Y'all, I'm used to running codes for 45 minutes to hours," Rivers said. "If there's no improvement, they call it, so we had yet to work on somebody, perform CPR on somebody that actually made it."
Rivers did not respond to a Nov. 16 Facebook Messenger request for comment.
According to the American Red Cross, although there is no specific data about COVID-19 transmission when performing CPR, "it is reasonable to conclude that chest compressions have the potential to generate respiratory droplets or aerosols and close contact needed for some aspects of first aid may have risk of transmission."
Rivers says because the hospital morgue was out of room, a deceased COVID-19 patient was brought into the "pit" area in a body bag to be stored, and she later mentions refrigerated trucks being used to store the hospital's dead due to morgue overflow.
However, in his email Tuesday, Mielke denies that patients who died from COVID-19 were stored near living patients.
Initially, El Paso County detention inmates moved these bodies into the refrigerated morgue trucks in early November. Last week, 36 Texas National Guard personnel were assigned to assist El Paso morgues with moving bodies and the county was hiring temporary workers to help as well.
El Paso emerged as a major hot spot in Texas for the virus this fall, with 37% of hospitalizations in the county designated as COVID-19 related as of Wednesday. There were eight new deaths and 897 patients hospitalized as of Wednesday, including 306 in intensive care and 216 on ventilators.
In regard to staffing, ventilators and personal protective equipment, Mielke said in his email: "Similar to all major hospitals in El Paso, UMC has been caring for a significant amount of COVID-19 inpatients resulting from this fall's surge. We are now more than 30 percent below our peak numbers reached in early November. Thanks to early planning last spring, from logistics to PPE supplies to preparing for additional staff, we have managed the last surge successfully. That continues to this day."
He added: "We have enough equipment, including ventilators, and resources to care for our patients at this time. It is important to note, however, that we and our other two major hospital systems in El Paso received tremendous support from the US military, El Paso County, FEMA, the City of El Paso and the State of Texas. This was a true example of planning, coordination and cooperation that made our response to the recent surge more effective."
UMC's news release said: "UMC is the most highly recognized and certified hospital in the El Paso region. The false assumptions made about our hospital were hurtful to the thousands of men and women, together with our partners from Texas Tech Physicians of El Paso, who have worked tirelessly to heal and care for each patient, with great compassion and the highest level of professional medical care during this pandemic."
In his email, Mielke said: "UMC has and will always care for each patient with one goal in mind: to heal. ... We are El Paso — and most of all, we have been El Paso's main hospital for more than a century."

redpajama_set_name: RedPajamaCommonCrawl


text:
"""
Implement the random and np.random module functions.
"""

import math
import random

import numpy as np

from llvmlite import ir

from numba.core.cgutils import is_nonelike
from numba.core.extending import intrinsic, overload, register_jitable
from numba.core.imputils import (Registry, impl_ret_untracked,
                                    impl_ret_new_ref)
from numba.core.typing import signature
from numba.core import types, utils, cgutils
from numba.np import arrayobj
from numba.core.errors import NumbaTypeError

POST_PY38 = utils.PYVERSION >= (3, 8)

registry = Registry('randomimpl')
lower = registry.lower

int32_t = ir.IntType(32)
int64_t = ir.IntType(64)
def const_int(x):
    return ir.Constant(int32_t, x)
double = ir.DoubleType()

N = 624
N_const = ir.Constant(int32_t, N)

# This is the same struct as rnd_state_t in _random.c.
rnd_state_t = ir.LiteralStructType([
    # index
    int32_t,
    # mt[N]
    ir.ArrayType(int32_t, N),
    # has_gauss
    int32_t,
    # gauss
    double,
    # is_initialized
    int32_t,
    ])
rnd_state_ptr_t = ir.PointerType(rnd_state_t)

def get_state_ptr(context, builder, name):
    """
    Get a pointer to the given thread-local random state
    (depending on *name*: "py" or "np").
    If the state isn't initialized, it is lazily initialized with
    system entropy.
    """
    assert name in ('py', 'np', 'internal')
    func_name = "numba_get_%s_random_state" % name
    fnty = ir.FunctionType(rnd_state_ptr_t, ())
    fn = cgutils.get_or_insert_function(builder.module, fnty, func_name)
    # These two attributes allow LLVM to hoist the function call
    # outside of loops.
    fn.attributes.add('readnone')
    fn.attributes.add('nounwind')
    return builder.call(fn, ())

def get_py_state_ptr(context, builder):
    """
    Get a pointer to the thread-local Python random state.
    """
    return get_state_ptr(context, builder, 'py')

def get_np_state_ptr(context, builder):
    """
    Get a pointer to the thread-local Numpy random state.
    """
    return get_state_ptr(context, builder, 'np')

def get_internal_state_ptr(context, builder):
    """
    Get a pointer to the thread-local internal random state.
    """
    return get_state_ptr(context, builder, 'internal')

# Accessors
def get_index_ptr(builder, state_ptr):
    return cgutils.gep_inbounds(builder, state_ptr, 0, 0)

def get_array_ptr(builder, state_ptr):
    return cgutils.gep_inbounds(builder, state_ptr, 0, 1)

def get_has_gauss_ptr(builder, state_ptr):
    return cgutils.gep_inbounds(builder, state_ptr, 0, 2)

def get_gauss_ptr(builder, state_ptr):
    return cgutils.gep_inbounds(builder, state_ptr, 0, 3)

def get_rnd_shuffle(builder):
    """
    Get the internal function to shuffle the MT taste.
    """
    fnty = ir.FunctionType(ir.VoidType(), (rnd_state_ptr_t,))
    fn = cgutils.get_or_insert_function(builder.function.module, fnty,
                                        "numba_rnd_shuffle")
    fn.args[0].add_attribute("nocapture")
    return fn

def get_next_int32(context, builder, state_ptr):
    """
    Get the next int32 generated by the PRNG at *state_ptr*.
    """
    idxptr = get_index_ptr(builder, state_ptr)
    idx = builder.load(idxptr)
    need_reshuffle = builder.icmp_unsigned('>=', idx, N_const)
    with cgutils.if_unlikely(builder, need_reshuffle):
        fn = get_rnd_shuffle(builder)
        builder.call(fn, (state_ptr,))
        builder.store(const_int(0), idxptr)
    idx = builder.load(idxptr)
    array_ptr = get_array_ptr(builder, state_ptr)
    y = builder.load(cgutils.gep_inbounds(builder, array_ptr, 0, idx))
    idx = builder.add(idx, const_int(1))
    builder.store(idx, idxptr)
    # Tempering
    y = builder.xor(y, builder.lshr(y, const_int(11)))
    y = builder.xor(y, builder.and_(builder.shl(y, const_int(7)),
                                    const_int(0x9d2c5680)))
    y = builder.xor(y, builder.and_(builder.shl(y, const_int(15)),
                                    const_int(0xefc60000)))
    y = builder.xor(y, builder.lshr(y, const_int(18)))
    return y

def get_next_double(context, builder, state_ptr):
    """
    Get the next double generated by the PRNG at *state_ptr*.
    """
    # a = rk_random(state) >> 5, b = rk_random(state) >> 6;
    a = builder.lshr(get_next_int32(context, builder, state_ptr), const_int(5))
    b = builder.lshr(get_next_int32(context, builder, state_ptr), const_int(6))

    # return (a * 67108864.0 + b) / 9007199254740992.0;
    a = builder.uitofp(a, double)
    b = builder.uitofp(b, double)
    return builder.fdiv(
        builder.fadd(b, builder.fmul(a, ir.Constant(double, 67108864.0))),
        ir.Constant(double, 9007199254740992.0))

def get_next_int(context, builder, state_ptr, nbits, is_numpy):
    """
    Get the next integer with width *nbits*.
    """
    c32 = ir.Constant(nbits.type, 32)
    def get_shifted_int(nbits):
        shift = builder.sub(c32, nbits)
        y = get_next_int32(context, builder, state_ptr)

        # This truncation/extension is safe because 0 < nbits <= 64
        if nbits.type.width < y.type.width:
            shift = builder.zext(shift, y.type)
        elif nbits.type.width > y.type.width:
            shift = builder.trunc(shift, y.type)

        if is_numpy:
            # Use the last N bits, to match np.random
            mask = builder.not_(ir.Constant(y.type, 0))
            mask = builder.lshr(mask, shift)
            return builder.and_(y, mask)
        else:
            # Use the first N bits, to match CPython random
            return builder.lshr(y, shift)

    ret = cgutils.alloca_once_value(builder, ir.Constant(int64_t, 0))

    is_32b = builder.icmp_unsigned('<=', nbits, c32)
    with builder.if_else(is_32b) as (ifsmall, iflarge):
        with ifsmall:
            low = get_shifted_int(nbits)
            builder.store(builder.zext(low, int64_t), ret)
        with iflarge:
            # XXX This assumes nbits <= 64
            if is_numpy:
                # Get the high bits first to match np.random
                high = get_shifted_int(builder.sub(nbits, c32))
            low = get_next_int32(context, builder, state_ptr)
            if not is_numpy:
                # Get the high bits second to match CPython random
                high = get_shifted_int(builder.sub(nbits, c32))
            total = builder.add(
                builder.zext(low, int64_t),
                builder.shl(builder.zext(high, int64_t),
                            ir.Constant(int64_t, 32)))
            builder.store(total, ret)

    return builder.load(ret)

@overload(random.seed)
def seed_impl(seed):
    if isinstance(seed, types.Integer):
        return _seed_impl('py')

@overload(np.random.seed)
def seed_impl(seed):
    if isinstance(seed, types.Integer):
        return _seed_impl('np')

def _seed_impl(state_type):
    @intrinsic
    def _impl(typingcontext, seed):
        def codegen(context, builder, sig, args):
            seed_value, = args
            fnty = ir.FunctionType(ir.VoidType(), (rnd_state_ptr_t, int32_t))
            fn = cgutils.get_or_insert_function(builder.function.module, fnty,
                                                'numba_rnd_init')
            builder.call(fn, (get_state_ptr(context, builder, state_type),
                              seed_value))
            return context.get_constant(types.none, None)
        return signature(types.void, types.uint32), codegen
    return lambda seed: _impl(seed)

@overload(random.random)
def random_impl():
    @intrinsic
    def _impl(typingcontext):
        def codegen(context, builder, sig, args):
            state_ptr = get_state_ptr(context, builder, "py")
            return get_next_double(context, builder, state_ptr)
        return signature(types.double), codegen
    return lambda: _impl()

@overload(np.random.random)
@overload(np.random.random_sample)
@overload(np.random.sample)
@overload(np.random.ranf)
def random_impl0():
    @intrinsic
    def _impl(typingcontext):
        def codegen(context, builder, sig, args):
            state_ptr = get_state_ptr(context, builder, "np")
            return get_next_double(context, builder, state_ptr)
        return signature(types.float64), codegen
    return lambda: _impl()

@overload(np.random.random)
@overload(np.random.random_sample)
@overload(np.random.sample)
@overload(np.random.ranf)
def random_impl1(size):
    if is_nonelike(size):
        return lambda size: np.random.random()
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                           and isinstance(size.dtype,
                                                          types.Integer)):
        def _impl(size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.random()
            return out
        return _impl

@overload(random.gauss)
@overload(random.normalvariate)
def gauss_impl(loc, scale):
    if isinstance(loc, (types.Float, types.Integer)) and isinstance(
            scale, (types.Float, types.Integer)):
        @intrinsic
        def _impl(typingcontext, loc, scale):
            loc_preprocessor = _double_preprocessor(loc)
            scale_preprocessor = _double_preprocessor(scale)
            return signature(types.float64, loc, scale),\
                   _gauss_impl("py", loc_preprocessor, scale_preprocessor)
        return lambda loc, scale: _impl(loc, scale)

@overload(np.random.standard_normal)
@overload(np.random.normal)
def np_gauss_impl0():
    return lambda: np.random.normal(0.0, 1.0)

@overload(np.random.normal)
def np_gauss_impl1(loc):
    if isinstance(loc, (types.Float, types.Integer)):
        return lambda loc: np.random.normal(loc, 1.0)

@overload(np.random.normal)
def np_gauss_impl2(loc, scale):
    if isinstance(loc, (types.Float, types.Integer)) and isinstance(
            scale, (types.Float, types.Integer)):
        @intrinsic
        def _impl(typingcontext, loc, scale):
            loc_preprocessor = _double_preprocessor(loc)
            scale_preprocessor = _double_preprocessor(scale)
            return signature(types.float64, loc, scale),\
                   _gauss_impl("np", loc_preprocessor, scale_preprocessor)
        return lambda loc, scale: _impl(loc, scale)

@overload(np.random.standard_normal)
def standard_normal_impl1(size):
    if is_nonelike(size):
        return lambda size: np.random.standard_normal()
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                           isinstance(size.dtype,
                                                      types.Integer)):
        def _impl(size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.standard_normal()
            return out
        return _impl

@overload(np.random.normal)
def np_gauss_impl3(loc, scale, size):
    if (isinstance(loc, (types.Float, types.Integer)) and isinstance(
            scale, (types.Float, types.Integer)) and
       is_nonelike(size)):
        return lambda loc, scale, size: np.random.normal(loc, scale)
    if (isinstance(loc, (types.Float, types.Integer)) and isinstance(
            scale, (types.Float, types.Integer)) and
       (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                            and isinstance(size.dtype,
                                                           types.Integer)))):
        def _impl(loc, scale, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.normal(loc, scale)
            return out
        return _impl

def _gauss_pair_impl(_random):
    def compute_gauss_pair():
        """
        Compute a pair of numbers on the normal distribution.
        """
        while True:
            x1 = 2.0 * _random() - 1.0
            x2 = 2.0 * _random() - 1.0
            r2 = x1*x1 + x2*x2
            if r2 < 1.0 and r2 != 0.0:
                break

        # Box-Muller transform
        f = math.sqrt(-2.0 * math.log(r2) / r2)
        return f * x1, f * x2
    return compute_gauss_pair

def _gauss_impl(state, loc_preprocessor, scale_preprocessor):
    def _impl(context, builder, sig, args):
        # The type for all computations (either float or double)
        ty = sig.return_type
        llty = context.get_data_type(ty)
        _random = {"py": random.random,
                   "np": np.random.random}[state]

        state_ptr = get_state_ptr(context, builder, state)

        ret = cgutils.alloca_once(builder, llty, name="result")

        gauss_ptr = get_gauss_ptr(builder, state_ptr)
        has_gauss_ptr = get_has_gauss_ptr(builder, state_ptr)
        has_gauss = cgutils.is_true(builder, builder.load(has_gauss_ptr))
        with builder.if_else(has_gauss) as (then, otherwise):
            with then:
                # if has_gauss: return it
                builder.store(builder.load(gauss_ptr), ret)
                builder.store(const_int(0), has_gauss_ptr)
            with otherwise:
                # if not has_gauss: compute a pair of numbers using the Box-Muller
                # transform; keep one and return the other
                pair = context.compile_internal(builder,
                                                _gauss_pair_impl(_random),
                                                signature(types.UniTuple(ty, 2)),
                                                ())

                first, second = cgutils.unpack_tuple(builder, pair, 2)
                builder.store(first, gauss_ptr)
                builder.store(second, ret)
                builder.store(const_int(1), has_gauss_ptr)

        mu, sigma = args
        return builder.fadd(loc_preprocessor(builder, mu),
                            builder.fmul(scale_preprocessor(builder, sigma),
                                         builder.load(ret)))
    return _impl

def _double_preprocessor(value):
    ty = ir.types.DoubleType()

    if isinstance(value, types.Integer):
        if value.signed:
            return lambda builder, v: builder.sitofp(v, ty)
        else:
            return lambda builder, v: builder.uitofp(v, ty)
    elif isinstance(value, types.Float):
        if value.bitwidth != 64:
            return lambda builder, v: builder.fpext(v, ty)
        else:
            return lambda _builder, v: v
    else:
        raise TypeError("Cannot convert {} to floating point type" % value)

@overload(random.getrandbits)
def getrandbits_impl(k):
    if isinstance(k, types.Integer):
        @intrinsic
        def _impl(typingcontext, k):
            def codegen(context, builder, sig, args):
                nbits, = args

                too_large = builder.icmp_unsigned(">=", nbits, const_int(65))
                too_small = builder.icmp_unsigned("==", nbits, const_int(0))
                with cgutils.if_unlikely(builder, builder.or_(too_large,
                                                              too_small)):
                    msg = "getrandbits() limited to 64 bits"
                    context.call_conv.return_user_exc(builder, OverflowError,
                                                      (msg,))
                state_ptr = get_state_ptr(context, builder, "py")
                return get_next_int(context, builder, state_ptr, nbits, False)
            return signature(types.uint64, k), codegen
        return lambda k: _impl(k)

def _randrange_impl(context, builder, start, stop, step, ty, signed, state):
    state_ptr = get_state_ptr(context, builder, state)
    zero = ir.Constant(ty, 0)
    one = ir.Constant(ty, 1)
    nptr = cgutils.alloca_once(builder, ty, name="n")

    # n = stop - start
    builder.store(builder.sub(stop, start), nptr)

    with builder.if_then(builder.icmp_signed('<', step, zero)):
        # n = (n + step + 1) // step
        w = builder.add(builder.add(builder.load(nptr), step), one)
        n = builder.sdiv(w, step)
        builder.store(n, nptr)
    with builder.if_then(builder.icmp_signed('>', step, one)):
        # n = (n + step - 1) // step
        w = builder.sub(builder.add(builder.load(nptr), step), one)
        n = builder.sdiv(w, step)
        builder.store(n, nptr)

    n = builder.load(nptr)
    with cgutils.if_unlikely(builder, builder.icmp_signed('<=', n, zero)):
        # n <= 0
        msg = "empty range for randrange()"
        context.call_conv.return_user_exc(builder, ValueError, (msg,))

    fnty = ir.FunctionType(ty, [ty, cgutils.true_bit.type])
    fn = cgutils.get_or_insert_function(builder.function.module, fnty,
                                        "llvm.ctlz.%s" % ty)
    # Since the upper bound is exclusive, we need to subtract one before
    # calculating the number of bits. This leads to a special case when
    # n == 1; there's only one possible result, so we don't need bits from
    # the PRNG. This case is handled separately towards the end of this
    # function. CPython's implementation is simpler and just runs another
    # iteration of the while loop when the resulting number is too large
    # instead of subtracting one, to avoid needing to handle a special
    # case. Thus, we only perform this subtraction for the NumPy case.
    nm1 = builder.sub(n, one) if state == "np" else n
    nbits = builder.trunc(builder.call(fn, [nm1, cgutils.true_bit]), int32_t)
    nbits = builder.sub(ir.Constant(int32_t, ty.width), nbits)

    rptr = cgutils.alloca_once(builder, ty, name="r")

    def get_num():
        bbwhile = builder.append_basic_block("while")
        bbend = builder.append_basic_block("while.end")
        builder.branch(bbwhile)

        builder.position_at_end(bbwhile)
        r = get_next_int(context, builder, state_ptr, nbits, state == "np")
        r = builder.trunc(r, ty)
        too_large = builder.icmp_signed('>=', r, n)
        builder.cbranch(too_large, bbwhile, bbend)

        builder.position_at_end(bbend)
        builder.store(r, rptr)

    if state == "np":
        # Handle n == 1 case, per previous comment.
        with builder.if_else(builder.icmp_signed('==', n, one)) as (is_one, is_not_one):
            with is_one:
                builder.store(zero, rptr)
            with is_not_one:
                get_num()
    else:
        get_num()

    return builder.add(start, builder.mul(builder.load(rptr), step))

@overload(random.randrange)
def randrange_impl_1(stop):
    if isinstance(stop, types.Integer):
        return lambda stop: random.randrange(0, stop, 1)

@overload(random.randrange)
def randrange_impl_2(start, stop):
    if isinstance(start, types.Integer) and isinstance(stop, types.Integer):
        return lambda start, stop: random.randrange(start, stop, 1)

def _randrange_preprocessor(bitwidth, ty):
    if ty.bitwidth != bitwidth:
        return (ir.IRBuilder.sext if ty.signed
                else ir.IRBuilder.zext)
    else:
        return lambda _builder, v, _ty: v

@overload(random.randrange)
def randrange_impl_3(start, stop, step):
    if (isinstance(start, types.Integer) and isinstance(stop, types.Integer) and
       isinstance(step, types.Integer)):
        signed = max(start.signed, stop.signed, step.signed)
        bitwidth = max(start.bitwidth, stop.bitwidth, step.bitwidth)
        int_ty = types.Integer.from_bitwidth(bitwidth, signed)
        llvm_type = ir.IntType(bitwidth)

        start_preprocessor = _randrange_preprocessor(bitwidth, start)
        stop_preprocessor = _randrange_preprocessor(bitwidth, stop)
        step_preprocessor = _randrange_preprocessor(bitwidth, step)

        @intrinsic
        def _impl(typingcontext, start, stop, step):
            def codegen(context, builder, sig, args):
                start, stop, step = args

                start = start_preprocessor(builder, start, llvm_type)
                stop = stop_preprocessor(builder, stop, llvm_type)
                step = step_preprocessor(builder, step, llvm_type)
                return _randrange_impl(context, builder, start, stop, step,
                                       llvm_type, signed, 'py')
            return signature(int_ty, start, stop, step), codegen
        return lambda start, stop, step: _impl(start, stop, step)

@overload(random.randint)
def randint_impl_1(start, stop):
    if isinstance(start, types.Integer) and isinstance(stop, types.Integer):
        return lambda start, stop: random.randrange(start, stop + 1, 1)

@overload(np.random.randint)
def np_randint_impl_1(high):
    if isinstance(high, types.Integer):
        return lambda high: np.random.randint(0, high)

@overload(np.random.randint)
def np_randint_impl_2(low, high):
    if isinstance(low, types.Integer) and isinstance(high, types.Integer):
        signed = max(low.signed, high.signed)
        bitwidth = max(low.bitwidth, high.bitwidth)
        int_ty = types.Integer.from_bitwidth(bitwidth, signed)
        llvm_type = ir.IntType(bitwidth)

        start_preprocessor = _randrange_preprocessor(bitwidth, low)
        stop_preprocessor = _randrange_preprocessor(bitwidth, high)

        @intrinsic
        def _impl(typingcontext, low, high):
            def codegen(context, builder, sig, args):
                start, stop = args

                start = start_preprocessor(builder, start, llvm_type)
                stop = stop_preprocessor(builder, stop, llvm_type)
                step = ir.Constant(llvm_type, 1)
                return _randrange_impl(context, builder, start, stop, step,
                                       llvm_type, signed, 'np')
            return signature(int_ty, low, high), codegen
        return lambda low, high: _impl(low, high)

@overload(np.random.randint)
def np_randint_impl_3(low, high, size):
    if (isinstance(low, types.Integer) and isinstance(high, types.Integer) and
       is_nonelike(size)):
        return lambda low, high, size: np.random.randint(low, high)
    if (isinstance(low, types.Integer) and isinstance(high, types.Integer) and
       (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                            and isinstance(size.dtype,
                                                           types.Integer)))):
        bitwidth = max(low.bitwidth, high.bitwidth)
        result_type = getattr(np, f'int{bitwidth}')

        def _impl(low, high, size):
            out = np.empty(size, dtype=result_type)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.randint(low, high)
            return out
        return _impl

@overload(random.uniform)
def uniform_impl0():
    return lambda: random.uniform(0.0, 1.0)

@overload(np.random.uniform)
def np_uniform_impl0():
    return lambda: np.random.uniform(0.0, 1.0)

@overload(random.uniform)
def uniform_impl1(low):
    if isinstance(low, (types.Float, types.Integer)):
        return lambda low: random.uniform(low, 1.0)

@overload(np.random.uniform)
def np_uniform_impl1(low):
    if isinstance(low, (types.Float, types.Integer)):
        return lambda low: np.random.uniform(low, 1.0)

@overload(random.uniform)
def uniform_impl2(low, high):
    if isinstance(low, (types.Float, types.Integer)) and isinstance(
            high, (types.Float, types.Integer)):
        @intrinsic
        def _impl(typingcontext, low, high):
            low_preprocessor = _double_preprocessor(low)
            high_preprocessor = _double_preprocessor(high)
            return signature(types.float64, low, high), uniform_impl(
                'py', low_preprocessor, high_preprocessor)
        return lambda low, high: _impl(low, high)

@overload(np.random.uniform)
def np_uniform_impl2(low, high):
    if isinstance(low, (types.Float, types.Integer)) and isinstance(
            high, (types.Float, types.Integer)):
        @intrinsic
        def _impl(typingcontext, low, high):
            low_preprocessor = _double_preprocessor(low)
            high_preprocessor = _double_preprocessor(high)
            return signature(types.float64, low, high), uniform_impl(
                'np', low_preprocessor, high_preprocessor)
        return lambda low, high: _impl(low, high)

def uniform_impl(state, a_preprocessor, b_preprocessor):
    def impl(context, builder, sig, args):
        state_ptr = get_state_ptr(context, builder, state)
        a, b = args
        a = a_preprocessor(builder, a)
        b = b_preprocessor(builder, b)
        width = builder.fsub(b, a)
        r = get_next_double(context, builder, state_ptr)
        return builder.fadd(a, builder.fmul(width, r))
    return impl

@overload(np.random.uniform)
def np_uniform_impl3(low, high, size):
    if (isinstance(low, (types.Float, types.Integer)) and isinstance(
            high, (types.Float, types.Integer)) and
       is_nonelike(size)):
        return lambda low, high, size: np.random.uniform(low, high)
    if (isinstance(low, (types.Float, types.Integer)) and isinstance(
            high, (types.Float, types.Integer)) and
       (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                            and isinstance(size.dtype,
                                                           types.Integer)))):
        def _impl(low, high, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.uniform(low, high)
            return out
        return _impl

@overload(random.triangular)
def triangular_impl_2(low, high):
    def _impl(low, high):
        u = random.random()
        c = 0.5
        if u > c:
            u = 1.0 - u
            low, high = high, low
        return low + (high - low) * math.sqrt(u * c)

    if isinstance(low, (types.Float, types.Integer)) and isinstance(
            high, (types.Float, types.Integer)):
        return _impl

@overload(random.triangular)
def triangular_impl_3(low, high, mode):
    if (isinstance(low, (types.Float, types.Integer)) and isinstance(
            high, (types.Float, types.Integer)) and
       isinstance(mode, (types.Float, types.Integer))):
        def _impl(low, high, mode):
            if high == low:
                return low
            u = random.random()
            c = (mode - low) / (high - low)
            if u > c:
                u = 1.0 - u
                c = 1.0 - c
                low, high = high, low
            return low + (high - low) * math.sqrt(u * c)

        return _impl

@overload(np.random.triangular)
def triangular_impl_3(low, mode, high):
    if (isinstance(low, (types.Float, types.Integer)) and isinstance(
            mode, (types.Float, types.Integer)) and
            isinstance(high, (types.Float, types.Integer))):
        def _impl(low, mode, high):
            if high == low:
                return low
            u = np.random.random()
            c = (mode - low) / (high - low)
            if u > c:
                u = 1.0 - u
                c = 1.0 - c
                low, high = high, low
            return low + (high - low) * math.sqrt(u * c)

        return _impl

@overload(np.random.triangular)
def triangular_impl(low, high, mode, size):
    if is_nonelike(size):
        return lambda low, high, mode, size: np.random.triangular(low, high,
                                                                  mode)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                            isinstance(size.dtype,
                                                       types.Integer))):
        def _impl(low, high, mode, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.triangular(low, high, mode)
            return out
        return _impl

@overload(random.gammavariate)
def gammavariate_impl(alpha, beta):
    if isinstance(alpha, (types.Float, types.Integer)) and isinstance(
            beta, (types.Float, types.Integer)):
        return _gammavariate_impl(random.random)

@overload(np.random.standard_gamma)
@overload(np.random.gamma)
def gammavariate_impl(alpha):
    if isinstance(alpha, (types.Float, types.Integer)):
        return lambda alpha: np.random.gamma(alpha, 1.0)

@overload(np.random.gamma)
def gammavariate_impl(alpha, beta):
    if isinstance(alpha, (types.Float, types.Integer)) and isinstance(
            beta, (types.Float, types.Integer)):
        return _gammavariate_impl(np.random.random)

def _gammavariate_impl(_random):
    def _impl(alpha, beta):
        """Gamma distribution.  Taken from CPython.
        """
        SG_MAGICCONST = 1.0 + math.log(4.5)
        # alpha > 0, beta > 0, mean is alpha*beta, variance is alpha*beta**2

        # Warning: a few older sources define the gamma distribution in terms
        # of alpha > -1.0
        if alpha <= 0.0 or beta <= 0.0:
            raise ValueError('gammavariate: alpha and beta must be > 0.0')

        if alpha > 1.0:
            # Uses R.C.H. Cheng, "The generation of Gamma
            # variables with non-integral shape parameters",
            # Applied Statistics, (1977), 26, No. 1, p71-74
            ainv = math.sqrt(2.0 * alpha - 1.0)
            bbb = alpha - math.log(4.0)
            ccc = alpha + ainv

            while 1:
                u1 = _random()
                if not 1e-7 < u1 < .9999999:
                    continue
                u2 = 1.0 - _random()
                v = math.log(u1/(1.0-u1))/ainv
                x = alpha*math.exp(v)
                z = u1*u1*u2
                r = bbb+ccc*v-x
                if r + SG_MAGICCONST - 4.5*z >= 0.0 or r >= math.log(z):
                    return x * beta

        elif alpha == 1.0:
            # expovariate(1)

            if POST_PY38:
                # Adjust due to cpython
                # commit 63d152232e1742660f481c04a811f824b91f6790
                return -math.log(1.0 - _random()) * beta
            else:
                u = _random()
                while u <= 1e-7:
                    u = _random()
                return -math.log(u) * beta

        else:   # alpha is between 0 and 1 (exclusive)
            # Uses ALGORITHM GS of Statistical Computing - Kennedy & Gentle
            while 1:
                u = _random()
                b = (math.e + alpha)/math.e
                p = b*u
                if p <= 1.0:
                    x = p ** (1.0/alpha)
                else:
                    x = -math.log((b-p)/alpha)
                u1 = _random()
                if p > 1.0:
                    if u1 <= x ** (alpha - 1.0):
                        break
                elif u1 <= math.exp(-x):
                    break
            return x * beta
    return _impl

@overload(np.random.gamma)
def gamma_impl(alpha, beta, size):
    if is_nonelike(size):
        return lambda alpha, beta, size: np.random.gamma(alpha, beta)
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                           isinstance(size.dtype,
                                                      types.Integer)):
        def _impl(alpha, beta, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.gamma(alpha, beta)
            return out
        return _impl

@overload(np.random.standard_gamma)
def standard_gamma_impl(alpha, size):
    if is_nonelike(size):
        return lambda alpha, size: np.random.standard_gamma(alpha)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                            and isinstance(size.dtype,
                                                           types.Integer))):
        def _impl(alpha, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.standard_gamma(alpha)
            return out
        return _impl

@overload(random.betavariate)
def betavariate_impl(alpha, beta):
    if isinstance(alpha, (types.Float, types.Integer)) and isinstance(
            beta, (types.Float, types.Integer)):
        return _betavariate_impl(random.gammavariate)

@overload(np.random.beta)
def betavariate_impl(alpha, beta):
    if isinstance(alpha, (types.Float, types.Integer)) and isinstance(
            beta, (types.Float, types.Integer)):
        return _betavariate_impl(np.random.gamma)

def _betavariate_impl(gamma):
    def _impl(alpha, beta):
        """Beta distribution.  Taken from CPython.
        """
        # This version due to Janne Sinkkonen, and matches all the std
        # texts (e.g., Knuth Vol 2 Ed 3 pg 134 "the beta distribution").
        y = gamma(alpha, 1.)
        if y == 0.0:
            return 0.0
        else:
            return y / (y + gamma(beta, 1.))
    return _impl

@overload(np.random.beta)
def beta_impl(alpha, beta, size):
    if is_nonelike(size):
        return lambda alpha, beta, size: np.random.beta(alpha, beta)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                            and isinstance(size.dtype,
                                                           types.Integer))):
        def _impl(alpha, beta, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.beta(alpha, beta)
            return out
        return _impl

@overload(random.expovariate)
def expovariate_impl(lambd):
    if isinstance(lambd, types.Float):
        def _impl(lambd):
            """Exponential distribution.  Taken from CPython.
            """
            # lambd: rate lambd = 1/mean
            # ('lambda' is a Python reserved word)

            # we use 1-random() instead of random() to preclude the
            # possibility of taking the log of zero.
            return -math.log(1.0 - random.random()) / lambd

        return _impl

@overload(np.random.exponential)
def exponential_impl(scale):
    if isinstance(scale, (types.Float, types.Integer)):
        def _impl(scale):
            return -math.log(1.0 - np.random.random()) * scale
        return _impl

@overload(np.random.exponential)
def exponential_impl(scale, size):
    if is_nonelike(size):
        return lambda scale, size: np.random.exponential(scale)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                            isinstance(size.dtype,
                                                       types.Integer))):
        def _impl(scale, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.exponential(scale)
            return out
        return _impl

@overload(np.random.standard_exponential)
@overload(np.random.exponential)
def exponential_impl():
    def _impl():
        return -math.log(1.0 - np.random.random())
    return _impl

@overload(np.random.standard_exponential)
def standard_exponential_impl(size):
    if is_nonelike(size):
        return lambda size: np.random.standard_exponential()
    if (isinstance(size, types.Integer) or
       (isinstance(size, types.UniTuple) and isinstance(size.dtype,
                                                        types.Integer))
    ):
        def _impl(size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.standard_exponential()
            return out
        return _impl

@overload(np.random.lognormal)
def np_lognormal_impl0():
    return lambda: np.random.lognormal(0.0, 1.0)

@overload(np.random.lognormal)
def np_log_normal_impl1(mu):
    if isinstance(mu, (types.Float, types.Integer)):
        return lambda mu: np.random.lognormal(mu, 1.0)

@overload(np.random.lognormal)
def np_log_normal_impl2(mu, sigma):
    if isinstance(mu, (types.Float, types.Integer)) and isinstance(
            sigma, (types.Float, types.Integer)):
        return _lognormvariate_impl(np.random.normal)

@overload(np.random.lognormal)
def lognormal_impl(mu, sigma, size):
    if is_nonelike(size):
        return lambda mu, sigma, size: np.random.lognormal(mu, sigma)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                            isinstance(size.dtype,
                                                       types.Integer))):
        def _impl(mu, sigma, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.lognormal(mu, sigma)
            return out
        return _impl

@overload(random.lognormvariate)
def lognormvariate_impl(mu, sigma):
    if isinstance(mu, types.Float) and isinstance(sigma, types.Float):
        return _lognormvariate_impl(random.gauss)

def _lognormvariate_impl(_gauss):
    return lambda mu, sigma: math.exp(_gauss(mu, sigma))

@overload(random.paretovariate)
def paretovariate_impl(alpha):
    if isinstance(alpha, types.Float):
        def _impl(alpha):
            """Pareto distribution.  Taken from CPython."""
            # Jain, pg. 495
            u = 1.0 - random.random()
            return 1.0 / u ** (1.0/alpha)

        return _impl

@overload(np.random.pareto)
def pareto_impl(alpha):
    if isinstance(alpha, types.Float):
        def _impl(alpha):
            # Same as paretovariate() - 1.
            u = 1.0 - np.random.random()
            return 1.0 / u ** (1.0/alpha) - 1

        return _impl

@overload(np.random.pareto)
def pareto_impl(alpha, size):
    if is_nonelike(size):
        return lambda alpha, size: np.random.pareto(alpha)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                            isinstance(size.dtype,
                                                       types.Integer))):
        def _impl(alpha, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.pareto(alpha)
            return out
        return _impl

@overload(random.weibullvariate)
def weibullvariate_impl(alpha, beta):
    if isinstance(alpha, (types.Float, types.Integer)) and isinstance(
            beta, (types.Float, types.Integer)):
        def _impl(alpha, beta):
            """Weibull distribution.  Taken from CPython."""
            # Jain, pg. 499; bug fix courtesy Bill Arms
            u = 1.0 - random.random()
            return alpha * (-math.log(u)) ** (1.0/beta)

        return _impl

@overload(np.random.weibull)
def weibull_impl(beta):
    if isinstance(beta, (types.Float, types.Integer)):
        def _impl(beta):
            # Same as weibullvariate(1.0, beta)
            u = 1.0 - np.random.random()
            return (-math.log(u)) ** (1.0/beta)

        return _impl

@overload(np.random.weibull)
def weibull_impl2(beta, size):
    if is_nonelike(size):
        return lambda beta, size: np.random.weibull(beta)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                            isinstance(size.dtype,
                                                       types.Integer))):
        def _impl(beta, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.weibull(beta)
            return out
        return _impl

@overload(random.vonmisesvariate)
def vonmisesvariate_impl(mu, kappa):
    if isinstance(mu, types.Float) and isinstance(kappa, types.Float):
        return _vonmisesvariate_impl(random.random)

@overload(np.random.vonmises)
def vonmisesvariate_impl(mu, kappa):
    if isinstance(mu, types.Float) and isinstance(kappa, types.Float):
        return _vonmisesvariate_impl(np.random.random)

def _vonmisesvariate_impl(_random):
    def _impl(mu, kappa):
        """Circular data distribution.  Taken from CPython.
        Note the algorithm in Python 2.6 and Numpy is different:
        http://bugs.python.org/issue17141
        """
        # mu:    mean angle (in radians between 0 and 2*pi)
        # kappa: concentration parameter kappa (>= 0)
        # if kappa = 0 generate uniform random angle

        # Based upon an algorithm published in: Fisher, N.I.,
        # "Statistical Analysis of Circular Data", Cambridge
        # University Press, 1993.

        # Thanks to Magnus Kessler for a correction to the
        # implementation of step 4.
        if kappa <= 1e-6:
            return 2.0 * math.pi * _random()

        s = 0.5 / kappa
        r = s + math.sqrt(1.0 + s * s)

        while 1:
            u1 = _random()
            z = math.cos(math.pi * u1)

            d = z / (r + z)
            u2 = _random()
            if u2 < 1.0 - d * d or u2 <= (1.0 - d) * math.exp(d):
                break

        q = 1.0 / r
        f = (q + z) / (1.0 + q * z)
        u3 = _random()
        if u3 > 0.5:
            theta = (mu + math.acos(f)) % (2.0 * math.pi)
        else:
            theta = (mu - math.acos(f)) % (2.0 * math.pi)

        return theta

    return _impl

@overload(np.random.vonmises)
def vonmises_impl(mu, kappa, size):
    if is_nonelike(size):
        return lambda mu, kappa, size: np.random.vonmises(mu, kappa)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                            and isinstance(size.dtype,
                                                           types.Integer))):
        def _impl(mu, kappa, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.vonmises(mu, kappa)
            return out
        return _impl

@overload(np.random.binomial)
def binomial_impl(n, p):
    if isinstance(n, types.Integer) and isinstance(
            p, (types.Float, types.Integer)):
        def _impl(n, p):
            """
            Binomial distribution.  Numpy's variant of the BINV algorithm
            is used.
            (Numpy uses BTPE for n*p >= 30, though)
            """
            if n < 0:
                raise ValueError("binomial(): n <= 0")
            if not (0.0 <= p <= 1.0):
                raise ValueError("binomial(): p outside of [0, 1]")
            if p == 0.0:
                return 0
            if p == 1.0:
                return n

            flipped = p > 0.5
            if flipped:
                p = 1.0 - p
            q = 1.0 - p

            niters = 1
            qn = q ** n
            while qn <= 1e-308:
                # Underflow => split into several iterations
                # Note this is much slower than Numpy's BTPE
                niters <<= 2
                n >>= 2
                qn = q ** n
                assert n > 0

            np_prod = n * p
            bound = min(n, np_prod + 10.0 * math.sqrt(np_prod * q + 1))

            total = 0
            while niters > 0:
                X = 0
                U = np.random.random()
                px = qn
                while X <= bound:
                    if U <= px:
                        total += n - X if flipped else X
                        niters -= 1
                        break
                    U -= px
                    X += 1
                    px = ((n - X + 1) * p * px) / (X * q)

            return total

        return _impl

@overload(np.random.binomial)
def binomial_impl(n, p, size):
    if is_nonelike(size):
        return lambda n, p, size: np.random.binomial(n, p)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                            isinstance(size.dtype,
                                                       types.Integer))):
        def _impl(n, p, size):
            out = np.empty(size, dtype=np.intp)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.binomial(n, p)
            return out
        return _impl

@overload(np.random.chisquare)
def chisquare_impl(df):
    if isinstance(df, (types.Float, types.Integer)):
        def _impl(df):
            return 2.0 * np.random.standard_gamma(df / 2.0)

        return _impl

@overload(np.random.chisquare)
def chisquare_impl2(p, size):
    if is_nonelike(size):
        return lambda p, size: np.random.chisquare(p)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                            isinstance(size.dtype,
                                                       types.Integer))):
        def _impl(p, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.chisquare(p)
            return out
        return _impl

@overload(np.random.f)
def f_impl(num, denom):
    if isinstance(num, (types.Float, types.Integer)) and isinstance(
            denom, (types.Float, types.Integer)):
        def _impl(num, denom):
            return ((np.random.chisquare(num) * denom) /
                    (np.random.chisquare(denom) * num))

        return _impl

@overload(np.random.f)
def f_impl(num, denom, size):
    if (isinstance(num, (types.Float, types.Integer)) and isinstance(
            denom, (types.Float, types.Integer)) and
       is_nonelike(size)):
        return lambda num, denom, size: np.random.f(num, denom)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                            and isinstance(size.dtype,
                                                           types.Integer))):
        def _impl(num, denom, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.f(num, denom)
            return out
        return _impl

@overload(np.random.geometric)
def geometric_impl(p):
    if isinstance(p, (types.Float, types.Integer)):
        def _impl(p):
            # Numpy's algorithm.
            if p <= 0.0 or p > 1.0:
                raise ValueError("geometric(): p outside of (0, 1]")
            q = 1.0 - p
            if p >= 0.333333333333333333333333:
                X = int(1)
                sum = prod = p
                U = np.random.random()
                while U > sum:
                    prod *= q
                    sum += prod
                    X += 1
                return X
            else:
                return math.ceil(math.log(1.0 - np.random.random()) /
                                 math.log(q))

        return _impl

@overload(np.random.geometric)
def geometric_impl(p, size):
    if is_nonelike(size):
        return lambda p, size: np.random.geometric(p)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                            isinstance(size.dtype,
                                                       types.Integer))):
        def _impl(p, size):
            out = np.empty(size, dtype=np.int64)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.geometric(p)
            return out
        return _impl

@overload(np.random.gumbel)
def gumbel_impl(loc, scale):
    if isinstance(loc, (types.Float, types.Integer)) and isinstance(
            scale, (types.Float, types.Integer)):
        def _impl(loc, scale):
            U = 1.0 - np.random.random()
            return loc - scale * math.log(-math.log(U))

        return _impl

@overload(np.random.gumbel)
def gumbel_impl3(loc, scale, size):
    if is_nonelike(size):
        return lambda loc, scale, size: np.random.gumbel(loc, scale)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                            and isinstance(size.dtype,
                                                           types.Integer))):
        def _impl(loc, scale, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.gumbel(loc, scale)
            return out
        return _impl

@overload(np.random.hypergeometric)
def hypergeometric_impl(ngood, nbad, nsamples):
    if (isinstance(ngood, (types.Float, types.Integer)) and isinstance(
            nbad, (types.Float, types.Integer))
       and isinstance(nsamples, (types.Float, types.Integer))):
        def _impl(ngood, nbad, nsamples):
            """Numpy's algorithm for hypergeometric()."""
            d1 = int(nbad) + int(ngood) - int(nsamples)
            d2 = float(min(nbad, ngood))

            Y = d2
            K = int(nsamples)
            while Y > 0.0 and K > 0:
                Y -= math.floor(np.random.random() + Y / (d1 + K))
                K -= 1
            Z = int(d2 - Y)
            if ngood > nbad:
                return int(nsamples) - Z
            else:
                return Z

        return _impl

@overload(np.random.hypergeometric)
def hypergeometric_impl(ngood, nbad, nsamples, size):
    if is_nonelike(size):
        return lambda ngood, nbad, nsamples, size:\
            np.random.hypergeometric(ngood, nbad, nsamples)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                            and isinstance(size.dtype,
                                                           types.Integer))):
        def _impl(ngood, nbad, nsamples, size):
            out = np.empty(size, dtype=np.intp)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.hypergeometric(ngood, nbad, nsamples)
            return out
        return _impl

@overload(np.random.laplace)
def laplace_impl0():
    return lambda: np.random.laplace(0.0, 1.0)

@overload(np.random.laplace)
def laplace_impl1(loc):
    if isinstance(loc, (types.Float, types.Integer)):
        return lambda loc: np.random.laplace(loc, 1.0)

@overload(np.random.laplace)
def laplace_impl2(loc, scale):
    if isinstance(loc, (types.Float, types.Integer)) and isinstance(
            scale, (types.Float, types.Integer)):
        return laplace_impl

@overload(np.random.laplace)
def laplace_impl3(loc, scale, size):
    if is_nonelike(size):
        return lambda loc, scale, size: np.random.laplace(loc, scale)
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                           isinstance(size.dtype,
                                                      types.Integer)):
        def _impl(loc, scale, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.laplace(loc, scale)
            return out
        return _impl

def laplace_impl(loc, scale):
    U = np.random.random()
    if U < 0.5:
        return loc + scale * math.log(U + U)
    else:
        return loc - scale * math.log(2.0 - U - U)

@overload(np.random.logistic)
def logistic_impl0():
    return lambda: np.random.logistic(0.0, 1.0)

@overload(np.random.logistic)
def logistic_impl1(loc):
    if isinstance(loc, (types.Float, types.Integer)):
        return lambda loc: np.random.logistic(loc, 1.0)

@overload(np.random.logistic)
def logistic_impl2(loc, scale):
    if isinstance(loc, (types.Float, types.Integer)) and isinstance(
            scale, (types.Float, types.Integer)):
        return logistic_impl

@overload(np.random.logistic)
def logistic_impl3(loc, scale, size):
    if is_nonelike(size):
        return lambda loc, scale, size: np.random.logistic(loc, scale)
    if (isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                            and isinstance(size.dtype,
                                                           types.Integer))):
        def _impl(loc, scale, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.logistic(loc, scale)
            return out
        return _impl

def logistic_impl(loc, scale):
    U = np.random.random()
    return loc + scale * math.log(U / (1.0 - U))

def _logseries_impl(p):
    """Numpy's algorithm for logseries()."""
    if p <= 0.0 or p > 1.0:
        raise ValueError("logseries(): p outside of (0, 1]")
    r = math.log(1.0 - p)

    while 1:
        V = np.random.random()
        if V >= p:
            return 1
        U = np.random.random()
        q = 1.0 - math.exp(r * U)
        if V <= q * q:
            # XXX what if V == 0.0 ?
            return np.int64(1.0 + math.log(V) / math.log(q))
        elif V >= q:
            return 1
        else:
            return 2

@overload(np.random.logseries)
def logseries_impl(p):
    if isinstance(p, (types.Float, types.Integer)):
        return _logseries_impl

@overload(np.random.logseries)
def logseries_impl(p, size):
    if is_nonelike(size):
        return lambda p, size: np.random.logseries(p)
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                           isinstance(size.dtype,
                                                      types.Integer)):
        def _impl(p, size):
            out = np.empty(size, dtype=np.int64)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.logseries(p)
            return out
        return _impl

@overload(np.random.negative_binomial)
def negative_binomial_impl(n, p):
    if isinstance(n, types.Integer) and isinstance(
            p,(types.Float, types.Integer)):
        def _impl(n, p):
            if n <= 0:
                raise ValueError("negative_binomial(): n <= 0")
            if p < 0.0 or p > 1.0:
                raise ValueError("negative_binomial(): p outside of [0, 1]")
            Y = np.random.gamma(n, (1.0 - p) / p)
            return np.random.poisson(Y)

        return _impl

@overload(np.random.poisson)
def poisson_impl0():
    return lambda: np.random.poisson(1.0)

@overload(np.random.poisson)
def poisson_impl1(lam):
    if isinstance(lam, (types.Float, types.Integer)):
        @intrinsic
        def _impl(typingcontext, lam):
            lam_preprocessor = _double_preprocessor(lam)

            def codegen(context, builder, sig, args):
                state_ptr = get_np_state_ptr(context, builder)

                retptr = cgutils.alloca_once(builder, int64_t, name="ret")
                bbcont = builder.append_basic_block("bbcont")
                bbend = builder.append_basic_block("bbend")

                lam, = args
                lam = lam_preprocessor(builder, lam)
                big_lam = builder.fcmp_ordered('>=', lam,
                                               ir.Constant(double, 10.0))
                with builder.if_then(big_lam):
                    # For lambda >= 10.0, we switch to a more accurate
                    # algorithm (see _random.c).
                    fnty = ir.FunctionType(int64_t, (rnd_state_ptr_t, double))
                    fn = cgutils.get_or_insert_function(builder.function.module,
                                                        fnty,
                                                        "numba_poisson_ptrs")
                    ret = builder.call(fn, (state_ptr, lam))
                    builder.store(ret, retptr)
                    builder.branch(bbend)

                builder.branch(bbcont)
                builder.position_at_end(bbcont)

                _random = np.random.random
                _exp = math.exp

                def poisson_impl(lam):
                    """Numpy's algorithm for poisson() on small *lam*.

                    This method is invoked only if the parameter lambda of the
                    distribution is small ( < 10 ). The algorithm used is
                    described in "Knuth, D. 1969. 'Seminumerical Algorithms.
                    The Art of Computer Programming' vol 2.
                    """
                    if lam < 0.0:
                        raise ValueError("poisson(): lambda < 0")
                    if lam == 0.0:
                        return 0
                    enlam = _exp(-lam)
                    X = 0
                    prod = 1.0
                    while 1:
                        U = _random()
                        prod *= U
                        if prod <= enlam:
                            return X
                        X += 1

                ret = context.compile_internal(builder, poisson_impl, sig, args)
                builder.store(ret, retptr)
                builder.branch(bbend)
                builder.position_at_end(bbend)
                return builder.load(retptr)
            return signature(types.int64, lam), codegen
        return lambda lam: _impl(lam)

@overload(np.random.poisson)
def poisson_impl2(lam, size):
    if isinstance(lam, (types.Float, types.Integer)) and is_nonelike(size):
        return lambda lam, size: np.random.poisson(lam)
    if isinstance(lam, (types.Float, types.Integer)) and (
            isinstance(size, types.Integer) or
       (isinstance(size, types.UniTuple) and isinstance(size.dtype,
                                                        types.Integer))
    ):
        def _impl(lam, size):
            out = np.empty(size, dtype=np.intp)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.poisson(lam)
            return out
        return _impl

@overload(np.random.power)
def power_impl(a):
    if isinstance(a, (types.Float, types.Integer)):
        def _impl(a):
            if a <= 0.0:
                raise ValueError("power(): a <= 0")
            return math.pow(1 - math.exp(-np.random.standard_exponential()),
                            1./a)

        return _impl

@overload(np.random.power)
def power_impl(a, size):
    if is_nonelike(size):
        return lambda a, size: np.random.power(a)
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                           isinstance(size.dtype,
                                                      types.Integer)):
        def _impl(a, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.power(a)
            return out
        return _impl

@overload(np.random.rayleigh)
def rayleigh_impl0():
    return lambda: np.random.rayleigh(1.0)

@overload(np.random.rayleigh)
def rayleigh_impl1(mode):
    if isinstance(mode, (types.Float, types.Integer)):
        return rayleigh_impl

def rayleigh_impl(mode):
    if mode <= 0.0:
        raise ValueError("rayleigh(): mode <= 0")
    return mode * math.sqrt(-2.0 * math.log(1.0 - np.random.random()))

@overload(np.random.rayleigh)
def rayleigh_impl2(mode, size):
    if is_nonelike(size):
        return lambda mode, size: np.random.rayleigh(mode)
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                           isinstance(size.dtype,
                                                      types.Integer)):
        def _impl(mode, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.rayleigh(mode)
            return out
        return _impl

@overload(np.random.standard_cauchy)
def cauchy_impl():
    def _impl():
        return np.random.standard_normal() / np.random.standard_normal()

    return _impl

@overload(np.random.standard_cauchy)
def standard_cauchy_impl(size):
    if is_nonelike(size):
        return lambda size: np.random.standard_cauchy()
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                           and isinstance(size.dtype,
                                                          types.Integer)):
        def _impl(size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.standard_cauchy()
            return out
        return _impl

@overload(np.random.standard_t)
def standard_t_impl(df):
    if isinstance(df, (types.Float, types.Integer)):
        def _impl(df):
            N = np.random.standard_normal()
            G = np.random.standard_gamma(df / 2.0)
            X = math.sqrt(df / 2.0) * N / math.sqrt(G)
            return X

        return _impl

@overload(np.random.standard_t)
def standard_t_impl2(df, size):
    if is_nonelike(size):
        return lambda p, size: np.random.standard_t(p)
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                           isinstance(size.dtype,
                                                      types.Integer)):
        def _impl(df, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.standard_t(df)
            return out
        return _impl

@overload(np.random.wald)
def wald_impl(mean, scale):
    if isinstance(mean, types.Float) and isinstance(scale, types.Float):
        def _impl(mean, scale):
            if mean <= 0.0:
                raise ValueError("wald(): mean <= 0")
            if scale <= 0.0:
                raise ValueError("wald(): scale <= 0")
            mu_2l = mean / (2.0 * scale)
            Y = np.random.standard_normal()
            Y = mean * Y * Y
            X = mean + mu_2l * (Y - math.sqrt(4 * scale * Y + Y * Y))
            U = np.random.random()
            if U <= mean / (mean + X):
                return X
            else:
                return mean * mean / X

        return _impl

@overload(np.random.wald)
def wald_impl2(mean, scale, size):
    if is_nonelike(size):
        return lambda mean, scale, size: np.random.wald(mean, scale)
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                           isinstance(size.dtype,
                                                      types.Integer)):
        def _impl(mean, scale, size):
            out = np.empty(size)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.wald(mean, scale)
            return out
        return _impl

@overload(np.random.zipf)
def zipf_impl(a):
    if isinstance(a, types.Float):
        def _impl(a):
            if a <= 1.0:
                raise ValueError("zipf(): a <= 1")
            am1 = a - 1.0
            b = 2.0 ** am1
            while 1:
                U = 1.0 - np.random.random()
                V = np.random.random()
                X = int(math.floor(U ** (-1.0 / am1)))
                T = (1.0 + 1.0 / X) ** am1
                if X >= 1 and V * X * (T - 1.0) / (b - 1.0) <= (T / b):
                    return X

        return _impl

@overload(np.random.zipf)
def zipf_impl(a, size):
    if is_nonelike(size):
        return lambda a, size: np.random.zipf(a)
    if isinstance(size, types.Integer) or (isinstance(size, types.UniTuple) and
                                           isinstance(size.dtype,
                                                      types.Integer)):
        def _impl(a, size):
            out = np.empty(size, dtype=np.intp)
            out_flat = out.flat
            for idx in range(out.size):
                out_flat[idx] = np.random.zipf(a)
            return out
        return _impl

def do_shuffle_impl(arr, rng):

    if not isinstance(arr, types.Buffer):
        raise TypeError("The argument to shuffle() should be a buffer type")

    if rng == "np":
        rand = np.random.randint
    elif rng == "py":
        rand = random.randrange

    if arr.ndim == 1:
        def impl(arr):
            i = arr.shape[0] - 1
            while i > 0:
                j = rand(i + 1)
                arr[i], arr[j] = arr[j], arr[i]
                i -= 1
    else:
        def impl(arr):
            i = arr.shape[0] - 1
            while i > 0:
                j = rand(i + 1)
                arr[i], arr[j] = np.copy(arr[j]), np.copy(arr[i])
                i -= 1

    return impl

@overload(random.shuffle)
def shuffle_impl(arr):
    return do_shuffle_impl(arr, "py")

@overload(np.random.shuffle)
def shuffle_impl(arr):
    return do_shuffle_impl(arr, "np")

@overload(np.random.permutation)
def permutation_impl(x):
    if isinstance(x, types.Integer):
        def permutation_impl(x):
            y = np.arange(x)
            np.random.shuffle(y)
            return y
    elif isinstance(x, types.Array):
        def permutation_impl(x):
            arr_copy = x.copy()
            np.random.shuffle(arr_copy)
            return arr_copy
    else:
        permutation_impl = None
    return permutation_impl

# ------------------------------------------------------------------------
# Irregular aliases: np.random.rand, np.random.randn

@overload(np.random.rand)
def rand(*size):
    if len(size) == 0:
        # Scalar output
        def rand_impl(*size):
            return np.random.random()

    else:
        # Array output
        def rand_impl(*size):
            return np.random.random(size)

    return rand_impl

@overload(np.random.randn)
def randn(*size):
    if len(size) == 0:
        # Scalar output
        def randn_impl(*size):
            return np.random.standard_normal()

    else:
        # Array output
        def randn_impl(*size):
            return np.random.standard_normal(size)

    return randn_impl

# ------------------------------------------------------------------------
# np.random.choice

@overload(np.random.choice)
def choice(a, size=None, replace=True):

    if isinstance(a, types.Array):
        # choice() over an array population
        assert a.ndim == 1
        dtype = a.dtype

        @register_jitable
        def get_source_size(a):
            return len(a)

        @register_jitable
        def copy_source(a):
            return a.copy()

        @register_jitable
        def getitem(a, a_i):
            return a[a_i]

    elif isinstance(a, types.Integer):
        # choice() over an implied arange() population
        dtype = np.intp

        @register_jitable
        def get_source_size(a):
            return a

        @register_jitable
        def copy_source(a):
            return np.arange(a)

        @register_jitable
        def getitem(a, a_i):
            return a_i

    else:
        raise TypeError("np.random.choice() first argument should be "
                        "int or array, got %s" % (a,))

    if size in (None, types.none):
        def choice_impl(a, size=None, replace=True):
            """
            choice() implementation returning a single sample
            (note *replace* is ignored)
            """
            n = get_source_size(a)
            i = np.random.randint(0, n)
            return getitem(a, i)

    else:
        def choice_impl(a, size=None, replace=True):
            """
            choice() implementation returning an array of samples
            """
            n = get_source_size(a)
            if replace:
                out = np.empty(size, dtype)
                fl = out.flat
                for i in range(len(fl)):
                    j = np.random.randint(0, n)
                    fl[i] = getitem(a, j)
                return out
            else:
                # Note we have to construct the array to compute out.size
                # (`size` can be an arbitrary int or tuple of ints)
                out = np.empty(size, dtype)
                if out.size > n:
                    raise ValueError("Cannot take a larger sample than "
                                     "population when 'replace=False'")
                # Get a permuted copy of the source array
                # we need this implementation in order to get the
                # np.random.choice inside numba to match the output
                # of np.random.choice outside numba when np.random.seed
                # is set to the same value
                permuted_a = np.random.permutation(a)
                fl = out.flat
                for i in range(len(fl)):
                    fl[i] = permuted_a[i]
                return out

    return choice_impl

# ------------------------------------------------------------------------
# np.random.multinomial

@overload(np.random.multinomial)
def multinomial(n, pvals, size=None):

    dtype = np.intp

    @register_jitable
    def multinomial_inner(n, pvals, out):
        # Numpy's algorithm for multinomial()
        fl = out.flat
        sz = out.size
        plen = len(pvals)

        for i in range(0, sz, plen):
            # Loop body: take a set of n experiments and fill up
            # fl[i:i + plen] with the distribution of results.

            # Current sum of outcome probabilities
            p_sum = 1.0
            # Current remaining number of experiments
            n_experiments = n
            # For each possible outcome `j`, compute the number of results
            # with this outcome.  This is done by considering the
            # conditional probability P(X=j | X>=j) and running a binomial
            # distribution over the remaining number of experiments.
            for j in range(0, plen - 1):
                p_j = pvals[j]
                n_j = fl[i + j] = np.random.binomial(n_experiments, p_j / p_sum)
                n_experiments -= n_j
                if n_experiments <= 0:
                    # Note the output was initialized to zero
                    break
                p_sum -= p_j
            if n_experiments > 0:
                # The remaining experiments end up in the last bucket
                fl[i + plen - 1] = n_experiments

    if not isinstance(n, types.Integer):
        raise TypeError("np.random.multinomial(): n should be an "
                        "integer, got %s" % (n,))

    if not isinstance(pvals, (types.Sequence, types.Array)):
        raise TypeError("np.random.multinomial(): pvals should be an "
                        "array or sequence, got %s" % (pvals,))

    if size in (None, types.none):
        def multinomial_impl(n, pvals, size=None):
            """
            multinomial(..., size=None)
            """
            out = np.zeros(len(pvals), dtype)
            multinomial_inner(n, pvals, out)
            return out

    elif isinstance(size, types.Integer):
        def multinomial_impl(n, pvals, size=None):
            """
            multinomial(..., size=int)
            """
            out = np.zeros((size, len(pvals)), dtype)
            multinomial_inner(n, pvals, out)
            return out

    elif isinstance(size, types.BaseTuple):
        def multinomial_impl(n, pvals, size=None):
            """
            multinomial(..., size=tuple)
            """
            out = np.zeros(size + (len(pvals),), dtype)
            multinomial_inner(n, pvals, out)
            return out

    else:
        raise TypeError("np.random.multinomial(): size should be int or "
                        "tuple or None, got %s" % (size,))

    return multinomial_impl

# ------------------------------------------------------------------------
# np.random.dirichlet

@overload(np.random.dirichlet)
def dirichlet(alpha):
    if isinstance(alpha, (types.Sequence, types.Array)):
        def dirichlet_impl(alpha):
            out = np.empty(len(alpha))
            dirichlet_arr(alpha, out)
            return out
        return dirichlet_impl

@overload(np.random.dirichlet)
def dirichlet(alpha, size=None):
    if not isinstance(alpha, (types.Sequence, types.Array)):
        raise NumbaTypeError(
            "np.random.dirichlet(): alpha should be an "
            "array or sequence, got %s" % (alpha,)
        )

    if size in (None, types.none):

        def dirichlet_impl(alpha, size=None):
            out = np.empty(len(alpha))
            dirichlet_arr(alpha, out)
            return out

    elif isinstance(size, types.Integer):

        def dirichlet_impl(alpha, size=None):
            """
            dirichlet(..., size=int)
            """
            out = np.empty((size, len(alpha)))
            dirichlet_arr(alpha, out)
            return out

    elif isinstance(size, types.UniTuple) and isinstance(size.dtype,
                                                         types.Integer):
        def dirichlet_impl(alpha, size=None):
            """
            dirichlet(..., size=tuple)
            """
            out = np.empty(size + (len(alpha),))
            dirichlet_arr(alpha, out)
            return out

    else:
        raise NumbaTypeError(
            "np.random.dirichlet(): size should be int or "
            "tuple of ints or None, got %s" % size
        )

    return dirichlet_impl

@register_jitable
def dirichlet_arr(alpha, out):

    # Gamma distribution method to generate a Dirichlet distribution

    for a_val in iter(alpha):
        if a_val <= 0:
            raise ValueError("dirichlet: alpha must be > 0.0")

    a_len = len(alpha)
    size = out.size
    flat = out.flat
    for i in range(0, size, a_len):
        # calculate gamma random numbers per alpha specifications
        norm = 0  # use this to normalize every the group total to 1
        for k, w in enumerate(alpha):
            flat[i + k] = np.random.gamma(w, 1)
            norm += flat[i + k].item()
        for k, w in enumerate(alpha):
            flat[i + k] /= norm

# ------------------------------------------------------------------------
# np.random.noncentral_chisquare

@overload(np.random.noncentral_chisquare)
def noncentral_chisquare(df, nonc):
    if isinstance(df, (types.Float, types.Integer)) and isinstance(
            nonc, (types.Float, types.Integer)):
        def noncentral_chisquare_impl(df, nonc):
            validate_noncentral_chisquare_input(df, nonc)
            return noncentral_chisquare_single(df, nonc)

        return noncentral_chisquare_impl

@overload(np.random.noncentral_chisquare)
def noncentral_chisquare(df, nonc, size=None):
     if size in (None, types.none):
         def noncentral_chisquare_impl(df, nonc, size=None):
             validate_noncentral_chisquare_input(df, nonc)
             return noncentral_chisquare_single(df, nonc)
         return noncentral_chisquare_impl
     elif isinstance(size, types.Integer) or (isinstance(size, types.UniTuple)
                                              and isinstance(size.dtype,
                                                             types.Integer)):

         def noncentral_chisquare_impl(df, nonc, size=None):
             validate_noncentral_chisquare_input(df, nonc)
             out = np.empty(size)
             out_flat = out.flat
             for idx in range(out.size):
                 out_flat[idx] = noncentral_chisquare_single(df, nonc)
             return out
         return noncentral_chisquare_impl
     else:
         raise NumbaTypeError(
             "np.random.noncentral_chisquare(): size should be int or "
             "tuple of ints or None, got %s" % size
         )

@register_jitable
def noncentral_chisquare_single(df, nonc):
    # identical to numpy implementation from distributions.c
    # https://github.com/numpy/numpy/blob/c65bc212ec1987caefba0ea7efe6a55803318de9/numpy/random/src/distributions/distributions.c#L797

    if np.isnan(nonc):
        return np.nan

    if 1 < df:
        chi2 = np.random.chisquare(df-1)
        n = np.random.standard_normal() + np.sqrt(nonc)
        return chi2 + n * n

    else:
        i = np.random.poisson(nonc/2.0)
        return np.random.chisquare(df + 2 * i)

@register_jitable
def validate_noncentral_chisquare_input(df, nonc):
    if df <= 0:
        raise ValueError("df <= 0")
    if nonc < 0:
        raise ValueError("nonc < 0")

redpajama_set_name: RedPajamaGithub


ACI's expert team is able to offer results oriented programs largely based on our experience and knowledge. The regulatory landscape is constantly changing and, now more than ever, clients need and want to know their financial future is secure. As an industry, we need to better understand our regulatory responsibilities and restore confidence in the financial markets.
Below, ACI has collected SEC, FINRA, and other regulatory notices that are most pertinent to the broker-dealer FinOp role. Ultimately the broker dealer is responsible for understanding and adhering to all regulations, as complex and expansive as they may be. It is critical to stay up to date, but you don't have to be alone. If you partner with ACI, our team of CPAs, FinOps, and financial services professionals will help you fully understand and minimize your risks.
Contact ACI today to learn more about our approach to managing the financial regulatory landscape with our clients.
For the full list of FINRA Notices visit www.finra.org/industry/notices.
Give us a call at 212-668-8700, or reach out via our contact form to learn more.


text:
KNUST Biochemistry students donate to department
Kumasi, Oct 7, GNA - The Ghana Biochemistry Students Association (GBSA) of the Kwame Nkrumah University of Science and Technology (KNUST) has donated science materials and books to the Biochemistry Department of the University.
The items that valued at about two million cedis, included two hot plates, three burettes and two thermometers as well as a set of science books.
Presenting the equipment, Mr Kwaku Akoi Tete, president of GBSA, said the donation formed part of the Association's week celebration. He said GBSA presented two computers to the Department last year and gave the promise that it would donate two more computers to the Department.
Mr Tete said facilities at the Department were limited citing that it had only 10 computers for 380 students.
Professor Pearl Victoria Dzogbefia and Dr William Otoo Ellis, both of the Department, received the items and praised the association for the gesture.


For nonprofit institutions, the impact of fraud can go beyond the actual dollar losses sustained and result in damage to the organization's reputation and loss of public trust.
According to a recent study by the Association of Certified Fraud Examiners (ACFE), organizations lose $3.7 trillion worldwide a year due to fraud.
Tate & Tryon's team of fraud and forensic accounting professionals are experienced in detecting, quantifying, and reporting on fraudulent activity. If you suspect financial fraud is occurring or has been committed, we can work directly with you and your attorney to ensure the conduct of a credible investigation. Our team includes professionals who are both Certified Public Accountants and Certified Fraud Examiners.
We also work with organizations to proactively manage fraud risk by helping to develop and ensure that the appropriate controls are in place to help prevent and detect fraud. Although no system of internal controls can provide absolute safeguards against fraud, we can assist with establishing practices, policies, and procedures that will help minimize the risk and exposure of fraud occurring in your organization.
According to a 2016 study by the Association of Certified Fraud Examiners (ACFE), organizations lost $3.7 trillion worldwide due to fraud. Effective fraud monitoring is a key management responsibility for future financial security.


The precious metal sharply increased in value during yesterday's trading hours and is currently located near its high since November 2016. The growth was caused by the US negative economic data and the statement by the Minister of Finance about future perspectives of the US currency. During the day, some negative US data is also expected, which will have a positive impact on the metal's price.
Gold has risen by 21 points, and still continues to actively grow. Traders have a great chance to earn money on the asset's further increase. Remember, that trading will be available from 3:00 to 19:00 GMT time.


No love for neti pots. kiyaserin13 said "I just think the whole concept is just a little gross. I see no reason why every orifice suddenly has to be squeaky clean. I saw the Oprah episode where they raved about it, but the idea totally doesn't appeal to me. Whatever happened to blowing our noses? And can something so weird really change someone's life?"
Are you best friend-less? Tinakm said "i agree! i have a small group of very close knit friends and i am much happier than when i had one best friend."
Ticked-off Tuesday: Spikie71 shared a personal family gripe: "I'm beyond mad at my Mom and have been ever since she left my Dad for another man 6 months ago."
Kate Winslet on still feeling like the "fat kid." Tiger234 said "she looks awesome. We need more women like her, who are talented and intelligent and totally unique." Agreed!
Would you turn down a handshake in the name of germ prevention? MEGS1987 said no way. "I would never turn down a handshake. I agree with you on using hand sanitizer. A Handshake is making a connection with someone, and I feel it is the utmost of ignorance to refuse. It's the world's way of saying "I am reaching out to you."


The SAFE LANE COALITION is a partnership of organizations and community members that aspire to eliminate fatalities and severe injuries on our transportation network.
Motor vehicle crashes are a public health issue that continues to affect our community. In 2015, 445 Oregonians were killed in motor vehicle crashes and 41,675 were injured. Lane County led the state with more traffic fatalities than any other county in Oregon – 57 killed and 3,242 injured. Nationally, there was an 8 percent increase in traffic fatalities, the largest increase in 50 years, with Oregon at the top of the list with a 27 percent increase. Safe Lane Transportation Coalition (SLTC) works to reduce the number of severe and fatal crashes in Lane County by evaluating the best safety practices from across the United States, and partnering with local agencies to implement new and effective safety initiatives.
Strategies to reduce traffic fatalities include a combination of engineering solutions to create safer roadways, educating people about safer practices, and improving enforcement and emergency response services. Supporting high-visibility Driving Under the Influence of Intoxicants (DUII) enforcement is a key area of focus for SLTC.
In 2015, the Central Lane Metropolitan Planning Organization (CLMPO) and Lane County began collaborating on an innovative planning process to address the growing need to prioritize safety throughout our transportation system. Their efforts created a regional safety action plan, The Safe Lane, that set the groundwork for systematic changes to our transportation system. To implement the vision and goals set out in the Safe Lane Action Plan, CLMPO and Lane County, with the support from the Oregon Department of Transportation, created the Safe Lane Transportation Coalition. This program focuses on reducing fatal and severe crashes in our region through education, outreach, and enforcement efforts.
In 2015 and 2016 coalition partners came together to develop a Transportation Safety Action Plan that serves Lane County. To date, the Metropolitan Policy Committee has adopted a safety plan for the metro area. A rural plan will be considered by the Board of County Commissioners in July.
Oregon has long been a leader in transportation safety through the Oregon Department of Transportation (ODOT) Transportation Safety Division. ODOT has developed a statewide Transportation Safety Action Plan (TSAP). The Oregon (TSAP) establishes a set of actions that Oregonians have identified as steps to a safer travel environment.
Building on the success and partnerships of this planning process, the MPO and Lane County with support from ODOT launched the Safe Lane Coalition. Safe Lane Coalition implements the vision the laid out in the Transportation Safety Action Plan and focuses on reducing fatal and severe crashes in our region through education, outreach, and enforcement efforts.


Submitted by Steve Dondley on Wed, 03/27/2013 - 8:49am.
Journalist Mike Elk with Prometheus owner Steve Dondley.
"Providing reporting on issues affecting working folks takes a lot of time and money", says Mike. "Unfortunately, there's as many pink slips going around for labor reporters as there are working folks. That's why LaborMail's underwriting program for labor journalism is so important. It's going to help me cover the stories most in the media don't care about and I can't thank Prometheus enough for starting this program."
While Mike won't violate editorial independence by guaranteeing that he will write a story favorable to your union if you sign up for LaborMail, he will promise to buy you a beer if you are ever in DC.
Find out about getting LaborMail for your union!


clubbing@gmt+1 is a project of young, enthusiastic people from Zurich and St.Gallen, Switzerland. clubbing@gmt+1 covers the most of the swiss party & music-scene and several other locations in europe.
Our target was to help the client to develope an up to date website, which has all state of the art technical and layout features. Additional features will be added regularely.
Design and content provided through clubbing@gmt+1. Hosting technology and databases specified, installed and maintained by VADIAN.NET INC. and VEBTREX.