Computes the next search direction using BFGS
509111
private boolean computeSearchDirection() {
		// Compute the function's gradient
		function.computeGradient(temp0_Nx1.data);

		// compute the change in gradient
		for( int i = 0; i < N; i++ ) {
			y.data[i] = temp0_Nx1.data[i] - g.data[i];
			g.data[i] = temp0_Nx1.data[i];
		}

		// Update the inverse Hessian matrix
		if( iterations != 0 ) {
			EquationsBFGS.inverseUpdate(B, s, y, temp0_Nx1, temp1_Nx1);
		}

		// compute the search direction
		CommonOps_DDRM.mult(-1,B,g, searchVector);

		// use the line search to find the next x
		if( !setupLineSearch(fx, x.data, g.data, searchVector.data) ) {
			// the search direction has a positive derivative, meaning the B matrix is
			// no longer SPD.  Attempt to fix the situation by resetting the matrix
			resetMatrixB();
			// do the search again, it can't fail this time
			CommonOps_DDRM.mult(-1,B,g, searchVector);
			setupLineSearch(fx, x.data, g.data, searchVector.data);
		} else if(Math.abs(derivAtZero) <= gtol ) {
			if( verbose != null ) {
				verbose.printf("finished select direction, gtest=%e\n",Math.abs(derivAtZero));
			}

			// the input might have been modified by the function.  So copy it
			System.arraycopy(function.getCurrentState(),0,x.data,0,N);
			return terminateSearch(true);
		}

		mode = 1;
		iterations++;
		return false;
	}
917704
def opt(self, x_init, f_fp=None, f=None, fp=None):
        
        rcstrings = ['Converged', 'Maximum number of f evaluations reached', 'Error']

        assert f_fp != None, "BFGS requires f_fp"

        opt_dict = {}
        if self.xtol is not None:
            print("WARNING: l-bfgs-b doesn't have an xtol arg, so I'm going to ignore it")
        if self.ftol is not None:
            print("WARNING: l-bfgs-b doesn't have an ftol arg, so I'm going to ignore it")
        if self.gtol is not None:
            opt_dict['pgtol'] = self.gtol
        if self.bfgs_factor is not None:
            opt_dict['factr'] = self.bfgs_factor

        opt_result = optimize.fmin_l_bfgs_b(f_fp, x_init, maxfun=self.max_iters, maxiter=self.max_iters, **opt_dict)
        self.x_opt = opt_result[0]
        self.f_opt = f_fp(self.x_opt)[0]
        self.funct_eval = opt_result[2]['funcalls']
        self.status = rcstrings[opt_result[2]['warnflag']]

        #a more helpful error message is available in opt_result in the Error case
        if opt_result[2]['warnflag']==2: # pragma: no coverage, this is not needed to be covered
            self.status = 'Error' + str(opt_result[2]['task'])
1177059
def find_path(start, goal, neighbors_fnct, reversePath=False, heuristic_cost_estimate_fnct=lambda a, b: Infinite, distance_between_fnct=lambda a, b: 1.0, is_goal_reached_fnct=lambda a, b: a == b):
    """"""
    class FindPath(AStar):

        def heuristic_cost_estimate(self, current, goal):
            return heuristic_cost_estimate_fnct(current, goal)

        def distance_between(self, n1, n2):
            return distance_between_fnct(n1, n2)

        def neighbors(self, node):
            return neighbors_fnct(node)

        def is_goal_reached(self, current, goal):
            return is_goal_reached_fnct(current, goal)
    return FindPath().astar(start, goal, reversePath)
735304
def backtracking(a, L, bestsofar):
    
    w, j = max(L.items())
    while j != -1:
        yield j
        w, j = bestsofar[j]
506547
def _next_move_direction(self):
        
        nmoves = len(self.moves)
        move = np.random.randint(1, nmoves+1)
        while self.prev_move == (move + 3) % nmoves:
            move = np.random.randint(1, nmoves+1)
        self.prev_move = move
        return np.array(self.moves[move])
183445
def next_stop(self):
        """"""
        p = self.api.predictions(vid=self.vid)['prd']
        pobj = Prediction.fromapi(self.api, p[0])
        pobj._busobj = self
        return pobj
763433
function getNextSearchDir( ptA, ptB, dir ){

        var ABdotB = ptB.normSq() - ptB.dot( ptA )
            ,ABdotA = ptB.dot( ptA ) - ptA.normSq()
            ;

        // if the origin is farther than either of these points
        // get the direction from one of those points to the origin
        if ( ABdotB < 0 ){

            return dir.clone( ptB ).negate();

        } else if ( ABdotA > 0 ){

            return dir.clone( ptA ).negate();

        // otherwise, use the perpendicular direction from the simplex
        } else {

            // dir = AB = B - A
            dir.clone( ptB ).vsub( ptA );
            // if (left handed coordinate system)
            // A cross AB < 0 then get perpendicular counterclockwise
            return dir.perp( (ptA.cross( dir ) > 0) );
        }
    }
476775
def next(self):
        
        x, y = next(self.scan)
        xr = -x if self.rx else x
        yr = -y if self.ry else y
        return xr, yr
780189
def direction_neuron(layer_name, vec, batch=None, x=None, y=None, cossim_pow=0):
  """"""
  def inner(T):
    layer = T(layer_name)
    shape = tf.shape(layer)
    x_ = shape[1] // 2 if x is None else x
    y_ = shape[2] // 2 if y is None else y
    if batch is None:
      return _dot_cossim(layer[:, x_, y_], vec[None], cossim_pow=cossim_pow)
    else:
      return _dot_cossim(layer[batch, x_, y_], vec, cossim_pow=cossim_pow)
  return inner
451601
def _kmp_search_first(self, pInput_sequence, pPattern):
                """"""
                input_sequence, pattern = pInput_sequence, [len(bin(e)) for e in pPattern]
                n, m = len(input_sequence), len(pattern)
                d = p = 0
                next = self._kmp_construct_next(pattern)
                while d < n and p < m:
                        p = next[len(bin(input_sequence[d]))][p]
                        d += 1
                if p == m: return d - p
                else: return -1
1040377
private static Direction getNextDirection(final Direction direction, final double p1x, final double p1y, final double p2x, final double p2y)
    {
        Direction next_direction;

        switch (direction)
        {
            case NORTH:
                if (p2y < p1y)
                {
                    next_direction = NORTH;
                }
                else if (p2x > p1x)
                {
                    next_direction = EAST;
                }
                else
                {
                    next_direction = WEST;
                }
                break;
            case SOUTH:
                if (p2y > p1y)
                {
                    next_direction = SOUTH;
                }
                else if (p2x > p1x)
                {
                    next_direction = EAST;
                }
                else
                {
                    next_direction = WEST;
                }
                break;
            case EAST:
                if (p2x > p1x)
                {
                    next_direction = EAST;
                }
                else if (p2y < p1y)
                {
                    next_direction = NORTH;
                }
                else
                {
                    next_direction = SOUTH;
                }
                break;
            case WEST:
                if (p2x < p1x)
                {
                    next_direction = WEST;
                }
                else if (p2y < p1y)
                {
                    next_direction = NORTH;
                }
                else
                {
                    next_direction = SOUTH;
                }
                break;
            default:
                throw new IllegalStateException("This should not be reached (Defensive Code)");
        }
        return next_direction;
    }
443632
private int calculatePositionViaBreakingForwards(int numOfBreaks, BreakIterator breakIterator, int position) {
        breakIterator.following(position);
        for (int i = 1; i < numOfBreaks; i++) {
            breakIterator.next(numOfBreaks);
        }
        return breakIterator.current();
    }
451374
def find_paths_breadth_first(from_target, to_target, log):
  """"""
  log.debug('Looking for all paths from {} to {}'.format(from_target.address.reference(),
                                                         to_target.address.reference()))

  if from_target == to_target:
    yield [from_target]
    return

  visited_edges = set()
  to_walk_paths = deque([[from_target]])
  while len(to_walk_paths) > 0:
    cur_path = to_walk_paths.popleft()
    target = cur_path[-1]

    if len(cur_path) > 1:
      prev_target = cur_path[-2]
    else:
      prev_target = None
    current_edge = (prev_target, target)

    if current_edge not in visited_edges:
      for dep in target.dependencies:
        dep_path = cur_path + [dep]
        if dep == to_target:
          yield dep_path
        else:
          to_walk_paths.append(dep_path)
      visited_edges.add(current_edge)
185240
function binarySearch(arr, pred) {
    let begin   = -1;
    let end     = arr.length;

    while (1 + begin < end) {
        const mi = begin + ((end - begin) >> 1);

        if (pred(arr[mi]))
            end = mi;
        else
            begin = mi;
    }

    return end;
}
643518
def forward(self, x):
        ''''''
        N,C,H,W = x.size()
        g = self.groups
        return x.view(N,g,C/g,H,W).permute(0,2,1,3,4).contiguous().view(N,C,H,W)
1208996
function(q, lowerTail, logp) {
            var ind, ret;

            logp = logp === true;
            lowerTail = lowerTail !== false;

            if (utils.hasNaN(q)) { return NaN; }
            if (q < xs[0]) {
               ret = lowerTail ? 0 : 1;
            } else if (q >= xs[xs.length - 1]) {
               ret = lowerTail ? 1 : 0;
            } else {
               ind = binSearch(xs, function(y) { return y <= q; });
               ret = lowerTail ? cumsLeft[ind] : cumsRight[ind];
            }
            ret = Math.min(ret, 1);
            return logp ? Math.log(ret) : ret;
         }
418953
function computeForwardSlotSegs(levels) {
	var i, level;
	var j, seg;
	var k;

	for (i=0; i<levels.length; i++) {
		level = levels[i];

		for (j=0; j<level.length; j++) {
			seg = level[j];

			seg.forwardSegs = [];
			for (k=i+1; k<levels.length; k++) {
				computeSlotSegCollisions(seg, levels[k], seg.forwardSegs);
			}
		}
	}
}