picks a value accoriding to the given density
968978
def pick(self):
        
        v = random.uniform(0, self.ub)
        d = self.dist
        c = self.vc - 1
        s = self.vc
        while True:
            s = s / 2
            if s == 0:
                break
            if v <= d[c][1]:
                c -= s
            else:
                c += s
                # we only need this logic when increasing c
                while len(d) <= c:
                    s = s / 2
                    c -= s
                    if s == 0:
                        break
        # we may have converged from the left, instead of the right
        if c == len(d) or v <= d[c][1]:
            c -= 1
        return d[c][0]
217190
private static int getRolledValue(int value, int amount, int min, int max) {
        assert value >= min && value <= max;
        int range = max - min + 1;
        amount %= range;
        int n = value + amount;
        if (n > max) {
            n -= range;
        } else if (n < min) {
            n += range;
        }
        assert n >= min && n <= max;
        return n;
    }
364573
def _check_min_density(self, min_density):
        """"""

        if min_density is None:
            self._min_density = -np.Inf
        elif (isinstance(min_density, float) and (0.0 <= min_density < 1.0)):
            self._min_density = min_density
        else:
            raise ValueError('min_density must be float and be >=0.0 and < 1.0')
1325924
def pick(self, *args):
        
        ns = self.Namespace()
        ns.result = {}

        def by(key, *args):
            if key in self.obj:
                ns.result[key] = self.obj[key]

        _.each(self._flatten(args, True, []), by)
        return self._wrap(ns.result)
19090
def pick(self, selector, entity_set, min_quantity=None):
        
        if isinstance(selector, int):
            for e in entity_set:
                if e.id == selector:
                    return set((e,))
        else:
            if selector.lower() in ('self', 'me', 'myself'):
                return set((self.entity,))

            return set(
                e for e in entity_set
                if (e.is_('Named') and selector.lower() in e.Named.name.lower())
                and not e.is_(Invisible)
                and (not min_quantity or min_quantity == 1 or (e.is_(Stackable) and e.Stackable.quantity >= min_quantity))
            )
366790
def paretoint(avg, alpha):
    """"""
    return int(random.paretovariate(alpha) * avg / (alpha / (alpha - 1)))
399405
def pick
            tst = rand
            sum = 0
            @map.each do |value, prob|
                sum += prob
                return value,prob if tst < sum
            end
            return nil
        end
312101
def bound_range(vals, density, time_unit='us'):
    
    if not len(vals):
        return(np.nan, np.nan, density, False)
    low, high = vals.min(), vals.max()
    invert = False
    if len(vals) > 1 and vals[0] > vals[1]:
        invert = True
    if not density:
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', r'invalid value encountered in double_scalars')
            full_precision_density = compute_density(low, high, len(vals)-1)
            density = round(full_precision_density, sys.float_info.dig)
        if density == 0:
            density = full_precision_density
    if density == 0:
        raise ValueError('Could not determine Image density, ensure it has a non-zero range.')
    halfd = 0.5/density
    if isinstance(low, datetime_types):
        halfd = np.timedelta64(int(round(halfd)), time_unit)
    return low-halfd, high+halfd, density, invert
1327802
def compute(self, data, fill_value=None, **kwargs):
        """"""
        del kwargs

        if fill_value is None:
            fill_value = data.attrs.get('_FillValue')
        target_shape = self.target_geo_def.shape

        res = self.resampler.get_sample_from_bil_info(data,
                                                      fill_value=fill_value,
                                                      output_shape=target_shape)

        return res
757976
def choose(self):
        """"""
        if not self.choosed:
            self.choosed = True
            self.pos = self.pos + Sep(5, 0)
341539
def density(self):
        
        tot_nonsparse = sum(ser.sp_index.npoints
                            for _, ser in self.items())
        tot = len(self.index) * len(self.columns)
        return tot_nonsparse / float(tot)
1069724
def propose(self):
        """"""

        # Generate uniform variate to choose kernel
        self.current_kernel = sum(self.cum_probs < random())
        kernel = self.kernels[self.current_kernel]

        # Parameters to move
        self.phi = (random(self._len) < self.p)

        # Propose new value
        kernel()
556655
def select(self, **kws):
        '''
            
        '''
        lst = [i for i in self.values() if i.select(**kws)]

        random.shuffle(lst)

        return lst
272798
def averageValues(self):
        
        assert self.opts['record_density'] and self.opts['method'] == 'sum'
        # dont increase value of partly filled cells (density 0..1):
        filled = self.density > 1
        v = self.values.copy()
        v[filled] /= self.density[filled]

        # ONLY AS OPTION??:
        v[~filled] *= self.density[~filled]
        return v
172657
def density(self, x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0):
        
        raise ValueError("not implemented! Use a Multi-Gaussian-component decomposition.")
907157
def choose(s, possibilities, threshold=.6):
    
    if not possibilities: return None
    if s in possibilities: return s
    if s == '': return None
    startswith = [x for x in possibilities if x.lower().startswith(s.lower())]
    if len(startswith) == 1: return startswith[0]
    contained = [x for x in possibilities if s.lower() in x.lower()]
    if len(contained) == 1: return contained[0]
    best = max([(x, Levenshtein.jaro_winkler(s, x, .05)) for x in possibilities], key=itemgetter(1))
    if best[1] < threshold:
        #print 'did you mean %s?' % best[0]
        return None
    return best[0]
187030
def fill_value(dtype):
    '''
    '''
    if np.issubdtype(dtype, np.floating) or np.issubdtype(dtype, np.complexfloating):
        return dtype(np.nan)

    return dtype(0)