Saturating sigmoid: 1.2 * sigmoid(x) - 0.1 cut to [0, 1].
328635
def saturating_sigmoid(x):
  """"""
  with tf.name_scope("saturating_sigmoid", values=[x]):
    y = tf.sigmoid(x)
    return tf.minimum(1.0, tf.maximum(0.0, 1.2 * y - 0.1))
1140884
def dmtoind(dm, f_min, f_max, nchan0, inttime, it):
    

#    maxDT = dmtodt(dm) # need to write

    if it>0:
        correction = dF/2.
    else:
        correction = 0

    shift = []
    nchan = nchan0/2**(iteration_num)
    for i_F in range(nchan):
        f_start = (f_max - f_min)/float(nchan) * (i_F) + f_min
        f_end = (f_max - f_min)/float(nchan) *(i_F+1) + f_min
        f_middle = (f_end - f_start)/2. + f_start - correction
        f_middle_larger = (f_end - f_start)/2 + f_start + correction

        dT_middle = int(round(i_dT * (1./f_middle**2 - 1./f_start**2)/(1./f_end**2 - 1./f_start**2)))
        dT_middle_larger = int(round(i_dT * (1./f_middle_larger**2 - 1./f_start**2)/(1./f_end**2 - 1./f_start**2)))

        shift.append( (-dT_middle_larger, i_F) )
525321
def round_sigfigs(x, n=2):
    
    iterable = is_iterable(x)
    if not iterable: x = [x]

    # make a copy to be safe
    x = _n.array(x)
    
    # loop over the elements
    for i in range(len(x)):
        
        # Handle the weird cases
        if not x[i] in [None, _n.inf, _n.nan]:
            sig_figs = -int(_n.floor(_n.log10(abs(x[i]))))+n-1
            x[i] = _n.round(x[i], sig_figs)
        
    if iterable: return x
    else:        return x[0]
736223
def _trunc(x, minval=None, maxval=None):
    
    x = np.copy(x)
    if minval is not None:
        x[x < minval] = minval
    if maxval is not None:
        x[x > maxval] = maxval
    return x
915966
def sbesselj(x, N):
    

    nmax = N - 1;
    out = np.zeros(N, dtype=np.float64)
    z = x ** 2

    out[0] = np.sin(x) / x
    j1 = np.sin(x) / z - np.cos(x) / x

    u = 1
    v = x / (2.0 * nmax + 1.0)
    w = v
    n = nmax

    while(np.abs(v / w) > 1e-20):
        n = n + 1
        u = 1 / (1 - z * u / (4.0 * n ** 2 - 1.0))
        v *= u - 1
        w += v

    out[nmax] = w

    for n in xrange(nmax - 1, 0, -1):
        out[n] = 1.0 / ((2.0 * n + 1.0) / x - out[n + 1])

    if(np.abs(out[0]) >= np.abs(j1)):
        out[1] *= out[0]
    else:
        out[1] = j1

    for n in xrange(1, nmax):
        out[n + 1] *= out[n]

    return out
398912
def val_to_bin_bounded(edges, x):
    """"""
    nbins = len(edges) - 1
    ibin = val_to_bin(edges, x)
    ibin[ibin < 0] = 0
    ibin[ibin > nbins - 1] = nbins - 1
    return ibin
607590
def from_unit_cube(self, x):
        

        low = math.log10(self.lower_bound.value)
        up = math.log10(self.upper_bound.value)

        spread = up - low
        par = 10 ** (x * spread + low)

        return par
1106271
def _pad(X):
    
    p_above = int(np.floor(np.log2(X.shape[1])))
    M = 2 ** (p_above + 1) - X.shape[1]
    X = np.hstack((np.zeros((X.shape[0], M)), X))

    return X, M
1178318
def derivativeX(self,*args):
        '''
        
        '''
        if self.n_dims >= 4:
            j = 1
        else:
            j = 0
        if self.i_dim == j:
            return np.ones_like(*args[0])
        else:
            return np.zeros_like(*args[0])
908967
def evaluate(x, amplitude, mean, stddev):
        
        return 1.0 - Gaussian1D.evaluate(x, amplitude, mean, stddev)
760108
def _norm(self, x):
    """"""
    return tf.sqrt(tf.reduce_sum(tf.square(x), keepdims=True, axis=-1) + 1e-7)
1325310
def sbessely(x, N):
    

    out = np.zeros(N, dtype=np.float64)

    out[0] = -np.cos(x) / x
    out[1] = -np.cos(x) / (x ** 2) - np.sin(x) / x

    for n in xrange(2, N):
        out[n] = ((2.0 * n - 1.0) / x) * out[n - 1] - out[n - 2]

    return out
787287
function roundn( x, n ) {
	var scalar = pow( 10, -n );
	return round( x*scalar ) / scalar;
}
1146656
def logit_(x:Tensor)->Tensor:
    ""
    x.clamp_(1e-7, 1-1e-7)
    return (x.reciprocal_().sub_(1)).log_().neg_()
687482
def _truncate(self, x, k):
        '''  '''
        not_F = np.argsort(np.abs(x))[:-k]
        x[not_F] = 0
        return x
69479
def _Bisect(self, x, xs, ys):
        """"""
        if x <= xs[0]:
            return ys[0]
        if x >= xs[-1]:
            return ys[-1]
        i = bisect.bisect(xs, x)
        frac = 1.0 * (x - xs[i - 1]) / (xs[i] - xs[i - 1])
        y = ys[i - 1] + frac * 1.0 * (ys[i] - ys[i - 1])
        return y
1136899
def SLIT_GAUSSIAN(x,g):
    
    g /= 2
    return sqrt(log(2))/(sqrt(pi)*g)*exp(-log(2)*(x/g)**2)