Internal finder for local maxima .
    Returns UNSORTED indices of maxima in input vector.
548804
def local_maxima(vector,min_distance = 4, brd_mode = "wrap"):
    
    fits = gaussian_filter(numpy.asarray(vector,dtype=numpy.float32),1., mode=brd_mode)
    for ii in range(len(fits)):
        if fits[ii] == fits[ii-1]:
            fits[ii-1] = 0.0
    maxfits     = maximum_filter(fits, size=min_distance, mode=brd_mode)
    maxima_mask = fits == maxfits
    maximum     = numpy.transpose(maxima_mask.nonzero())
    return numpy.asarray(maximum)
386338
def _find_neighbors(self, inst):
        
        # Make a vector of distances between target instance (inst) and all others
        dist_vect = []
        for j in range(self._datalen):
            if inst != j:
                locator = [inst, j]
                if inst < j:
                    locator.reverse()
                dist_vect.append(self._distance_array[locator[0]][locator[1]])
            else:
                # Ensures that target instance is never selected as neighbor.
                dist_vect.append(sys.maxsize)

        dist_vect = np.array(dist_vect)

        # Identify neighbors-------------------------------------------------------
        """ NN for Binary Endpoints: """
        if self._class_type == 'binary':
            nn_list = []
            match_count = 0
            miss_count = 0
            for nn_index in np.argsort(dist_vect):
                if self._y[inst] == self._y[nn_index]:  # Hit neighbor identified
                    if match_count >= self.n_neighbors:
                        continue
                    nn_list.append(nn_index)
                    match_count += 1
                else:  # Miss neighbor identified
                    if miss_count >= self.n_neighbors:
                        continue
                    nn_list.append(nn_index)
                    miss_count += 1

                if match_count >= self.n_neighbors and miss_count >= self.n_neighbors:
                    break

        elif self._class_type == 'multiclass':
            nn_list = []
            match_count = 0
            miss_count = dict.fromkeys(self._label_list, 0)
            for nn_index in np.argsort(dist_vect):
                if self._y[inst] == self._y[nn_index]:  # Hit neighbor identified
                    if match_count >= self.n_neighbors:
                        continue
                    nn_list.append(nn_index)
                    match_count += 1
                else:
                    for label in self._label_list:
                        if self._y[nn_index] == label:
                            if miss_count[label] >= self.n_neighbors:
                                continue
                            nn_list.append(nn_index)
                            miss_count[label] += 1

                if match_count >= self.n_neighbors and all(v >= self.n_neighbors for v in miss_count.values()):
                    break
        else:
            nn_list = []
            match_count = 0
            miss_count = 0
            for nn_index in np.argsort(dist_vect):
                if abs(self._y[inst]-self._y[nn_index]) < self._labels_std:  # Hit neighbor identified
                    if match_count >= self.n_neighbors:
                        continue
                    nn_list.append(nn_index)
                    match_count += 1
                else:  # Miss neighbor identified
                    if miss_count >= self.n_neighbors:
                        continue
                    nn_list.append(nn_index)
                    miss_count += 1

                if match_count >= self.n_neighbors and miss_count >= self.n_neighbors:
                    break
        return np.array(nn_list)
439305
def find_range(values, soft_range=[]):
    
    try:
        values = np.array(values)
        values = np.squeeze(values) if len(values.shape) > 1 else values
        if len(soft_range):
            values = np.concatenate([values, soft_range])
        if values.dtype.kind == 'M':
            return values.min(), values.max()
        return np.nanmin(values), np.nanmax(values)
    except:
        try:
            values = sorted(values)
            return (values[0], values[-1])
        except:
            return (None, None)
1096678
void findHistogramPeaks() {
		// reset data structures
		peaks.reset();
		angles.reset();
		peakAngle = 0;

		// identify peaks and find the highest peak
		double largest = 0;
		int largestIndex = -1;
		double before = histogramMag[ histogramMag.length-2 ];
		double current = histogramMag[ histogramMag.length-1 ];
		for(int i = 0; i < histogramMag.length; i++ ) {
			double after = histogramMag[ i ];

			if( current > before && current > after ) {
				int currentIndex = CircularIndex.addOffset(i,-1,histogramMag.length);
				peaks.push(currentIndex);
				if( current > largest ) {
					largest = current;
					largestIndex = currentIndex;
				}
			}
			before = current;
			current = after;
		}

		if( largestIndex < 0 )
			return;

		// see if any of the other peaks are within 80% of the max peak
		double threshold = largest*0.8;
		for( int i = 0; i < peaks.size; i++ ) {
			int index = peaks.data[i];
			current = histogramMag[index];
			if( current >= threshold) {
				double angle = computeAngle(index);

				angles.push( angle );

				if( index == largestIndex )
					peakAngle = angle;
			}
		}
	}
1124475
def find_valley_range(vector, min_distance = 4):
    
    
    # http://users.monash.edu.au/~dengs/resource/papers/icme08.pdf
    # find min and max with mode = wrap
    mode = "wrap"
    minima = local_minima(vector,min_distance,mode)
    maxima = local_maxima(vector,min_distance,mode)

    if len(maxima)>len(minima):
        if vector[maxima[0]] >= vector[maxima[-1]]:
            maxima=maxima[1:]
        else:
            maxima=maxima[:-1]
        
    if len(maxima)==len(minima):
        valley_range = numpy.asarray([minima[ii+1] - minima[ii] for ii in range(len(minima)-1)] + [len(vector)-minima[-1]+minima[0]])
        if minima[0] < maxima[0]:
            minima = numpy.asarray(list(minima) + [minima[0]])
        else:
            minima = numpy.asarray(list(minima) + [minima[-1]])       
    else:
        valley_range = numpy.asarray([minima[ii+1] - minima[ii] for ii in range(len(maxima))])
    
    return maxima, minima, valley_range
83788
def max_or_none(val1, val2):
    """"""
    return max(val1, val2, key=lambda x: -sys.maxint if x is None else x)
644878
def _get_bounds(mapper, values):
        

        array = np.array([mapper.get(x) for x in values])
        return array[:, 0], array[:, 1]
870900
def get_bounds(self):
        
        if self._vertices_indexed_by_faces is not None:
            v = self._vertices_indexed_by_faces
        elif self._vertices is not None:
            v = self._vertices
        else:
            return None
        bounds = [(v[:, ax].min(), v[:, ax].max()) for ax in range(v.shape[1])]
        return bounds
836684
function max(x) {
        var value;
        for (var i = 0; i < x.length; i++) {
            // On the first iteration of this loop, max is
            // undefined and is thus made the maximum element in the array
            if (x[i] > value || value === undefined) value = x[i];
        }
        return value;
    }
1324557
def softmax(x):
    """"""
    e_x = np.exp(x - np.max(x))
    return e_x / e_x.sum(axis=1)[:, None]
482520
public double[][] getMaxedMarginals() {
    double[][] maxValues = new double[neighborIndices.length][];
    for (int i = 0; i < neighborIndices.length; i++) {
      maxValues[i] = new double[getDimensions()[i]];
      for (int j = 0; j < maxValues[i].length; j++) maxValues[i][j] = Double.NEGATIVE_INFINITY;
    }

    // Get max values

    // OPTIMIZATION:
    // Rather than use the standard iterator, which creates lots of int[] arrays on the heap, which need to be GC'd,
    // we use the fast version that just mutates one array. Since this is read once for us here, this is ideal.

    Iterator<int[]> fastPassByReferenceIterator = fastPassByReferenceIterator();
    int[] assignment = fastPassByReferenceIterator.next();
    while (true) {
      double v = getAssignmentLogValue(assignment);
      for (int i = 0; i < neighborIndices.length; i++) {
        if (maxValues[i][assignment[i]] < v) maxValues[i][assignment[i]] = v;
      }
      // This mutates the resultAssignment[] array, rather than creating a new one
      if (fastPassByReferenceIterator.hasNext()) {
        fastPassByReferenceIterator.next();
      } else break;
    }

    for (int i = 0; i < neighborIndices.length; i++) {
      normalizeLogArr(maxValues[i]);
    }

    return maxValues;
  }
722174
def find_max(self, predicate, max_=None):
        
        if predicate(self.value):
            max_ = self.value
            next_node = self._greater
        else:
            next_node = self._lesser
        if next_node is None:
            return max_
        return next_node.find_max(predicate, max_)
813080
def get_minmax(self, stmt, refine_dict):
        
        minel = refine_dict["min-elements"]
        maxel = refine_dict["max-elements"]
        if minel is None:
            minst = stmt.search_one("min-elements")
            if minst:
                minel = minst.arg
            else:
                minel = "0"
        if maxel is None:
            maxst = stmt.search_one("max-elements")
            if maxst:
                maxel = maxst.arg
        if maxel == "unbounded": maxel = None
        return (minel, maxel)
193163
def through_maxima(*array_options, **options)
      @after_maxima ||= Command.output(itself: Unit) do |c|
        c.let :itself, self.to_s, *array_options, **options
      end[:itself]
    end
1188647
public static int whichMax(float[] x) {
        float m = Float.NEGATIVE_INFINITY;
        int which = 0;

        for (int i = 0; i < x.length; i++) {
            if (x[i] > m) {
                m = x[i];
                which = i;
            }
        }

        return which;
    }
400920
def maxlevel(lst):
    """"""
    maxlev = 0
    def f(lst, level):
        nonlocal maxlev
        if isinstance(lst, list):
            level += 1
            maxlev = max(level, maxlev)
            for item in lst:
                f(item, level)
    f(lst, 0)
    return maxlev
788376
function closestToZero(numbers, maxNumber) {
    //returns the index of value closest to 0
    var positiveNumbers = numbers.map(function(number) {
        return Math.abs(number);
    });

    var sortedPositiveNumbers = positiveNumbers.sort(function(a, b) {
        return (a - b);
    });

    return sortedPositiveNumbers[0];
}