Catmull-Rom spline
547392
function ( points, scale ) {

		var c = [], v3 = [],
		point, intPoint, weight, w2, w3,
		pa, pb, pc, pd;

		point = ( points.length - 1 ) * scale;
		intPoint = Math.floor( point );
		weight = point - intPoint;

		c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
		c[ 1 ] = intPoint;
		c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
		c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;

		pa = points[ c[ 0 ] ];
		pb = points[ c[ 1 ] ];
		pc = points[ c[ 2 ] ];
		pd = points[ c[ 3 ] ];

		w2 = weight * weight;
		w3 = weight * w2;

		v3[ 0 ] = interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
		v3[ 1 ] = interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
		v3[ 2 ] = interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );

		return v3;

	}
1327284
function(r, x) {
  var r1 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var r2 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  curve25519_sqrmodp(r1, x);									// r1 = x^2
  curve25519_mulasmall(r2, x, 486662);							// r2 = Ax
  curve25519_addmodp(r, r1, r2);								//  r = x^2 + Ax
  curve25519_addmodp(r1, r, curve25519_one());					// r1 = x^2 + Ax + 1
  curve25519_mulmodp(r, r1, x);									//  r = x^3 + Ax^2 + x
}
59966
def _le_butt(self, annot, p1, p2, lr):
        
        m, im, L, R, w, scol, fcol, opacity = self._le_annot_parms(annot, p1, p2)
        shift = 3
        d = shift * max(1, w)
        M = R if lr else L
        top = (M + (0, -d/2.)) * im
        bot = (M + (0, d/2.)) * im
        ap = "\nq\n%s%f %f m\n" % (opacity, top.x, top.y)
        ap += "%f %f l\n" % (bot.x, bot.y)
        ap += "%g w\n" % w
        ap += scol + "s\nQ\n"
        return ap
706803
def get_spline_values(filt, inp, nr_per_dec=None):
    """

    # Standard DLF
    if nr_per_dec == 0:
        return filt.base/inp[:, None], inp

    # Get min and max required out-values (depends on filter and inp-value)
    outmax = filt.base[-1]/inp.min()
    outmin = filt.base[0]/inp.max()

    # Get pts_per_dec and define number of out-values, depending on pts_per_dec
    if nr_per_dec < 0:  # Lagged Convolution DLF
        pts_per_dec = 1/np.log(filt.factor)

        # Calculate number of output values
        nout = int(np.ceil(np.log(outmax/outmin)*pts_per_dec) + 1)

    else:  # Splined DLF
        pts_per_dec = nr_per_dec

        # Calculate number of output values
        nout = int(np.ceil(np.log10(outmax/outmin)*pts_per_dec) + 1)

    # Min-nout check, becaus the cubic InterpolatedUnivariateSpline needs at
    # least 4 points.
    if nr_per_dec < 0:  # Lagged Convolution DLF
        # Lagged Convolution DLF interpolates in output domain, so `new_inp`
        # needs to have at least 4 points.
        if nout-filt.base.size < 3:
            nout = filt.base.size+3

    else:  # Splined DLF
        # Splined DLF interpolates in input domain, so `out` needs to have at
        # least 4 points. This should always be the case, we're just overly
        # cautious here.
        if nout < 4:
            nout = 4

    if nr_per_dec < 0:
        # Calculate output values
        out = np.exp(np.arange(np.log(outmin), np.log(outmin) +
                               nout/pts_per_dec, 1/pts_per_dec))
        # If lagged convolution is used, we calculate the new input values, as
        # spline is carried out in the input domain.
        new_inp = inp.max()*np.exp(-np.arange(nout - filt.base.size + 1) /
                                   pts_per_dec)
    else:
        # Calculate output values
        out = 10**np.arange(np.log10(outmin), np.log10(outmin) +
                            nout/pts_per_dec, 1/pts_per_dec)

        # If spline is used, interpolation is carried out in output domain and
        # we calculate the intermediate values.
        new_inp = filt.base/inp[:, None]

    # Return output values
    return np.atleast_2d(out), new_inp
412252
def _simplify_shape(self, alist, rec=0):
        """"""
        if rec != 0:
            if len(alist) == 1:
                return alist[-1]
            return alist
        if len(alist) == 1:
            return self._simplify_shape(alist[-1], 1)
        return [self._simplify_shape(al, 1) for al in alist]
786839
function roundedRect(ctx, x, y, width, height, radius) {
    // from MDN docs
    ctx.beginPath();
    ctx.moveTo(x, y + radius);
    ctx.lineTo(x, y + height - radius);
    ctx.quadraticCurveTo(x, y + height, x + radius, y + height);
    ctx.lineTo(x + width - radius, y + height);
    ctx.quadraticCurveTo(x + width, y + height, x + width, y + height
        - radius);
    ctx.lineTo(x + width, y + radius);
    ctx.quadraticCurveTo(x + width, y, x + width - radius, y);
    ctx.lineTo(x + radius, y);
    ctx.quadraticCurveTo(x, y, x, y + radius);
    ctx.stroke();
    ctx.fill();
  }
400520
def _validate_data_dep_params(self, X):
        
        n_samples, m_features = X.shape

        # terms
        if self.terms is 'auto':
            # one numerical spline per feature
            self.terms = TermList(*[SplineTerm(feat, verbose=self.verbose) for feat in range(m_features)])

        elif self.terms is None:
            # no terms
            self.terms = TermList()

        else:
            # user-specified
            self.terms = TermList(self.terms, verbose=self.verbose)

        # add intercept
        if self.fit_intercept:
            self.terms = self.terms + Intercept()

        if len(self.terms) == 0:
            raise ValueError('At least 1 term must be specified')

        # copy over things from plural
        remove = []
        for k, v in self.__dict__.items():
            if k in self._plural:
                setattr(self.terms, k, v)
                remove.append(k)
        for k in remove:
            delattr(self, k)

        self.terms.compile(X)
322211
def spline_matrix2d(x,y,px,py,mask=None):
    ''''''
    V = np.kron(spline_matrix(x,px),spline_matrix(y,py))
    
    lenV = len(V)
    
    if mask is not None:
        indices = np.nonzero(mask.T.flatten())
        if len(indices)>1:
            indices = np.nonzero(mask.T.flatten())[1][0]
        newV=V.T[indices]
        V=newV.T
        
        V=V.reshape((V.shape[0],V.shape[1]))
        
    return V
56941
def ystep(self):
        
        """

        if self.opt['NonNegCoef'] or self.opt['NoBndryCross']:
            Y1 = self.block_sep1(self.Y)
            if self.opt['NonNegCoef']:
                Y1[Y1 < 0.0] = 0.0
            if self.opt['NoBndryCross']:
                for n in range(0, self.cri.dimN):
                    Y1[(slice(None),)*n +
                       (slice(1-self.D.shape[n], None),)] = 0.0
            self.block_sep1(self.Y)[:] = Y1
540906
def absrange_fltr(dem, rangelim):
    
    out = range_fltr(np.ma.abs(dem), *rangelim)
    #Apply mask to original input
    out = np.ma.array(dem, mask=np.ma.getmaskarray(out))
    out.set_fill_value(dem.fill_value)
    return out
1301199
def tilt_model(params, shape):
    """"""
    mx = params["mx"].value
    my = params["my"].value
    off = params["off"].value
    bg = np.zeros(shape, dtype=float) + off
    x = np.arange(bg.shape[0]) - bg.shape[0] // 2
    y = np.arange(bg.shape[1]) - bg.shape[1] // 2
    x = x.reshape(-1, 1)
    y = y.reshape(1, -1)
    bg += mx * x + my * y
    return bg
1085421
def derivatives_factory(cls, coef, degree, knots, ext, **kwargs):
        
        return cls._basis_spline_factory(coef, degree, knots, 1, ext)
577127
def spline(self):
        
        from scipy.interpolate import UnivariateSpline
        sp = UnivariateSpline(range(len(self.energies)), self.energies, k=4)
        return sp
370851
def spline_backwards_hankel(ht, htarg, opt):
    """
    # Ensure ht is all lowercase
    ht = ht.lower()

    # Only relevant for 'fht' and 'hqwe', not for 'quad'
    if ht in ['fht', 'qwe', 'hqwe']:

        # Get corresponding htarg
        if ht == 'fht':
            htarg = _check_targ(htarg, ['fhtfilt', 'pts_per_dec'])
        elif ht in ['qwe', 'hqwe']:
            htarg = _check_targ(htarg, ['rtol', 'atol', 'nquad', 'maxint',
                                'pts_per_dec', 'diff_quad', 'a', 'b', 'limit'])

        # If spline (qwe, fht) or lagged (fht)
        if opt == 'spline':

            # Issue warning
            mesg = ("\n    The use of `opt='spline'` is deprecated and will " +
                    "be removed\n    in v2.0.0; use the corresponding " +
                    "setting in `htarg`.")
            warnings.warn(mesg, DeprecationWarning)

            # Reset opt
            opt = None

            # Check pts_per_dec; set to old default values if not given
            if 'pts_per_dec' not in htarg:
                if ht == 'fht':
                    htarg['pts_per_dec'] = -1  # Lagged Convolution DLF

                elif ht in ['qwe', 'hqwe']:
                    htarg['pts_per_dec'] = 80  # Splined QWE; old default value

    return htarg, opt
1035571
def splay(vec):
    
    N2 = 2 ** int(numpy.log2( len(vec) ) / 2)
    N1 = len(vec) / N2
    return N1, N2
458706
def _profile_loglike_spline(self, x):
        
        z = []
        y = []

        yv = self._nuis_pdf.profile_bins()
        nuis_vals = self._nuis_pdf.log_value(yv) - self._nuis_log_norm
        for xtmp in x:
            zv = -1. * self._lnlfn.interp(xtmp * yv) + nuis_vals
            sp = splrep(yv, zv, k=2, s=0)

            def rf(t): return splev(t, sp, der=1)
            ix = np.argmax(splev(yv, sp))
            imin, imax = max(0, ix - 3), min(len(yv) - 1, ix + 3)
            try:
                y0 = opt.brentq(rf, yv[imin], yv[imax], xtol=1e-10)
            except:
                y0 = yv[ix]
            z0 = self.loglike(xtmp, y0)
            z.append(z0)
            y.append(y0)

        self._prof_y = np.array(y)
        self._prof_z = np.array(z)
        self._prof_z = self._prof_z.max() - self._prof_z
        
        self._prof_interp = castro.Interpolator(x, self._prof_z)
        return self._prof_y, self._prof_z
185572
def smoothline(document, coords):
	""
	element = document.createElement('path')
	path    = []

	points  = [(coords[i], coords[i+1]) for i  in range(0, len(coords), 2)]
	def pt(points):
		x0, y0 = points[0]
		x1, y1 = points[1]
		p0     = (2*x0-x1, 2*y0-y1)

		x0, y0 = points[-1]
		x1, y1 = points[-2]
		pn     = (2*x0-x1, 2*y0-y1)

		p = [p0] + points[1:-1] + [pn]

		for i in range(1, len(points)-1):
			a = p[i-1]
			b = p[i]
			c = p[i+1]

			yield lerp(a, b, 0.5), b, lerp(b, c, 0.5)


	for i, (A, B, C) in enumerate(pt(points)):
		if i == 0:
			path.append("M%s,%s Q%s,%s %s,%s" % (A[0], A[1], B[0], B[1], C[0], C[1]))
		else:
			path.append("T%s,%s" % (C[0], C[1]))

	element.setAttribute('d', ' '.join(path))
	return element