Various peephole optimizations.
179985
private static CompilerPass createPeepholeOptimizationsPass(
      AbstractCompiler compiler, String passName) {
    final boolean late = false;
    final boolean useTypesForOptimization = compiler.getOptions().useTypesForLocalOptimization;
    List<AbstractPeepholeOptimization> optimizations = new ArrayList<>();
    optimizations.add(new MinimizeExitPoints());
    optimizations.add(new PeepholeMinimizeConditions(late));
    optimizations.add(new PeepholeSubstituteAlternateSyntax(late));
    optimizations.add(new PeepholeReplaceKnownMethods(late, useTypesForOptimization));
    optimizations.add(new PeepholeRemoveDeadCode());
    if (compiler.getOptions().j2clPassMode.shouldAddJ2clPasses()) {
      optimizations.add(new J2clEqualitySameRewriterPass(useTypesForOptimization));
      optimizations.add(new J2clStringValueOfRewriterPass());
    }
    optimizations.add(new PeepholeFoldConstants(late, useTypesForOptimization));
    optimizations.add(new PeepholeCollectPropertyAssignments());
    return new PeepholeOptimizationsPass(compiler, passName, optimizations);
  }
996400
def adapt(self, d, x):
        
        y = np.dot(self.w, x)
        e = d - y
        nu = self.mu / (self.eps + np.dot(x, x))
        self.w += nu * x * e**3
765665
protected void adjustElipseForBinaryBias( EllipseRotated_F64 ellipse ) {
		ellipse.center.x += 0.5;
		ellipse.center.y += 0.5;

		ellipse.a += 0.5;
		ellipse.b += 0.5;
	}
856584
def main(dimension, iterations):
    
    objective_function = minimize(functions.sphere)
    stopping_condition = max_iterations(iterations)
    (solution, metrics) = optimize(objective_function=objective_function,
                                   domain=Domain(-5.12, 5.12, dimension),
                                   stopping_condition=stopping_condition,
                                   parameters={'seed': 3758117674,
                                               'rho': 1.0, 'e_s': 15, 'e_f': 5},
                                   velocity_update=gc_velocity_update,
                                   parameter_update=update_rho,
                                   measurements=[fitness_measurement])
    return solution
622969
@Managed
   @ManagedDescription("Index optimization ")
   public void optimize()
   {
      if (handler instanceof SearchIndex)
      {
         try
         {
            if (isSuspended.get())
            {
               resume();

               try
               {
                  ((SearchIndex)handler).getIndex().optimize();
               }
               finally
               {
                  suspend();
               }
            }
            else
            {
               ((SearchIndex)handler).getIndex().optimize();
            }
         }
         catch (IOException e)
         {
            LOG.error(e.getMessage(), e);
         }
         catch (ResumeException e)
         {
            LOG.error(e.getMessage(), e);
         }
         catch (SuspendException e)
         {
            LOG.error(e.getMessage(), e);
         }
      }
      else
      {
         LOG.error("This kind of QuerHandler class doesn't support index optimization.");
      }
   }
1034205
function(instance, searchNode, x, y, cost) {
        var adjacentCoordinateX = searchNode.x+x;
        var adjacentCoordinateY = searchNode.y+y;

        if ((pointsToAvoid[adjacentCoordinateY] === undefined ||
             pointsToAvoid[adjacentCoordinateY][adjacentCoordinateX] === undefined) &&
            isTileWalkable(collisionGrid, acceptableTiles, adjacentCoordinateX, adjacentCoordinateY, searchNode)) {
            var node = coordinateToNode(instance, adjacentCoordinateX,
                adjacentCoordinateY, searchNode, cost);

            if (node.list === undefined) {
                node.list = OPEN_LIST;
                instance.openList.push(node);
            } else if (searchNode.costSoFar + cost < node.costSoFar) {
                node.costSoFar = searchNode.costSoFar + cost;
                node.parent = searchNode;
                instance.openList.updateItem(node);
            }
        }
    }
571685
void optimizeReset() {
    FlatParagraphTools flatPara = new FlatParagraphTools(xContext);
    flatPara.markFlatParasAsChecked(resetFrom + divNum, resetTo + divNum, isChecked);
    resetCheck = false;
  }
370416
def uinit(self, ushape):
        """"""

        if  self.opt['Y0'] is None:
            return np.zeros(ushape, dtype=self.dtype)
        else:
            # If initial Y is non-zero, initial U is chosen so that
            # the relevant dual optimality criterion (see (3.10) in
            # boyd-2010-distributed) is satisfied.
            Yss = np.sqrt(np.sum(self.Y**2, axis=self.S.ndim, keepdims=True))
            return (self.lmbda/self.rho)*sl.zdivide(self.Y, Yss)
1310323
void performOptimizations() {
    checkState(options.shouldOptimize());
    List<PassFactory> optimizations = getPassConfig().getOptimizations();
    if (optimizations.isEmpty()) {
      return;
    }

    phaseOptimizer = createPhaseOptimizer();
    phaseOptimizer.consume(optimizations);
    phaseOptimizer.process(externsRoot, jsRoot);
    phaseOptimizer = null;
  }
1179790
private double adjustBetaSign( double beta , List<Point3D_F64> nullPts ) {
		if( beta == 0 )
			return 0;

		int N = alphas.numRows;

		int positiveCount = 0;

		for( int i = 0; i < N; i++ ) {
			double z = 0;
			for( int j = 0; j < numControl; j++ ) {
				Point3D_F64 c = nullPts.get(j);
				z += alphas.get(i,j)*c.z;
			}

			if( z > 0 )
				positiveCount++;
		}

		if( positiveCount < N/2 )
			beta *= -1;

		return beta;
	}
651848
private void calculateMinimapBounds() {
        float ratioX = Constants.MINIMAP_MAX_SIZE / optimalPageWidth;
        float ratioY = Constants.MINIMAP_MAX_SIZE / optimalPageHeight;
        float ratio = Math.min(ratioX, ratioY);
        float minimapWidth = optimalPageWidth * ratio;
        float minimapHeight = optimalPageHeight * ratio;
        minimapBounds = new RectF(getWidth() - 5 - minimapWidth, 5, getWidth() - 5, 5 + minimapHeight);
        calculateMinimapAreaBounds();
    }
680802
void adjustOffsets(final double pNorthOrWest, final double pSouthOrEast,
					   final boolean isLatitude, final int pExtraSize) {
		final long min;
		final long max;
		final long deltaX;
		final long deltaY;
		if (isLatitude) {
			min = getLongPixelYFromLatitude(pNorthOrWest);
			max = getLongPixelYFromLatitude(pSouthOrEast);
			deltaX = 0;
			deltaY = getScrollableOffset(min, max, mMercatorMapSize, mIntrinsicScreenRectProjection.height(), pExtraSize);
		} else {
			min = getLongPixelXFromLongitude(pNorthOrWest);
			max = getLongPixelXFromLongitude(pSouthOrEast);
			deltaX = getScrollableOffset(min, max, mMercatorMapSize, mIntrinsicScreenRectProjection.width(), pExtraSize);
			deltaY = 0;
		}
		adjustOffsets(deltaX, deltaY);
	}
446107
public static void optimizeAln(FatCatParameters params, AFPChain afpChain,Atom[] ca1, Atom[] ca2) throws StructureException
	{

		int minLen = afpChain.getMinLen();
		int fragLen = params.getFragLen();


		long optStart = System.currentTimeMillis();
		int     i, a, k, p1, p2, bk, b1, b2, e1, e2, a1, a2;
		int     iniLen;
		int[][]     iniSet = new int[2][minLen];
		int     maxi = 100;

		int[][][] optAln = afpChain.getOptAln();
		int[] optLen = afpChain.getOptLen();

		int maxTra = params.getMaxTra();
		double[] optRmsd = afpChain.getOptRmsd();

		int blockNum = afpChain.getBlockNum();

		if(optAln == null)      {
			optAln     = new int[maxTra+1][2][minLen];
			optLen     = new int[maxTra+1];
			afpChain.setOptLen(optLen);
			optRmsd    = new double[maxTra+1];
			afpChain.setOptRmsd(optRmsd);
		}

		List<AFP> afpSet = afpChain.getAfpSet();

		int optLength         = afpChain.getOptLength();
		int[] afpChainList    = afpChain.getAfpChainList();
		int[] block2Afp       = afpChain.getBlock2Afp();
		int[] blockSize       = afpChain.getBlockSize();


		if (debug)
			System.out.println("AFPOptimizer got blockNum: " +blockNum);
		//optimize each alignment defined by a block
		b1 = b2 = e1 = e2 = optLength = 0;
		for(bk = 0; bk < blockNum; bk ++)       {
			//initial aligned position
			iniLen = 0;
			if(bk > 0)      {
				b1 = e1;
				b2 = e2;
			}
			if(bk < blockNum - 1)   {
				a1 = afpChainList[block2Afp[bk] + blockSize[bk] - 1]; //the last AFP in current block
				a2 = afpChainList[block2Afp[bk + 1]];  //the first AFP in next block
				e1 = (afpSet.get(a1).getP1() + fragLen +  afpSet.get(a2).getP1()) / 2;
				e2 = (afpSet.get(a1).getP2() + fragLen +  afpSet.get(a2).getP2()) / 2;
			} //use the middle point of the current and next AFPs. old (starting point of next AFP)
			else    {
				e1 = ca1.length;
				e2 = ca2.length;
			}


			for(i = block2Afp[bk]; i < block2Afp[bk] + blockSize[bk]; i ++) {
				a = afpChainList[i];
				p1 = afpSet.get(a).getP1();
				p2 = afpSet.get(a).getP2();
				for(k = 0; k < afpSet.get(a).getFragLen(); k ++)     {
					iniSet[0][iniLen] = p1 + k - b1; //note -b1
					iniSet[1][iniLen] = p2 + k - b2; //note -b2
					iniLen ++;

				}
			}
			//optimize the align by dynamic programming & constraint the optimization region
			if(debug) {
				System.err.println(String.format("optimize block %d (%d afp), region %d-%d(len %d), %d-%d(len %d)\n",
						bk, blockSize[bk], b1, e1, e1-b1, b2, e2, e2-b2));

				System.err.println(" initial alignment Length: " + iniLen );
			}

			StructureAlignmentOptimizer opt = new StructureAlignmentOptimizer(b1,e1, ca1, b2,e2, ca2, iniLen, iniSet);
			opt.runOptimization(maxi);
			optRmsd[bk] = opt.optimizeResult(optLen,bk,optAln[bk]);

			//System.out.println(optRmsd[bk]);
			// SALNOPT *opt = new SALNOPT(e1-b1, &pro1->caCod[3 * b1], e2-b2, &pro2->caCod[3 * b2], iniLen, iniSet, maxi);
			// optRmsd[bk] = opt->OptimizeResult(&optLen[bk], optAln[bk]);

			if(debug)
				System.out.println(String.format(" optimized len=%d, rmsd %f\n", optLen[bk], optRmsd[bk]));

			for(i = 0; i < optLen[bk]; i ++)        {
				optAln[bk][0][i] += b1; //restore the position
				optAln[bk][1][i] += b2; //restore the position
			}
			optLength += optLen[bk];


		}

		long optEnd = System.currentTimeMillis();
		if(debug)       System.out.println("complete AlignOpt " + (optEnd-optStart) +"\n");

		if(optLength < minLen) {
			int[][][] optAln_trim = new int[maxTra + 1][2][optLength];
			for (i = 0; i < maxTra + 1; i ++) {
				System.arraycopy(optAln[i][0], 0, optAln_trim[i][0], 0, optLength);
				System.arraycopy(optAln[i][1], 0, optAln_trim[i][1], 0, optLength);
			}
			afpChain.setOptAln(optAln_trim);
		} else {
			afpChain.setOptAln(optAln);
		}

		afpChain.setBlockNum(blockNum);
		afpChain.setOptLength(optLength);
		afpChain.setAfpChainList(afpChainList);
		afpChain.setBlock2Afp(block2Afp);
		afpChain.setBlockSize(blockSize);


	}
598980
def _heuristic_bin_width(obs):
    """"""
    IQR = sp.percentile(obs, 75) - sp.percentile(obs, 25)
    N = len(obs)
    return 2*IQR*N**(-1/3)
1038458
def uinit(self, ushape):
        """"""

        if self.opt['Y0'] is None:
            return np.zeros(ushape, dtype=self.dtype)
        else:
            # If initial Y is non-zero, initial U is chosen so that
            # the relevant dual optimality criterion (see (3.10) in
            # boyd-2010-distributed) is satisfied.
            U0 = np.sign(self.block_sep0(self.Y)) / self.rho
            U1 = self.block_sep1(self.Y) - self.S
            return self.block_cat(U0, U1)
1330207
def partial_fit(self, X):
        
        opt, cost = self.sess.run((self.optimizer, self.cost), 
                                  feed_dict={self.x: X})
        return cost
787866
function googleOptimize({ experiment }) {
  if (process.server || !window.ga || !experiment || !experiment.experimentID) {
    return
  }

  const exp = experiment.experimentID + '.' + experiment.$variantIndexes.join('-')

  window.ga('set', 'exp', exp)
}