java.lang.Math#min ( )源码实例Demo

下面列出了java.lang.Math#min ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: systemds   文件: LibMatrixCUDA.java
/**
 * Get threads, blocks and shared memory for a reduce all operation
 * @param gCtx a valid {@link GPUContext}
 * @param n size of input array
 * @return integer array containing {blocks, threads, shared memory}
 */
private static int[] getKernelParamsForReduceAll(GPUContext gCtx, int n) {
	final int MAX_THREADS = getMaxThreads(gCtx);
	final int MAX_BLOCKS = getMaxBlocks(gCtx);
	final int WARP_SIZE = getWarpSize(gCtx);
	int threads = (n < MAX_THREADS *2) ? nextPow2((n + 1)/ 2) : MAX_THREADS;

	int blocks = (n + (threads * 2 - 1)) / (threads * 2);
	blocks = Math.min(MAX_BLOCKS, blocks);

	int sharedMemSize = threads * sizeOfDataType;
	if (threads <= WARP_SIZE) {
		sharedMemSize *= 2;
	}
	return new int[] {blocks, threads, sharedMemSize};
}
 
源代码2 项目: systemds   文件: LibMatrixCUDA.java
/**
 * Get threads, blocks and shared memory for a reduce all operation
 * @param gCtx a valid {@link GPUContext}
 * @param n size of input array
 * @return integer array containing {blocks, threads, shared memory}
 */
private static int[] getKernelParamsForReduceAll(GPUContext gCtx, int n) {
	final int MAX_THREADS = getMaxThreads(gCtx);
	final int MAX_BLOCKS = getMaxBlocks(gCtx);
	final int WARP_SIZE = getWarpSize(gCtx);
	int threads = (n < MAX_THREADS *2) ? nextPow2((n + 1)/ 2) : MAX_THREADS;

	int blocks = (n + (threads * 2 - 1)) / (threads * 2);
	blocks = Math.min(MAX_BLOCKS, blocks);

	int sharedMemSize = threads * sizeOfDataType;
	if (threads <= WARP_SIZE) {
		sharedMemSize *= 2;
	}
	return new int[] {blocks, threads, sharedMemSize};
}
 
源代码3 项目: circuitjs1   文件: CirSim.java
void zoomCircuit(int dy) {
double newScale;
   	double oldScale = transform[0];
   	double val = dy*.01;
   	newScale = Math.max(oldScale+val, .2);
   	newScale = Math.min(newScale, 2.5);
   	setCircuitScale(newScale);
   }
 
源代码4 项目: jdk8u-jdk   文件: SnmpStringFixed.java
/**
 * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>Bytes</CODE> array
 * with the specified length.
 * @param l The length of the fixed-string.
 * @param v The <CODE>Bytes</CODE> composing the fixed-string value.
 * @exception IllegalArgumentException Either the length or the <CODE>Byte</CODE> array is not valid.
 */
public SnmpStringFixed(int l, Byte[] v) throws IllegalArgumentException {
    if ((l <= 0) || (v == null)) {
        throw new IllegalArgumentException() ;
    }
    int length = Math.min(l, v.length);
    value = new byte[l] ;
    for (int i = 0 ; i < length ; i++) {
        value[i] = v[i].byteValue() ;
    }
    for (int i = length ; i < l ; i++) {
        value[i] = 0 ;
    }
}
 
源代码5 项目: openjdk-8   文件: SnmpStringFixed.java
/**
 * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>bytes</CODE> array
 * with the specified length.
 * @param l The length of the fixed-string.
 * @param v The <CODE>bytes</CODE> composing the fixed-string value.
 * @exception IllegalArgumentException Either the length or the <CODE>byte</CODE> array is not valid.
 */
public SnmpStringFixed(int l, byte[] v) throws IllegalArgumentException {
    if ((l <= 0) || (v == null)) {
        throw new IllegalArgumentException() ;
    }
    int length = Math.min(l, v.length);
    value = new byte[l] ;
    for (int i = 0 ; i < length ; i++) {
        value[i] = v[i] ;
    }
    for (int i = length ; i < l ; i++) {
        value[i] = 0 ;
    }
}
 
源代码6 项目: systemds   文件: LibMatrixCUDA.java
private static int[] getKernelParamsForReduceByCol(GPUContext gCtx, int rows, int cols) {
	final int MAX_THREADS = getMaxThreads(gCtx);
	final int MAX_BLOCKS = getMaxBlocks(gCtx);
	final int WARP_SIZE = getWarpSize(gCtx);
	int threads = Math.min(cols, MAX_THREADS);
	int blocks = Math.min(cols/MAX_THREADS, MAX_BLOCKS);
	if (cols % MAX_THREADS != 0) blocks++;
	int sharedMemSize = threads * sizeOfDataType;
	if (threads <= WARP_SIZE) {
		sharedMemSize *=2;
	}
	return new int[] {blocks, threads, sharedMemSize};
}
 
源代码7 项目: knopflerfish.org   文件: RS485.java
public int read( byte b[], int off, int len ) throws IOException 
{
	dataAvailable=0;
	int i=0, Minimum=0;
	int intArray[] = 
	{
		b.length,
		InputBuffer, 
		len
	};
/*
	find the lowest nonzero value
	timeout and threshold are handled on the native side
	see  NativeEnableReceiveTimeoutThreshold in
	RS485Imp.c
*/
	while(intArray[i]==0 && i < intArray.length) i++;
	Minimum=intArray[i];
	while( i < intArray.length )
	{
		if(intArray[i] > 0 )
		{
			Minimum=Math.min(Minimum,intArray[i]);
		}
		i++;
	}
	Minimum=Math.min(Minimum,threshold);
	if(Minimum == 0) Minimum=1;
	int Available=available();
	int Ret = readArray( b, off, Minimum);
	return Ret;
}
 
源代码8 项目: TencentKona-8   文件: SnmpStringFixed.java
/**
 * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>Bytes</CODE> array
 * with the specified length.
 * @param l The length of the fixed-string.
 * @param v The <CODE>Bytes</CODE> composing the fixed-string value.
 * @exception IllegalArgumentException Either the length or the <CODE>Byte</CODE> array is not valid.
 */
public SnmpStringFixed(int l, Byte[] v) throws IllegalArgumentException {
    if ((l <= 0) || (v == null)) {
        throw new IllegalArgumentException() ;
    }
    int length = Math.min(l, v.length);
    value = new byte[l] ;
    for (int i = 0 ; i < length ; i++) {
        value[i] = v[i].byteValue() ;
    }
    for (int i = length ; i < l ; i++) {
        value[i] = 0 ;
    }
}
 
源代码9 项目: TencentKona-8   文件: SnmpStringFixed.java
/**
 * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>String</CODE>
 * with the specified length.
 * @param l The length of the fixed-string.
 * @param s The <CODE>String</CODE> composing the fixed-string value.
 * @exception IllegalArgumentException Either the length or the <CODE>String</CODE> is not valid.
 */
public SnmpStringFixed(int l, String s) throws IllegalArgumentException {
    if ((l <= 0) || (s == null)) {
        throw new IllegalArgumentException() ;
    }
    byte[] v = s.getBytes();
    int length = Math.min(l, v.length);
    value = new byte[l] ;
    for (int i = 0 ; i < length ; i++) {
        value[i] = v[i] ;
    }
    for (int i = length ; i < l ; i++) {
        value[i] = 0 ;
    }
}
 
源代码10 项目: jdk8u60   文件: SnmpStringFixed.java
/**
 * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>bytes</CODE> array
 * with the specified length.
 * @param l The length of the fixed-string.
 * @param v The <CODE>bytes</CODE> composing the fixed-string value.
 * @exception IllegalArgumentException Either the length or the <CODE>byte</CODE> array is not valid.
 */
public SnmpStringFixed(int l, byte[] v) throws IllegalArgumentException {
    if ((l <= 0) || (v == null)) {
        throw new IllegalArgumentException() ;
    }
    int length = Math.min(l, v.length);
    value = new byte[l] ;
    for (int i = 0 ; i < length ; i++) {
        value[i] = v[i] ;
    }
    for (int i = length ; i < l ; i++) {
        value[i] = 0 ;
    }
}
 
源代码11 项目: knopflerfish.org   文件: Raw.java
public int read( byte b[], int off, int len ) throws IOException 
{
	dataAvailable=0;
	int i=0, Minimum=0;
	int intArray[] = 
	{
		b.length,
		InputBuffer, 
		len
	};
/*
	find the lowest nonzero value
	timeout and threshold are handled on the native side
	see  NativeEnableReceiveTimeoutThreshold in
	RawImp.c
*/
	while(intArray[i]==0 && i < intArray.length) i++;
	Minimum=intArray[i];
	while( i < intArray.length )
	{
		if(intArray[i] > 0 )
		{
			Minimum=Math.min(Minimum,intArray[i]);
		}
		i++;
	}
	Minimum=Math.min(Minimum,threshold);
	if(Minimum == 0) Minimum=1;
	int Available=available();
	int Ret = readArray( b, off, Minimum);
	return Ret;
}
 
源代码12 项目: JDKSourceCode1.8   文件: SnmpStringFixed.java
/**
 * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>String</CODE>
 * with the specified length.
 * @param l The length of the fixed-string.
 * @param s The <CODE>String</CODE> composing the fixed-string value.
 * @exception IllegalArgumentException Either the length or the <CODE>String</CODE> is not valid.
 */
public SnmpStringFixed(int l, String s) throws IllegalArgumentException {
    if ((l <= 0) || (s == null)) {
        throw new IllegalArgumentException() ;
    }
    byte[] v = s.getBytes();
    int length = Math.min(l, v.length);
    value = new byte[l] ;
    for (int i = 0 ; i < length ; i++) {
        value[i] = v[i] ;
    }
    for (int i = length ; i < l ; i++) {
        value[i] = 0 ;
    }
}
 
源代码13 项目: jdk8u-dev-jdk   文件: SnmpStringFixed.java
/**
 * Constructs a new <CODE>SnmpStringFixed</CODE> from the specified <CODE>Bytes</CODE> array
 * with the specified length.
 * @param l The length of the fixed-string.
 * @param v The <CODE>Bytes</CODE> composing the fixed-string value.
 * @exception IllegalArgumentException Either the length or the <CODE>Byte</CODE> array is not valid.
 */
public SnmpStringFixed(int l, Byte[] v) throws IllegalArgumentException {
    if ((l <= 0) || (v == null)) {
        throw new IllegalArgumentException() ;
    }
    int length = Math.min(l, v.length);
    value = new byte[l] ;
    for (int i = 0 ; i < length ; i++) {
        value[i] = v[i].byteValue() ;
    }
    for (int i = length ; i < l ; i++) {
        value[i] = 0 ;
    }
}
 
源代码14 项目: apk-dependency-graph   文件: ApkSmaliDecoder.java
private int getNumberOfAvailableProcessors() {
    int jobs = Runtime.getRuntime().availableProcessors();
    return Math.min(jobs, MAXIMUM_NUMBER_OF_PROCESSORS);
}
 
源代码15 项目: codeu_project_2017   文件: ListNavigator.java
private void moveUp() {
  top = Math.max(top - pageSize, 1);
  bottom = Math.min(top + pageSize - 1, selection.size());
}
 
源代码16 项目: RDFS   文件: ReduceTask.java
public ReduceCopier(TaskUmbilicalProtocol umbilical, JobConf conf,
                    TaskReporter reporter
                    )throws ClassNotFoundException, IOException {

  configureClasspath(conf);
  this.reporter = reporter;
  this.shuffleClientMetrics = new ShuffleClientMetrics(conf);
  this.umbilical = umbilical;
  this.reduceTask = ReduceTask.this;

  this.scheduledCopies = new ArrayList<MapOutputLocation>(100);
  this.copyResults = new ArrayList<CopyResult>(100);
  this.numCopiers = conf.getInt("mapred.reduce.parallel.copies", 5);
  this.maxInFlight = 4 * numCopiers;
  Counters.Counter combineInputCounter =
    reporter.getCounter(Task.Counter.COMBINE_INPUT_RECORDS);
  this.combinerRunner = CombinerRunner.create(conf, getTaskID(),
                                              combineInputCounter,
                                              reporter, null);
  if (combinerRunner != null) {
    combineCollector =
      new CombineOutputCollector(reduceCombineOutputCounter);
  }

  this.ioSortFactor = conf.getInt("io.sort.factor", 10);

  this.abortFailureLimit = Math.max(30, numMaps / 10);

  this.maxFetchFailuresBeforeReporting = conf.getInt(
      "mapreduce.reduce.shuffle.maxfetchfailures", REPORT_FAILURE_LIMIT);

  this.maxFailedUniqueFetches = Math.min(numMaps,
                                         this.maxFailedUniqueFetches);
  this.maxInMemOutputs = conf.getInt("mapred.inmem.merge.threshold", 1000);
  this.maxInMemCopyPer =
    conf.getFloat("mapred.job.shuffle.merge.percent", 0.66f);
  final float maxRedPer =
    conf.getFloat("mapred.job.reduce.input.buffer.percent", 0f);
  if (maxRedPer > 1.0 || maxRedPer < 0.0) {
    throw new IOException("mapred.job.reduce.input.buffer.percent" +
                          maxRedPer);
  }
  this.maxInMemReduce = (int)Math.min(
      Runtime.getRuntime().maxMemory() * maxRedPer, Integer.MAX_VALUE);

  // Setup the RamManager
  ramManager = new ShuffleRamManager(conf);

  localFileSys = FileSystem.getLocal(conf);

  rfs = ((LocalFileSystem)localFileSys).getRaw();

  // hosts -> next contact time
  this.penaltyBox = new LinkedHashMap<String, Long>();

  // hostnames
  this.uniqueHosts = new HashSet<String>();

  // Seed the random number generator with a reasonably globally unique seed
  long randomSeed = System.nanoTime() +
                    (long)Math.pow(this.reduceTask.getPartition(),
                                   (this.reduceTask.getPartition()%10)
                                  );
  this.random = new Random(randomSeed);
  this.maxMapRuntime = 0;
  this.reportReadErrorImmediately =
    conf.getBoolean("mapreduce.reduce.shuffle.notify.readerror", true);
}
 
源代码17 项目: bumblebench   文件: BumbleBench.java
final boolean runAttempt(boolean lowball) throws InterruptedException {
	float under = _estimate * (1-_uncertainty/2);
	float over  = _estimate * (1+_uncertainty/2);
	float target = lowball? under : over;

	// Run an experiment
	//
	if (VERBOSE)
		out().println("attempt(" + target + ")");
	float result = attempt(target);

	// Analyze the results
	//
	boolean runSucceeded;                    // Was the target score achieved?
	boolean guessWasCorrect;                 // Was runSucceeded what we expected it to be based on the lowball/highball setting?
	boolean newEstimateWasSpecified = false; // Did the run provide an estimate of the score it can achieve?
	float oldEstimate = _estimate;
	if (result >= target && result < Float.POSITIVE_INFINITY) {
		runSucceeded = true;
		recordSuccess(target);
		guessWasCorrect = lowball;
		_estimate = result;
		newEstimateWasSpecified = true;
	} else if (result <= 0F) {
		// UNSPECIFIED_FAILURE
		runSucceeded = false;
		guessWasCorrect = !lowball;
		_estimate = lowball? _estimate * (1-_uncertainty) : _estimate;
	} else if (result < target) {
		runSucceeded = false;
		guessWasCorrect = !lowball;
		_estimate = result; // This is why we can't handle result==0 here.  Estimate hits zero and never recovers
		newEstimateWasSpecified = true;
	} else {
		// UNSPECIFIED_SUCCESS
		runSucceeded = true;
		recordSuccess(target);
		guessWasCorrect = lowball;
		_estimate = lowball? _estimate : _estimate * (1+_uncertainty);
	}
	if (_recentPeak == _maxPeak) {
		if (under <= _maxPeak && _maxPeak <= over)
			_maxPeakUncertainty = Math.min(_maxPeakUncertainty, _uncertainty);
	}
	if (!runSucceeded && target < _recentPeak)
		_recentPeak = Float.NEGATIVE_INFINITY;
	float oldUncertainty = _uncertainty;
	if (runSucceeded && target >= Float.POSITIVE_INFINITY) {
		// lowball guess or not, if we thought it was infinitely fast and the
		// runSucceeded, we were right.  Otherwise, we may never terminate,
		// always attempting to increase the already-infinite target score ever higher.
		guessWasCorrect = true;
	}
	if (newEstimateWasSpecified) {
		float impliedUncertainty = Math.abs(oldEstimate - result) / target;
		if (impliedUncertainty > _uncertainty) {
			if (TAME_UNCERTAINTY) {
				// If the estimate was way off, just bump up the _uncertainty as though our guess was incorrect
				_uncertainty *= INCORRECT_GUESS_ADJUSTMENT;
			} else {
				_uncertainty = impliedUncertainty;
			}
		} else {
			_uncertainty *= guessWasCorrect? CORRECT_GUESS_ADJUSTMENT : INCORRECT_GUESS_ADJUSTMENT;
		}
	} else {
		_uncertainty *= guessWasCorrect? CORRECT_GUESS_ADJUSTMENT : INCORRECT_GUESS_ADJUSTMENT;
	}
	_uncertainty = Math.min(_uncertainty, MAX_UNCERTAINTY); 
	report(target, result, oldUncertainty, lowball, guessWasCorrect, runSucceeded);
	return guessWasCorrect;
}
 
源代码18 项目: RDFS   文件: TransferFsImage.java
/**
 * A server-side method to respond to a getfile http request
 * Copies the contents of the local file into the output stream.
 */
static void getFileServer(OutputStream outstream, File localfile, DataTransferThrottler throttler) 
  throws IOException {
  byte buf[] = new byte[BUFFER_SIZE];
  FileInputStream infile = null;
  long totalReads = 0, totalSends = 0;
  try {
    infile = new FileInputStream(localfile);
    if (ErrorSimulator.getErrorSimulation(2)
        && localfile.getAbsolutePath().contains("secondary")) {
      // throw exception only when the secondary sends its image
      throw new IOException("If this exception is not caught by the " +
          "name-node fs image will be truncated.");
    }
    
    if (ErrorSimulator.getErrorSimulation(3)
        && localfile.getAbsolutePath().contains("fsimage")) {
        // Test sending image shorter than localfile
        long len = localfile.length();
        buf = new byte[(int)Math.min(len/2, BUFFER_SIZE)];
        // This will read at most half of the image
        // and the rest of the image will be sent over the wire
        infile.read(buf);
    }
    int num = 1;
    while (num > 0) {
      long startRead = System.currentTimeMillis();
      num = infile.read(buf);
      if (num <= 0) {
        break;
      }
      outstream.write(buf, 0, num);
      if (throttler != null) {
        throttler.throttle(num);
      }
    }
  } finally {
    if (infile != null) {
      infile.close();
    }
  }
}
 
源代码19 项目: incubator-retired-mrql   文件: SystemFunctions.java
public static MR_long min ( MR_long x, MR_long y ) { return new MR_long(Math.min(x.get(),y.get())); } 
源代码20 项目: incubator-retired-mrql   文件: SystemFunctions.java
public static MR_double min ( MR_double x, MR_double y ) { return new MR_double(Math.min(x.get(),y.get())); }