Segregate Series based on type and coerce into matrices.
    Needs to handle a lot of exceptional cases.
773310
def init_dict(data, index, columns, dtype=None):
    
    if columns is not None:
        from pandas.core.series import Series
        arrays = Series(data, index=columns, dtype=object)
        data_names = arrays.index

        missing = arrays.isnull()
        if index is None:
            # GH10856
            # raise ValueError if only scalars in dict
            index = extract_index(arrays[~missing])
        else:
            index = ensure_index(index)

        # no obvious "empty" int column
        if missing.any() and not is_integer_dtype(dtype):
            if dtype is None or np.issubdtype(dtype, np.flexible):
                # GH#1783
                nan_dtype = object
            else:
                nan_dtype = dtype
            val = construct_1d_arraylike_from_scalar(np.nan, len(index),
                                                     nan_dtype)
            arrays.loc[missing] = [val] * missing.sum()

    else:
        keys = com.dict_keys_to_ordered_list(data)
        columns = data_names = Index(keys)
        # GH#24096 need copy to be deep for datetime64tz case
        # TODO: See if we can avoid these copies
        arrays = [data[k] if not is_datetime64tz_dtype(data[k]) else
                  data[k].copy(deep=True) for k in keys]
    return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
990536
def _separable_series3(h, N=1, verbose=False):
    

    hx, hy, hz = [], [], []
    res = h.copy()
    for i in range(N):
        _hx, _hy, _hz, P = _splitrank3(res, verbose=verbose)
        res -= P
        hx.append(_hx)
        hy.append(_hy)
        hz.append(_hz)
    return np.array(list(zip(hx, hy, hz)))
1233496
def matrix_chain_mult(M):
    
    opt, arg = matrix_mult_opt_order(M)
    return _apply_order(M, arg, 0, len(M)-1)
1130759
def SMA(Series, N, M=1):
    
    ret = []
    i = 1
    length = len(Series)
    # 跳过X中前面几个 nan 值
    while i < length:
        if np.isnan(Series.iloc[i]):
            i += 1
        else:
            break
    preY = Series.iloc[i]  # Y'
    ret.append(preY)
    while i < length:
        Y = (M * Series.iloc[i] + (N - M) * preY) / float(N)
        ret.append(Y)
        preY = Y
        i += 1
    return pd.Series(ret, index=Series.tail(len(ret)).index)
335643
def series2df(Series, layer=2, split_sign = '_'):
    """"""
    try:
        Series.columns
        Series = Series.iloc[:,0]
    except:
        pass
    
    def _helper(x, layer=2):
        try:
            return flatten_dict(ast.literal_eval(x), layers=layer, split_sign=split_sign)
        except:
            try:
                return flatten_dict(x, layers=layer, split_sign=split_sign)
            except:
                return x
    
    df=pd.DataFrame(Series.apply(_helper).tolist())
    
    return df
1059134
def from_series(series):
        
        result = PercentRankTransform()
        result.cdf = series.values
        result.bin_edges = series.index.values[1:-1]
        return result
231739
def sparse(numRows, numCols, colPtrs, rowIndices, values):
        
        return SparseMatrix(numRows, numCols, colPtrs, rowIndices, values)
1053513
function coalesce(ranges) {
  if (!ranges.length) return [];
  var results=[ranges[0]];
  ranges.reduce(function (a,b) {
    var prev=results.length-1;
    if (a[a.length-1]===pred(b[0])) {
      return results[prev]=results[prev][0]+b[b.length-1];
    }
    results.push(b);
    return b;
  });
  return results.reduce(function (results,range) {
    if (range.length===2 && range[0]===pred(range[1])) {
      results.push(range[0]);
      results.push(range[1]);
    } else {
      results.push(range);
    }
    return results;
  },[]);
}
105926
def coarsen_matrix(Z, xlevel=0, ylevel=0, method='average'):
    

    # coarsen x
    if not ylevel:
        Z_coarsened = Z
    else:
        temp = []
        for z in Z: temp.append(coarsen_array(z, ylevel, method))
        Z_coarsened = _n.array(temp)

    # coarsen y
    if xlevel:
        Z_coarsened = Z_coarsened.transpose()
        temp = []
        for z in Z_coarsened: temp.append(coarsen_array(z, xlevel, method))
        Z_coarsened = _n.array(temp).transpose()

    return Z_coarsened



    # first coarsen the columns (if necessary)
    if ylevel:
        Z_ycoarsened = []
        for c in Z: Z_ycoarsened.append(coarsen_array(c, ylevel, method))
        Z_ycoarsened = _n.array(Z_ycoarsened)

    # now coarsen the rows
    if xlevel: return coarsen_array(Z_ycoarsened, xlevel, method)
    else:      return _n.array(Z_ycoarsened)
984774
function blockMult(a, b, rows, cols) {
                            // For small matrices, resort to naive multiplication.
                            if (rows <= 512 || cols <= 512) {
                                return a.mmul(b); // a is equivalent to this
                            }

                            // Apply dynamic padding.
                            if ((rows % 2 === 1) && (cols % 2 === 1)) {
                                a = embed(a, rows + 1, cols + 1);
                                b = embed(b, rows + 1, cols + 1);
                            } else if (rows % 2 === 1) {
                                a = embed(a, rows + 1, cols);
                                b = embed(b, rows + 1, cols);
                            } else if (cols % 2 === 1) {
                                a = embed(a, rows, cols + 1);
                                b = embed(b, rows, cols + 1);
                            }

                            var halfRows = parseInt(a.rows / 2);
                            var halfCols = parseInt(a.columns / 2);
                            // Subdivide input matrices.
                            var a11 = a.subMatrix(0, halfRows - 1, 0, halfCols - 1);
                            var b11 = b.subMatrix(0, halfRows - 1, 0, halfCols - 1);

                            var a12 = a.subMatrix(0, halfRows - 1, halfCols, a.columns - 1);
                            var b12 = b.subMatrix(0, halfRows - 1, halfCols, b.columns - 1);

                            var a21 = a.subMatrix(halfRows, a.rows - 1, 0, halfCols - 1);
                            var b21 = b.subMatrix(halfRows, b.rows - 1, 0, halfCols - 1);

                            var a22 = a.subMatrix(halfRows, a.rows - 1, halfCols, a.columns - 1);
                            var b22 = b.subMatrix(halfRows, b.rows - 1, halfCols, b.columns - 1);

                            // Compute intermediate values.
                            var m1 = blockMult(Matrix.add(a11, a22), Matrix.add(b11, b22), halfRows, halfCols);
                            var m2 = blockMult(Matrix.add(a21, a22), b11, halfRows, halfCols);
                            var m3 = blockMult(a11, Matrix.sub(b12, b22), halfRows, halfCols);
                            var m4 = blockMult(a22, Matrix.sub(b21, b11), halfRows, halfCols);
                            var m5 = blockMult(Matrix.add(a11, a12), b22, halfRows, halfCols);
                            var m6 = blockMult(Matrix.sub(a21, a11), Matrix.add(b11, b12), halfRows, halfCols);
                            var m7 = blockMult(Matrix.sub(a12, a22), Matrix.add(b21, b22), halfRows, halfCols);

                            // Combine intermediate values into the output.
                            var c11 = Matrix.add(m1, m4);
                            c11.sub(m5);
                            c11.add(m7);
                            var c12 = Matrix.add(m3, m5);
                            var c21 = Matrix.add(m2, m4);
                            var c22 = Matrix.sub(m1, m2);
                            c22.add(m3);
                            c22.add(m6);

                            //Crop output to the desired size (undo dynamic padding).
                            var resultat = Matrix.zeros(2 * c11.rows, 2 * c11.columns);
                            resultat = resultat.setSubMatrix(c11, 0, 0);
                            resultat = resultat.setSubMatrix(c12, c11.rows, 0);
                            resultat = resultat.setSubMatrix(c21, 0, c11.columns);
                            resultat = resultat.setSubMatrix(c22, c11.rows, c11.columns);
                            return resultat.subMatrix(0, rows - 1, 0, cols - 1);
                        }
194635
private function mixColumns()
    {
        $s0 = $s1 = $s2 = $s3 = '';

        // There are Nb columns
        for ($i = 0; $i < self::$Nb; $i++) {
            $s0 = $this->s[0][$i];
            $s1 = $this->s[1][$i];
            $s2 = $this->s[2][$i];
            $s3 = $this->s[3][$i];

            $this->s[0][$i] = $this->mult(0x02, $s0) ^ $this->mult(0x03, $s1) ^ $this->mult(0x01, $s2) ^ $this->mult(0x01, $s3);
            $this->s[1][$i] = $this->mult(0x01, $s0) ^ $this->mult(0x02, $s1) ^ $this->mult(0x03, $s2) ^ $this->mult(0x01, $s3);
            $this->s[2][$i] = $this->mult(0x01, $s0) ^ $this->mult(0x01, $s1) ^ $this->mult(0x02, $s2) ^ $this->mult(0x03, $s3);
            $this->s[3][$i] = $this->mult(0x03, $s0) ^ $this->mult(0x01, $s1) ^ $this->mult(0x01, $s2) ^ $this->mult(0x02, $s3);
        }
    }
502498
def _separable_approx2(h, N=1):
    
    return np.cumsum([np.outer(fy, fx) for fy, fx in _separable_series2(h, N)], 0)
1327131
private void _symmetricTred2 ()
  {
    // This is derived from the Algol procedures tred2 by
    // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
    // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
    // Fortran subroutine in EISPACK.
    for (int j = 0; j < m_nDim; j++)
    {
      m_aEVd[j] = m_aEigenVector[m_nDim - 1][j];
    }

    // Householder reduction to tridiagonal form.

    for (int i = m_nDim - 1; i > 0; i--)
    {
      // Scale to avoid under/overflow.
      double scale = 0.0;
      double h = 0.0;
      for (int k = 0; k < i; k++)
        scale += MathHelper.abs (m_aEVd[k]);
      if (scale == 0.0)
      {
        m_aEVe[i] = m_aEVd[i - 1];
        for (int j = 0; j < i; j++)
        {
          m_aEVd[j] = m_aEigenVector[i - 1][j];
          m_aEigenVector[i][j] = 0.0;
          m_aEigenVector[j][i] = 0.0;
        }
      }
      else
      {
        // Generate Householder vector.

        for (int k = 0; k < i; k++)
        {
          m_aEVd[k] /= scale;
          h += m_aEVd[k] * m_aEVd[k];
        }
        double f = m_aEVd[i - 1];
        double g = Math.sqrt (h);
        if (f > 0)
        {
          g = -g;
        }
        m_aEVe[i] = scale * g;
        h -= f * g;
        m_aEVd[i - 1] = f - g;
        for (int j = 0; j < i; j++)
        {
          m_aEVe[j] = 0.0;
        }

        // Apply similarity transformation to remaining columns.
        for (int j = 0; j < i; j++)
        {
          f = m_aEVd[j];
          m_aEigenVector[j][i] = f;
          g = m_aEVe[j] + m_aEigenVector[j][j] * f;
          for (int k = j + 1; k <= i - 1; k++)
          {
            g += m_aEigenVector[k][j] * m_aEVd[k];
            m_aEVe[k] += m_aEigenVector[k][j] * f;
          }
          m_aEVe[j] = g;
        }
        f = 0.0;
        for (int j = 0; j < i; j++)
        {
          m_aEVe[j] /= h;
          f += m_aEVe[j] * m_aEVd[j];
        }
        final double hh = f / (h + h);
        for (int j = 0; j < i; j++)
        {
          m_aEVe[j] -= hh * m_aEVd[j];
        }
        for (int j = 0; j < i; j++)
        {
          f = m_aEVd[j];
          g = m_aEVe[j];
          for (int k = j; k <= i - 1; k++)
          {
            m_aEigenVector[k][j] -= (f * m_aEVe[k] + g * m_aEVd[k]);
          }
          m_aEVd[j] = m_aEigenVector[i - 1][j];
          m_aEigenVector[i][j] = 0.0;
        }
      }
      m_aEVd[i] = h;
    }

    // Accumulate transformations.
    for (int i = 0; i < m_nDim - 1; i++)
    {
      m_aEigenVector[m_nDim - 1][i] = m_aEigenVector[i][i];
      m_aEigenVector[i][i] = 1.0;
      final double h = m_aEVd[i + 1];
      if (h != 0.0)
      {
        for (int k = 0; k <= i; k++)
        {
          m_aEVd[k] = m_aEigenVector[k][i + 1] / h;
        }
        for (int j = 0; j <= i; j++)
        {
          double g = 0.0;
          for (int k = 0; k <= i; k++)
          {
            g += m_aEigenVector[k][i + 1] * m_aEigenVector[k][j];
          }
          for (int k = 0; k <= i; k++)
          {
            m_aEigenVector[k][j] -= g * m_aEVd[k];
          }
        }
      }
      for (int k = 0; k <= i; k++)
      {
        m_aEigenVector[k][i + 1] = 0.0;
      }
    }
    for (int j = 0; j < m_nDim; j++)
    {
      m_aEVd[j] = m_aEigenVector[m_nDim - 1][j];
      m_aEigenVector[m_nDim - 1][j] = 0.0;
    }
    m_aEigenVector[m_nDim - 1][m_nDim - 1] = 1.0;
    m_aEVe[0] = 0.0;
  }
982022
def non_decreasing_series(n, size):
    ''''''

    if size == 1:
        return [[a] for a in range(n)]
    else:
        lc = non_decreasing_series(n, size-1)
        ll = []
        for l in lc:
            last = l[-1]
            for i in range(last, n):
                e = l + [i]
                ll.append(e)
        return ll
411146
function assembleSeriesWithCategoryAxis(series) {
    var tables = [];
    zrUtil.each(series, function (group, key) {
        var categoryAxis = group.categoryAxis;
        var valueAxis = group.valueAxis;
        var valueAxisDim = valueAxis.dim;

        var headers = [' '].concat(zrUtil.map(group.series, function (series) {
            return series.name;
        }));
        var columns = [categoryAxis.model.getCategories()];
        zrUtil.each(group.series, function (series) {
            columns.push(series.getRawData().mapArray(valueAxisDim, function (val) {
                return val;
            }));
        });
        // Assemble table content
        var lines = [headers.join(ITEM_SPLITER)];
        for (var i = 0; i < columns[0].length; i++) {
            var items = [];
            for (var j = 0; j < columns.length; j++) {
                items.push(columns[j][i]);
            }
            lines.push(items.join(ITEM_SPLITER));
        }
        tables.push(lines.join('\n'));
    });
    return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
}
625773
def colgen(*lstcol,**kargs):
    """"""
    if len(lstcol) < 2:
        lstcol *= 2
    trans = kargs.get("trans", lambda x,y,z: (x,y,z))
    while 1:
        for i in range(len(lstcol)):
            for j in range(len(lstcol)):
                for k in range(len(lstcol)):
                    if i != j or j != k or k != i:
                        yield trans(lstcol[(i+j)%len(lstcol)],lstcol[(j+k)%len(lstcol)],lstcol[(k+i)%len(lstcol)])
424597
def combine(items, k=None):
    
    length_items = len(items)
    lengths = [len(i) for i in items]
    length = reduce(lambda x, y: x * y, lengths)
    repeats = [reduce(lambda x, y: x * y, lengths[i:])
               for i in range(1, length_items)] + [1]
    if k is not None:
        k = k % length
        # Python division by default is integer division (~ floor(a/b))
        indices = [old_div((k % (lengths[i] * repeats[i])), repeats[i])
                   for i in range(length_items)]
        return [items[i][indices[i]] for i in range(length_items)]
    else:
        matrix = []
        for i, item in enumerate(items):
            row = []
            for subset in item:
                row.extend([subset] * repeats[i])
            times = old_div(length, len(row))
            matrix.append(row * times)
        # Transpose the matrix or return the columns instead rows
        return list(zip(*matrix))