Computes the child 'up' and 'down' arrays in O(n) based on the LCP table.

        Abouelhoda et al. (2004).
359998
def _compute_childtab(self, lcptab):
        
        last_index = -1
        stack = [0]
        n = len(lcptab)
        childtab_up = np.zeros(n, dtype=np.int)  # Zeros / -1 ?
        childtab_down = np.zeros(n, dtype=np.int)
        for i in xrange(n):
            while lcptab[i] < lcptab[stack[-1]]:
                last_index = stack.pop()
                if lcptab[i] <= lcptab[stack[-1]] and lcptab[stack[-1]] != lcptab[last_index]:
                    childtab_down[stack[-1]] = last_index
            if last_index != -1:
                childtab_up[i] = last_index
                last_index = -1
            stack.append(i)
        return childtab_up, childtab_down
1071582
function calcSortedIntersections(lines,y) {
    var xlist = [];
    for(var i=0; i<lines.length; i++) {
        var A = lines[i].start;
        var B = lines[i].end;
        if(A.y<y && B.y>=y || B.y<y && A.y>=y) {
            var xval = A.x + (y-A.y) / (B.y-A.y) * (B.x-A.x);
            xlist.push(xval);
        }
    }
    return xlist.sort(function(a,b) {  return a-b; });
}
795571
def p_array(self,t):
    
    if len(t)==4: t[0] = ArrayLit(t[2].children)
    elif len(t)==5: t[0] = ArrayLit(t[3].children)
    else: raise NotImplementedError('unk_len',len(t)) # pragma: no cover
552089
public static int[][] computeFloydAPSP(double costMatrix[][]) {
        int nrow = costMatrix.length;
        int[][] distMatrix = new int[nrow][nrow];
        //logger.debug("Matrix size: " + n);
        for (int i = 0; i < nrow; i++) {
            for (int j = 0; j < nrow; j++) {
                if (costMatrix[i][j] == 0) {
                    distMatrix[i][j] = 0;
                } else {
                    distMatrix[i][j] = 1;
                }
            }
        }
        return computeFloydAPSP(distMatrix);
    }
482222
def negative_directional_movement(high_data, low_data):
    
    catch_errors.check_for_input_len_diff(high_data, low_data)
    up_moves = calculate_up_moves(high_data)
    down_moves = calculate_down_moves(low_data)

    ndm = []
    for idx in range(0, len(down_moves)):
        if down_moves[idx] > up_moves[idx] and down_moves[idx] > 0:
            ndm.append(down_moves[idx])
        else:
            ndm.append(0)

    return ndm
1031923
def _populate_sgc_payoff_arrays(payoff_arrays):
    
    n = payoff_arrays[0].shape[0]  # 4*k-1
    m = (n+1)//2 - 1  # 2*k-1
    for payoff_array in payoff_arrays:
        for i in range(m):
            for j in range(m):
                payoff_array[i, j] = 0.75
            for j in range(m, n):
                payoff_array[i, j] = 0.5
        for i in range(m, n):
            for j in range(n):
                payoff_array[i, j] = 0

        payoff_array[0, m-1] = 1
        payoff_array[0, 1] = 0.5
        for i in range(1, m-1):
            payoff_array[i, i-1] = 1
            payoff_array[i, i+1] = 0.5
        payoff_array[m-1, m-2] = 1
        payoff_array[m-1, 0] = 0.5

    k = (m+1)//2
    for h in range(k):
        i, j = m + 2*h, m + 2*h
        payoff_arrays[0][i, j] = 0.75
        payoff_arrays[0][i+1, j+1] = 0.75
        payoff_arrays[1][j, i+1] = 0.75
        payoff_arrays[1][j+1, i] = 0.75
662603
function() {
    var M = this.dup(), els;
    var n = this.elements.length, k = n, i, np, kp = this.elements[0].length, p;
    do { i = k - n;
      if (M.elements[i][i] == 0) {
        for (j = i + 1; j < k; j++) {
          if (M.elements[j][i] != 0) {
            els = []; np = kp;
            do { p = kp - np;
              els.push(M.elements[i][p] + M.elements[j][p]);
            } while (--np);
            M.elements[i] = els;
            break;
          }
        }
      }
      if (M.elements[i][i] != 0) {
        for (j = i + 1; j < k; j++) {
          var multiplier = M.elements[j][i] / M.elements[i][i];
          els = []; np = kp;
          do { p = kp - np;
            // Elements with column numbers up to an including the number
            // of the row that we're subtracting can safely be set straight to
            // zero, since that's the point of this routine and it avoids having
            // to loop over and correct rounding errors later
            els.push(p <= i ? 0 : M.elements[j][p] - M.elements[i][p] * multiplier);
          } while (--np);
          M.elements[j] = els;
        }
      }
    } while (--n);
    return M;
  }
1264889
def _calc(self, y, w):
        '''

        '''
        if self.discrete:
            self.lclass_ids = weights.lag_categorical(w, self.class_ids,
                                                      ties="tryself")
        else:
            ly = weights.lag_spatial(w, y)
            self.lclass_ids, self.lag_cutoffs, self.m = self._maybe_classify(
                ly, self.m, self.lag_cutoffs)
            self.lclasses = np.arange(self.m)

        T = np.zeros((self.m, self.k, self.k))
        n, t = y.shape
        for t1 in range(t - 1):
            t2 = t1 + 1
            for i in range(n):
                T[self.lclass_ids[i, t1], self.class_ids[i, t1],
                    self.class_ids[i, t2]] += 1

        P = np.zeros_like(T)
        for i, mat in enumerate(T):
            row_sum = mat.sum(axis=1)
            row_sum = row_sum + (row_sum == 0)
            p_i = np.matrix(np.diag(1. / row_sum) * np.matrix(mat))
            P[i] = p_i
        return T, P
389126
protected static int postorder_dfs( int j , int k , int []w, int[] post, int N ) {
        final int next = N;
        final int stack = 2*N;
        int top = 0; // top of the stack
        w[stack+top] = j;
        while( top >= 0 ) {
            int p = w[stack+top]; // next index in the stack to process
            int i = w[p];         // yongest child of p

            if( i == -1 ) {
                // p has no more unordered children left to process
                top--;
                post[k++] = p;
            } else {
                w[p] = w[next+i];
                top++;
                w[stack + top] = i;
            }
        }
        return k;
    }
305202
private void computePeriod(InfoTree it1, int aVp, int aNextVp, InfoTree it2, int aStrategy) {

		int fTreeSize = it1.getSize();
		int gTreeSize = it2.getSize();

		int vpPreorder = it1.info[POST2_PRE][aVp];
		int vpRevPreorder = fTreeSize - 1 - aVp;
		int vpSize = it1.info[POST2_SIZE][aVp];

		int gSize = it2.info[POST2_SIZE][it2.getCurrentNode()];
		int gPreorder = it2.info[POST2_PRE][it2.getCurrentNode()];
		int gRevPreorder = gTreeSize - 1 - it2.getCurrentNode();

		int nextVpPreorder = -1;
		int nextVpRevPreorder = -1;
		int nextVpSize = -1;
		// count k and assign next vp values
		int k;
		if (aNextVp != -1) {
			nextVpPreorder = it1.info[POST2_PRE][aNextVp];
			nextVpRevPreorder = fTreeSize - 1 - aNextVp;
			nextVpSize = it1.info[POST2_SIZE][aNextVp];
			// if strategy==LEFT use preorder to count number of left deletions from vp to
			// vp-1
			// if strategy==RIGHT use reversed preorder
			k = aStrategy == LEFT ? nextVpPreorder - vpPreorder
					: nextVpRevPreorder - vpRevPreorder;
			if (aStrategy != previousStrategy) {
				computeIJTable(it2, gPreorder, gRevPreorder, gSize, aStrategy, gTreeSize);
			}
		} else {
			k = 1;
			computeIJTable(it2, gPreorder, gRevPreorder, gSize, aStrategy, gTreeSize);
		}

		int realStrategy = it1.info[POST2_STRATEGY][aVp];

		boolean switched = it1.isSwitched();

		double[][] tTable_copy = t.clone();

		// Q and T are visible for every i
		double[] qTable = new double[k];

		// if aVp is a leaf => precompute table T - edit distance betwen EMPTY and all
		// subforests of G

		// check if nextVp is the only child of vp
		if (vpSize - nextVpSize == 1) {
			// update delta from T table => dist between Fvp-1 and G was computed in
			// previous compute period
			if (gSize == 1) {
				setDeltaValue(it1.info[PRE2_POST][vpPreorder], it2.info[PRE2_POST][gPreorder],
						vpSize - 1, switched);
			} else {
				setDeltaValue(it1.info[PRE2_POST][vpPreorder], it2.info[PRE2_POST][gPreorder],
						t[1][0], switched);
			}
		}

		double[][] sTable;// = new double[k][gTreeSize+1];

		int gijForestPreorder;
		int previousI;
		int fForestPreorderKPrime;
		int jPrime;
		int kBis;
		int jOfIminus1;
		int gijOfIMinus1Preorder;
		int jOfI;
		double deleteFromLeft;
		double deleteFromRight;
		double match;
		int fLabel;
		int gLabel;

		// Q and T are visible for every i
		for (int i = gSize - 1; i >= 0; i--) {

			// jOfI was already computed once in spfH
			jOfI = jOfI(it2, i, gSize, gRevPreorder, gPreorder, aStrategy, gTreeSize);

			// when strategy==BOTH first LEFT then RIGHT is done

			counter += realStrategy == BOTH && aStrategy == LEFT ? (k - 1) * (jOfI + 1)
					: k * (jOfI + 1);

			// compute table S - visible for actual i

			sTable = new double[k][jOfI + 1]; // initialized outside loop? -> doesn't work

			for (int kPrime = 1; kPrime <= k; kPrime++) {

				fForestPreorderKPrime = aStrategy == LEFT ? vpPreorder + (k - kPrime)
						: it1.info[POST2_PRE][fTreeSize - 1 - (vpRevPreorder + (k - kPrime))];
				kBis = kPrime - it1.info[POST2_SIZE][it1.info[PRE2_POST][fForestPreorderKPrime]];

				// reset the minimum arguments' values
				deleteFromRight = costIns;
				deleteFromLeft = costDel;
				match = 0;

				match += aStrategy == LEFT ? kBis + nextVpSize : vpSize - k + kBis;

				if ((i + jOfI) == (gSize - 1)) {
					deleteFromRight += (vpSize - (k - kPrime));
				} else {
					deleteFromRight += qTable[kPrime - 1];
				}

				fLabel = it1.info[POST2_LABEL][it1.info[PRE2_POST][fForestPreorderKPrime]];

				for (int j = jOfI; j >= 0; j--) {
					// count dist(FkPrime, Gij) with min

					// delete from left

					gijForestPreorder = aStrategy == LEFT ? IJ[i][j]
							: it2.info[POST2_PRE][gTreeSize - 1 - IJ[i][j]];

					if (kPrime == 1) {
						// if the direction changed from the previous period to this one use i and j
						// of
						// previous strategy

						// since T is overwritten continously, thus use T_copy for getting values
						// from
						// previous period

						if (aStrategy != previousStrategy) {
							if (aStrategy == LEFT) {
								previousI = gijForestPreorder - gPreorder; // minus preorder of G
							} else {
								previousI = gTreeSize - 1
										- it2.info[RPOST2_POST][gTreeSize - 1 - gijForestPreorder]
										- gRevPreorder; // minus rev preorder of G
							}
							deleteFromLeft += tTable_copy[previousI][i + j - previousI];
						} else {
							deleteFromLeft += tTable_copy[i][j];
						}

					} else {
						deleteFromLeft += sTable[kPrime - 1 - 1][j];
					}

					// match

					match += switched
							?
							delta[it2.info[PRE2_POST][gijForestPreorder]][it1.info[PRE2_POST][fForestPreorderKPrime]]
							:
							delta[it1.info[PRE2_POST][fForestPreorderKPrime]][it2.info[PRE2_POST][gijForestPreorder]];

					jPrime = j + it2.info[POST2_SIZE][it2.info[PRE2_POST][gijForestPreorder]];

					// if root nodes of L/R Fk' and L/R Gij have different labels add the match cost
					gLabel = it2.info[POST2_LABEL][it2.info[PRE2_POST][gijForestPreorder]];

					if (fLabel != gLabel) {
						match += costMatch;
					}

					// this condition is checked many times but is not satisfied only once
					if (j != jOfI) {
						// delete from right
						deleteFromRight += sTable[kPrime - 1][j + 1];
						if (kBis == 0) {
							if (aStrategy != previousStrategy) {
								previousI = aStrategy == LEFT ? IJ[i][jPrime] - gPreorder
										: IJ[i][jPrime] - gRevPreorder;
								match += tTable_copy[previousI][i + jPrime - previousI];
							} else {
								match += tTable_copy[i][jPrime];
							}
						} else if (kBis > 0) {
							match += sTable[kBis - 1][jPrime];
						} else {
							match += gSize - (i + jPrime);
						}

					}

					// fill S table
					sTable[kPrime - 1][j] = (deleteFromLeft < deleteFromRight)
							? ((deleteFromLeft < match) ? deleteFromLeft : match)
							: ((deleteFromRight < match) ? deleteFromRight : match);

					// reset the minimum arguments' values
					deleteFromRight = costIns;
					deleteFromLeft = costDel;
					match = 0;
				}
			}

			// compute table T => add row to T
			if (realStrategy == BOTH && aStrategy == LEFT) {
				t[i] = sTable[k - 1 - 1];
			} else {
				t[i] = sTable[k - 1];
			}

			if (i > 0) {
				// compute table Q
				jOfIminus1 =
						jOfI(it2, i - 1, gSize, gRevPreorder, gPreorder, aStrategy, gTreeSize);
				if (jOfIminus1 <= jOfI) {
					for (int x = 0;
					     x < qTable.length; x++) { // copy whole column | qTable.length=k
						qTable[x] = sTable[x][jOfIminus1];
					}
				}

				// fill table delta
				if (i + jOfIminus1 < gSize) {

					gijOfIMinus1Preorder = aStrategy == LEFT
							? it2.info[POST2_PRE][gTreeSize - 1 - (gRevPreorder + (i - 1))]
							: gPreorder + (i - 1);

					// If Fk from Fk-1 differ with a single node,
					// then Fk without the root node is Fk-1 and the distance value has to be taken
					// from previous T table.
					if (k - 1 - 1 < 0) {
						if (aStrategy != previousStrategy) {
							previousI = aStrategy == LEFT ? IJ[i][jOfIminus1] - gPreorder
									: IJ[i][jOfIminus1] - gRevPreorder;
							setDeltaValue(it1.info[PRE2_POST][vpPreorder],
									it2.info[PRE2_POST][gijOfIMinus1Preorder],
									tTable_copy[previousI][i + jOfIminus1 - previousI], switched);
						} else {
							setDeltaValue(it1.info[PRE2_POST][vpPreorder],
									it2.info[PRE2_POST][gijOfIMinus1Preorder],
									tTable_copy[i][jOfIminus1], switched);
						}
					} else {
						setDeltaValue(it1.info[PRE2_POST][vpPreorder],
								it2.info[PRE2_POST][gijOfIMinus1Preorder],
								sTable[k - 1 - 1][jOfIminus1], switched);
					}
				}
			}

		}
		previousStrategy = aStrategy;
	}
231217
private static void gaussian(float a[][],
	                             int index[]) {
		int n = index.length;
		float c[] = new float[n];
		// Initialize the index
		for (int i = 0; i < n; ++i) {
			index[i] = i;
		}
		// Find the rescaling factors, one from each row
		for (int i = 0; i < n; ++i){
			float c1 = 0;
			for (int j = 0; j < n; ++j){
				float c0 = Math.abs(a[i][j]);
				if (c0 > c1) {
					c1 = c0;
				}
			}
			c[i] = c1;
		}
		// Search the pivoting element from each column
		int k = 0;
		for (int j = 0; j < n - 1; ++j){
			float pi1 = 0;
			for (int i = j; i < n; ++i){
				float pi0 = Math.abs(a[index[i]][j]);
				pi0 /= c[index[i]];
				if (pi0 > pi1) {

					pi1 = pi0;
					k = i;
				}
			}
			// Interchange rows according to the pivoting order
			int itmp = index[j];
			index[j] = index[k];
			index[k] = itmp;
			for (int i = j + 1; i < n; ++i){
				float pj = a[index[i]][j] / a[index[j]][j];
				// Record pivoting ratios below the diagonal
				a[index[i]][j] = pj;

				// Modify other elements accordingly
				for (int l = j + 1; l < n; ++l){
					a[index[i]][l] -= pj * a[index[j]][l];
				}
			}
		}
	}
537472
private static void compute(int[] in, int[] out, int width, int height, int radius)
    {
        final int widthMinus1 = width - 1;
        final int tableSize = 2 * radius + 1;
        final int[] divide = new int[Constant.UNSIGNED_BYTE * tableSize];

        for (int i = 0; i < Constant.UNSIGNED_BYTE * tableSize; i++)
        {
            divide[i] = i / tableSize;
        }

        int inIndex = 0;
        for (int y = 0; y < height; y++)
        {
            compute(in, out, y, inIndex, divide, width, widthMinus1, height, radius);
            inIndex += width;
        }
    }
123484
public static void sort(int n, int[] Xip, int Xip_offset, int[] Xlen, int Xlen_offset,
			double[] LU, int[] Tp, int[] Tj, double[] Tx, int[] W)
	{
		/*int[]*/double[] Xi ;
		double[] Xx ;
		int p, i, j, nz, tp, xlen, pend ;
		int[] len = new int[1] ;
		int[] Xi_offset = new int[1] ;
		int[] Xx_offset = new int[1] ;

		ASSERT (klu_valid_LU (n, FALSE, Xip, Xip_offset, Xlen, Xlen_offset, LU)) ;

		/* count the number of entries in each row of L or U */
		for (i = 0 ; i < n ; i++)
		{
			W [i] = 0 ;
		}
		for (j = 0 ; j < n ; j++)
		{
			Xi = Xx = GET_POINTER (LU, Xip, Xip_offset, Xlen, Xlen_offset, Xi_offset, Xx_offset, j, len) ;
			for (p = 0 ; p < len[0] ; p++)
			{
				W [(int) Xi [Xi_offset[0] + p]]++ ;
			}
		}

		/* construct the row pointers for T */
		nz = 0 ;
		for (i = 0 ; i < n ; i++)
		{
			Tp [i] = nz ;
			nz += W [i] ;
		}
		Tp [n] = nz ;
		for (i = 0 ; i < n ; i++)
		{
			W [i] = Tp [i] ;
		}

		/* transpose the matrix into Tp, Ti, Tx */
		for (j = 0 ; j < n ; j++)
		{
			Xi = Xx = GET_POINTER (LU, Xip, Xip_offset, Xlen, Xlen_offset, Xi_offset, Xx_offset, j, len) ;
			for (p = 0 ; p < len[0] ; p++)
			{
				tp = W [(int) Xi [Xi_offset[0] + p]]++ ;
				Tj [tp] = j ;
				Tx [tp] = Xx [Xx_offset[0] + p] ;
			}
		}

		/* transpose the matrix back into Xip, Xlen, Xi, Xx */
		for (j = 0 ; j < n ; j++)
		{
			W [j] = 0 ;
		}
		for (i = 0 ; i < n ; i++)
		{
			pend = Tp [i+1] ;
			for (p = Tp [i] ; p < pend ; p++)
			{
				j = Tj [p] ;
				Xi = Xx = GET_POINTER (LU, Xip, Xip_offset, Xlen, Xlen_offset, Xi_offset, Xx_offset, j, len) ;
				xlen = W [j]++ ;
				Xi [Xi_offset[0] + xlen] = i ;
				Xx [Xx_offset[0] + xlen] = Tx [p] ;
			}
		}

		ASSERT (klu_valid_LU (n, FALSE, Xip, Xip_offset, Xlen, Xlen_offset, LU)) ;
	}
18855
function(T, SA, C, B, n, k) {
        var b, i, j;
        var c0, c1;
        /* compute SAl */
        if (C === B) { getCounts(T, C, n, k); }
        getBuckets(C, B, k, false); /* find starts of buckets */
        j = n - 1;
        b = B[c1 = T[j]];
        j--;
        SA[b++] = (T[j] < c1) ? ~j : j;
        for (i = 0; i < n; i++) {
            if ((j = SA[i]) > 0) {
                ASSERT(T[j] >= T[j+1]);
                if ((c0 = T[j]) !== c1) { B[c1] = b; b = B[c1 = c0]; }
                ASSERT(i < b);
                j--;
                SA[b++] = (T[j] < c1) ? ~j : j;
                SA[i] = 0;
            } else if (j < 0) {
                SA[i] = ~j;
            }
        }
        /* compute SAs */
        if (C === B) { getCounts(T, C, n, k); }
        getBuckets(C, B, k, 1); /* find ends of buckets */
        for (i = n-1, b = B[c1 = 0]; i >= 0; i--) {
            if ((j = SA[i]) > 0) {
                ASSERT(T[j] <= T[j+1]);
                if ((c0 = T[j]) !== c1) { B[c1] = b; b = B[c1 = c0]; }
                ASSERT(b <= i);
                j--;
                SA[--b] = (T[j] > c1) ? ~(j+1) : j;
                SA[i] = 0;
            }
        }
    }
530410
def _compute(self):
        """"""
        self._x_pos = [
            (x + 1) / self._order for x in range(self._order)
        ] if self._order != 1 else [.5]  # Center if only one value

        previous = [[self.zero, self.zero] for i in range(self._len)]
        for i, serie in enumerate(self.series):
            y_height = -sum(serie.safe_values) / 2
            all_x_pos = [0] + self._x_pos
            serie.points = []
            for j, value in enumerate(serie.values):
                poly = []
                poly.append((all_x_pos[i], previous[j][0]))
                poly.append((all_x_pos[i], previous[j][1]))
                previous[j][0] = y_height
                y_height = previous[j][1] = y_height + value
                poly.append((all_x_pos[i + 1], previous[j][1]))
                poly.append((all_x_pos[i + 1], previous[j][0]))
                serie.points.append(poly)

        val_max = max(list(map(sum, cut(self.series, 'values'))) + [self.zero])
        self._box.ymin = -val_max
        self._box.ymax = val_max

        if self.range and self.range[0] is not None:
            self._box.ymin = self.range[0]

        if self.range and self.range[1] is not None:
            self._box.ymax = self.range[1]
419811
function computeTableHeaderCellIndexes(t) {
                var matrix = [];
                var lookup = {};
                var thead = t.getElementsByTagName('THEAD')[0];
                var trs = thead.getElementsByTagName('TR');

                for (var i = 0; i < trs.length; i++) {
                    var cells = trs[i].cells;
                    for (var j = 0; j < cells.length; j++) {
                        var c = cells[j];

                        var rowIndex = c.parentNode.rowIndex;
                        var cellId = rowIndex + "-" + c.cellIndex;
                        var rowSpan = c.rowSpan || 1;
                        var colSpan = c.colSpan || 1
                        var firstAvailCol;
                        if (typeof(matrix[rowIndex]) == "undefined") {
                            matrix[rowIndex] = [];
                        }
                        // Find first available column in the first row
                        for (var k = 0; k < matrix[rowIndex].length + 1; k++) {
                            if (typeof(matrix[rowIndex][k]) == "undefined") {
                                firstAvailCol = k;
                                break;
                            }
                        }
                        lookup[cellId] = firstAvailCol;
                        for (var k = rowIndex; k < rowIndex + rowSpan; k++) {
                            if (typeof(matrix[k]) == "undefined") {
                                matrix[k] = [];
                            }
                            var matrixrow = matrix[k];
                            for (var l = firstAvailCol; l < firstAvailCol + colSpan; l++) {
                                matrixrow[l] = "x";
                            }
                        }
                    }
                }
                return lookup;
            }
1314882
def fpbspl(t, n, k, x, l, h, hh):
    
    h[0] = 1.0
    for j in range(1, k + 1):
        hh[0:j] = h[0:j]
        h[0] = 0.0
        for i in range(j):
            li = l+i
            f = hh[i]/(t[li] - t[li - j])
            h[i] = h[i] + f*(t[li] - x)
            h[i + 1] = f*(x - t[li - j])