Permutes a vector, x=P*b, for dense vectors x and b.

@param p
permutation vector, p=null denotes identity
@param b
input vector
@param x
output vector, x=P*b
@param n
length of p, b and x
@return true if successful, false otherwise
494238
public static boolean cs_pvec(int [] p, DZcsa b, DZcsa x, int n)
	{
		int k ;
		if (x == null || b == null) return (false) ;	/* check inputs */
		for (k = 0 ; k < n ; k++) x.set(k, b.get(p != null ? p [k] : k)) ;
		return (true) ;
	}
335074
void pass_n(int fi, 
	      float in[],  int in0, int istride,
	      float out[], int out0, int ostride,
	      int sign, int factor, int product){
    int i = 0, j = 0;
    int k, k1;

    int m = n / factor;
    int q = n / product;
    int p_1 = product / factor;
    int jump = (factor - 1) * p_1;

    int e, e1;

    for (i = 0; i < m; i++) {
      out[out0+ostride*i]   = in[in0+istride*i];
      out[out0+ostride*i+1] = in[in0+istride*i+1]; }

    for (e = 1; e < (factor - 1) / 2 + 1; e++) {
      for (i = 0; i < m; i++) {
	int idx = i + e * m;
	int idxc = i + (factor - e) * m;
	out[out0+ostride*idx]    = in[in0+istride*idx]   + in[in0+istride*idxc];
	out[out0+ostride*idx+1]  = in[in0+istride*idx+1] + in[in0+istride*idxc+1];
	out[out0+ostride*idxc]   = in[in0+istride*idx]   - in[in0+istride*idxc];
	out[out0+ostride*idxc+1] = in[in0+istride*idx+1] - in[in0+istride*idxc+1];  }}

    /* e = 0 */

    for (i=0; i<m; i++) {
      in[in0+istride*i]   = out[out0+ostride*i];
      in[in0+istride*i+1] = out[out0+ostride*i+1]; }

    for (e1 = 1; e1 < (factor - 1) / 2 + 1; e1++){
      for (i = 0; i < m; i++){
	in[in0+istride*i]   += out[out0+ostride*(i + e1*m)];
	in[in0+istride*i+1] += out[out0+ostride*(i + e1*m)+1]; }}

    float twiddl[] = twiddle[fi][q];

    for (e = 1; e < (factor-1)/2 + 1; e++){
      int idx = e;
      float w_real, w_imag;

      int em = e * m;
      int ecm = (factor - e) * m;

      for (i = 0; i < m; i++) {
	in[in0+istride*(i+em)]    = out[out0+ostride*i];
	in[in0+istride*(i+em)+1]  = out[out0+ostride*i+1];
	in[in0+istride*(i+ecm)]   = out[out0+ostride*i];
	in[in0+istride*(i+ecm)+1] = out[out0+ostride*i+1];
      }

      for (e1 = 1; e1 < (factor - 1) / 2 + 1; e1++) {
	if (idx == 0) {
	  w_real = 1;
	  w_imag = 0; }
	else {
	  w_real =       twiddl[2*(idx-1)];
	  w_imag = -sign*twiddl[2*(idx-1)+1]; }
	for (i = 0; i < m; i++) {
	  float ap = w_real * out[out0+ostride*(i + e1 * m)];
	  float am = w_imag * out[out0+ostride*(i + (factor - e1) *m)+1];

	  float bp = w_real * out[out0+ostride*(i + e1 * m)+1];
	  float bm = w_imag * out[out0+ostride*(i + (factor - e1) *m)];

	  in[in0+istride*(i + em)]    += (ap - am);
	  in[in0+istride*(i + em)+1]  += (bp + bm);
	  in[in0+istride*(i + ecm)]   += (ap + am);
	  in[in0+istride*(i + ecm)+1] += (bp - bm);
	}
	idx += e;
	idx %= factor;
      }
    }

    i = 0;
    j = 0;

    /* k = 0 */
    for (k1 = 0; k1 < p_1; k1++) {
      out[out0+ostride*k1]   = in[in0+istride*k1];
      out[out0+ostride*k1+1] = in[in0+istride*k1+1]; }

    for (e1 = 1; e1 < factor; e1++){
      for (k1 = 0; k1 < p_1; k1++){
	out[out0+ostride*(k1 + e1 * p_1)]   = in[in0+istride*(k1 + e1 * m)];
	out[out0+ostride*(k1 + e1 * p_1)+1] = in[in0+istride*(k1 + e1 * m)+1];
      }}

    i = p_1;
    j = product;

    for (k = 1; k < q; k++) {
      for (k1 = 0; k1 < p_1; k1++) {
	out[out0+ostride*j]   = in[in0+istride*i];
	out[out0+ostride*j+1] = in[in0+istride*i+1];
	i++;
	j++;
      }
      j += jump;
    }

    i = p_1;
    j = product;

    for (k = 1; k < q; k++) {
      twiddl = twiddle[fi][k];
      for (k1 = 0; k1 < p_1; k1++) {
	for (e1 = 1; e1 < factor; e1++) {
	  float x_real = in[in0+istride*(i + e1 * m)];
	  float x_imag = in[in0+istride*(i + e1 * m)+1];

	  float w_real =       twiddl[2*(e1-1)];
	  float w_imag = -sign*twiddl[2*(e1-1)+1];

	  out[out0+ostride*(j + e1 * p_1)]   = w_real * x_real - w_imag * x_imag;
	  out[out0+ostride*(j + e1 * p_1)+1] = w_real * x_imag + w_imag * x_real;
	}
 	i++;
	j++;
      }
      j += jump;
    }
  }
1310764
void rot(int n, int[] xy, int rx, int ry) {
        if (ry == 0) {
            if (rx == 1) {
                xy[0] = n - 1 - xy[0];
                xy[1] = n - 1 - xy[1];
            }
            int t = xy[0];
            xy[0] = xy[1];
            xy[1] = t;
        }
    }
1317153
public void permutate(int[] x) {
        for (int i = 0; i < x.length; i++) {
            int j = i + nextInt(x.length - i);
            int s = x[i];
            x[i] = x[j];
            x[j] = s;
        }
    }
400342
public static boolean cmp(byte[] a, byte[] b) {
		if(a.length != b.length) {
			return false;
		}
		for(int i = 0; i < a.length; i++) {
			if(a[i] != b[i]) {
				return false;
			}
		}
		return true;
	}
39626
public static double binomialCdf(int k, double p, int n) {
        if(k<0 ||  p<0 || n<1) {
            throw new IllegalArgumentException("All the parameters must be positive and n larger than 1.");
        }
        
        k = Math.min(k, n);
        
        double probabilitySum = approxBinomialCdf(k,p,n); 
        
        return probabilitySum;
    }
681113
public boolean process( DMatrixRMaj P ) {
		if( !svd.decompose(P) )
			return false;

		svd.getU(Ut,true);
		svd.getV(V,false);
		double sv[] = svd.getSingularValues();

		SingularOps_DDRM.descendingOrder(Ut,true,sv,3,V,false);

		// compute W+, which is transposed and non-negative inverted
		for (int i = 0; i < 3; i++) {
			Wt.unsafe_set(i,i, 1.0/sv[i]);
		}

		// get the pseudo inverse
		// A+ = V*(W+)*U'
		CommonOps_DDRM.mult(V,Wt,tmp);
		CommonOps_DDRM.mult(tmp, Ut,PA);

		// Vector U, which is P*U = 0
		SpecializedOps_DDRM.subvector(V,0,3,V.numRows,false,0,ns);

		return true;
	}
118936
function(p) {

        var start = this.start;
        var end = this.end;

        if (start.cross(p, end) !== 0) return false;
        // else: cross product of 0 indicates that this line and the vector to `p` are collinear

        var length = this.length();
        if ((new g.Line(start, p)).length() > length) return false;
        if ((new g.Line(p, end)).length() > length) return false;
        // else: `p` lies between start and end of the line

        return true;
    }
294284
public static void permute( int[] perm , double []input , double[]output , int N ) {
        for (int k = 0; k < N; k++) {
            output[k] = input[perm[k]];
        }
    }
759376
boolean cmppt(float[] a, float[] b) {
        if (a[0] < b[0]) {
            return true;
        }
        if (a[0] > b[0]) {
            return false;
        }
        if (a[2] < b[2]) {
            return true;
        }
        if (a[2] > b[2]) {
            return false;
        }
        return false;
    }
784488
public static void premultiply(int[] p, int offset, int length) {
		length += offset;
		for (int i = offset; i < length; i++) {
			int rgb = p[i];
			int a = (rgb >> 24) & 0xff;
			int r = (rgb >> 16) & 0xff;
			int g = (rgb >> 8) & 0xff;
			int b = rgb & 0xff;
			float f = a * (1.0f / 255.0f);
			r *= f;
			g *= f;
			b *= f;
			p[i] = (a << 24) | (r << 16) | (g << 8) | b;
		}
	}
894894
@Override
    public IAtomContainer containerFromPermutation(int[] permutation) {
        try {
            IAtomContainer permutedContainer = (IAtomContainer) atomContainer.clone();
            IAtom[] atoms = new IAtom[atomContainer.getAtomCount()];
            for (int i = 0; i < atomContainer.getAtomCount(); i++) {
                atoms[permutation[i]] = permutedContainer.getAtom(i);
            }
            permutedContainer.setAtoms(atoms);
            return permutedContainer;
        } catch (CloneNotSupportedException c) {
            return null;
        }
    }
1331024
private static void permuteOptAln(AFPChain afpChain, int cp)
	{
		int ca2len = afpChain.getCa2Length();

		if( ca2len <= 0) {
			throw new IllegalArgumentException("No Ca2Length specified in "+afpChain);
		}

		// Allow negative cp points for convenience.
		if(cp == 0) {
			return;
		}
		if(cp <= -ca2len || cp >= ca2len) {
			// could just take cp%ca2len, but probably its a bug if abs(cp)>=ca2len
			throw new ArrayIndexOutOfBoundsException( String.format(
					"Permutation point %d must be between %d and %d for %s",
					cp, 1-ca2len,ca2len-1, afpChain.getName2() ) );
		}
		if(cp < 0) {
			cp = cp + ca2len;
		}

		// the unprocessed alignment
		int[][][] optAln = afpChain.getOptAln();
		int[] optLen = afpChain.getOptLen();

		// the processed alignment
		List<List<List<Integer>>> blocks = new ArrayList<List<List<Integer>>>(afpChain.getBlockNum()*2);

		//Update residue indices
		// newi = (oldi-cp) % N
		for(int block = 0; block < afpChain.getBlockNum(); block++) {
			if(optLen[block]<1)
				continue;

			// set up storage for the current block
			List<List<Integer>> currBlock = new ArrayList<List<Integer>>(2);
			currBlock.add( new ArrayList<Integer>());
			currBlock.add( new ArrayList<Integer>());
			blocks.add(currBlock);

			// pos = 0 case
			currBlock.get(0).add( optAln[block][0][0] );
			currBlock.get(1).add( (optAln[block][1][0]+cp ) % ca2len);

			for(int pos = 1; pos < optLen[block]; pos++) {
				//check if we need to start a new block
				//this happens when the new alignment crosses the protein terminus
				if( optAln[block][1][pos-1]+cp<ca2len &&
						optAln[block][1][pos]+cp >= ca2len) {
					currBlock = new ArrayList<List<Integer>>(2);
					currBlock.add( new ArrayList<Integer>());
					currBlock.add( new ArrayList<Integer>());
					blocks.add(currBlock);
				}
				currBlock.get(0).add( optAln[block][0][pos] );
				currBlock.get(1).add( (optAln[block][1][pos]+cp ) % ca2len);
			}
		}

		// save permuted blocks to afpChain
		assignOptAln(afpChain,blocks);
	}
404446
private void swap(Node n, Node p, Node pp) {
        if (pp == null) {
            swap(n, p);
            return;
        }

        Node nLeftChild = n.o_c;
        if (pp.o_c == p) {
            // p left child of pp
            if (p.o_c == n) {
                if (n.y_s == p) {
                    // n left child of p and no sibling
                    pp.o_c = n;
                    n.y_s = p.y_s;
                    n.o_c = p;
                    p.y_s = n;
                } else {
                    // n left child or p and sibling
                    n.y_s.y_s = n;
                    Node tmp = n.y_s;
                    n.y_s = p.y_s;
                    p.y_s = tmp;
                    pp.o_c = n;
                    n.o_c = p;
                }
            } else {
                // n right child of p
                Node tmp = p.o_c;
                n.y_s = p.y_s;
                pp.o_c = n;
                n.o_c = tmp;
                tmp.y_s = p;
                p.y_s = n;
            }
        } else {
            // p right child of pp
            if (p.o_c == n) {
                if (n.y_s == p) {
                    // n left child of p and no sibling
                    n.y_s = pp;
                    pp.o_c.y_s = n;
                    n.o_c = p;
                    p.y_s = n;
                } else {
                    // n left child of p and sibling
                    pp.o_c.y_s = n;
                    p.y_s = n.y_s;
                    n.y_s = pp;
                    n.o_c = p;
                    p.y_s.y_s = n;
                }
            } else {
                // n right child of p
                pp.o_c.y_s = n;
                n.y_s = pp;
                n.o_c = p.o_c;
                n.o_c.y_s = p;
                p.y_s = n;
            }
        }

        // hang children
        p.o_c = nLeftChild;
        if (nLeftChild != null) {
            if (nLeftChild.y_s == n) {
                nLeftChild.y_s = p;
            } else {
                nLeftChild.y_s.y_s = p;
            }
        }
    }
1261364
def permute_point(p, permutation=None):
    
    if not permutation:
        return p
    return [p[int(permutation[i])] for i in range(len(p))]
734414
@Override
  public void write (final int b)
  {
    final int nNewCount = m_nCount + 1;
    if (nNewCount > m_aBuf.length)
      m_aBuf = _enlarge (m_aBuf, Math.max (m_aBuf.length << 1, nNewCount));
    m_aBuf[m_nCount] = (byte) b;
    m_nCount = nNewCount;
  }
446279
public TernaryVector permute(TernaryVector v, 
                                 int numPermutations) {
        int[] oldPos = v.positiveDimensions();
        int[] oldNeg = v.negativeDimensions();

        // create new arrays to hold the permuted locations of the vectors's
        // positive and negative values.
        //
        // NB: we use a copy here to ensure that the function works for the 0
        // permutation (i.e. effectively a no-op);
        int[] positive = Arrays.copyOf(oldPos, oldPos.length);
        int[] negative = Arrays.copyOf(oldNeg, oldNeg.length);

        boolean isInverse = numPermutations < 0;
        
        // NB: because we use the signum and !=, this loop will work for both
        // positive and negative numbers of permutations
        int totalPermutations = Math.abs(numPermutations);

        for (int count = 1; count <= totalPermutations; ++count) {            

            // load the reordering funcion for this iteration of the permutation
            Function function = getFunction(count, v.length());

            // based on whether this is an inverse permutation, select whether
            // to use the forward or backwards mapping.
            int[] reordering = (isInverse) 
                ? function.backward : function.forward;
            
            // create a copy of the previous permuted values for positive and
            // negative.  We need this array because the permutation cannot be
            // done in place
            oldPos = Arrays.copyOf(positive, positive.length);
            oldNeg = Arrays.copyOf(negative, negative.length);
            
            // The reordering array specifies for index i the positive of i in
            // the permuted array.  Since the positive and negative indices are
            // the only non-zero indicies, we can simply create new arrays for
            // them of the same length and then set their new positions based on
            // the values in the reordering array.
            for (int i = 0; i < oldPos.length; ++i) {
                positive[i] = reordering[oldPos[i]];
            }

            for (int i = 0; i < oldNeg.length; ++i) {
                negative[i] = reordering[oldNeg[i]];
            }
        }

        return new TernaryVector(v.length(), positive, negative);
    }