java.lang.Float.isFinite()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(342)

本文整理了Java中java.lang.Float.isFinite()方法的一些代码示例,展示了Float.isFinite()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Float.isFinite()方法的具体详情如下:
包路径:java.lang.Float
类名称:Float
方法名:isFinite

Float.isFinite介绍

暂无

代码示例

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Update the feature value of this field.
 */
public void setFeatureValue(float featureValue) {
 if (Float.isFinite(featureValue) == false) {
  throw new IllegalArgumentException("featureValue must be finite, got: " + featureValue +
    " for feature " + fieldsData + " on field " + name);
 }
 if (featureValue < Float.MIN_NORMAL) {
  throw new IllegalArgumentException("featureValue must be a positive normal float, got: " +
    featureValue + "for feature " + fieldsData + " on field " + name +
    " which is less than the minimum positive normal float: " + Float.MIN_NORMAL);
 }
 this.featureValue = featureValue;
}

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * BM25 with the supplied parameter values.
 * @param k1 Controls non-linear term frequency normalization (saturation).
 * @param b Controls to what degree document length normalizes tf values.
 * @throws IllegalArgumentException if {@code k1} is infinite or negative, or if {@code b} is 
 *         not within the range {@code [0..1]}
 */
public BM25Similarity(float k1, float b) {
 if (Float.isFinite(k1) == false || k1 < 0) {
  throw new IllegalArgumentException("illegal k1 value: " + k1 + ", must be a non-negative finite value");
 }
 if (Float.isNaN(b) || b < 0 || b > 1) {
  throw new IllegalArgumentException("illegal b value: " + b + ", must be between 0 and 1");
 }
 this.k1 = k1;
 this.b  = b;
}

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Constructor setting all Axiomatic hyperparameters
 * @param s hyperparam for the growth function
 * @param queryLen the query length
 * @param k hyperparam for the primitive weighting function
 */
public Axiomatic(float s, int queryLen, float k) {
 if (Float.isFinite(s) == false || Float.isNaN(s) || s < 0 || s > 1) {
  throw new IllegalArgumentException("illegal s value: " + s + ", must be between 0 and 1");
 }
 if (Float.isFinite(k) == false || Float.isNaN(k) || k < 0 || k > 1) {
  throw new IllegalArgumentException("illegal k value: " + k + ", must be between 0 and 1");
 }
 if (queryLen < 0 || queryLen > Integer.MAX_VALUE) {
  throw new IllegalArgumentException("illegal query length value: "
    + queryLen + ", must be larger 0 and smaller than MAX_INT");
 }
 this.s = s;
 this.queryLen = queryLen;
 this.k = k;
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

Params withRequestsPerSecond(float requestsPerSecond) {
  // the default in AbstractBulkByScrollRequest is Float.POSITIVE_INFINITY,
  // but we don't want to add that to the URL parameters, instead we use -1
  if (Float.isFinite(requestsPerSecond)) {
    return putParam("requests_per_second", Float.toString(requestsPerSecond));
  } else {
    return putParam("requests_per_second", "-1");
  }
}

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Return a new {@link Query} that will score documents as
 * {@code weight * S^a / (S^a + pivot^a)} where S is the value of the static feature.
 * @param fieldName   field that stores features
 * @param featureName name of the feature
 * @param weight      weight to give to this feature, must be in (0,64]
 * @param pivot       feature value that would give a score contribution equal to weight/2, must be in (0, +Infinity)
 * @param exp         exponent, higher values make the function grow slower before 'pivot' and faster after 'pivot', must be in (0, +Infinity)
 * @throws IllegalArgumentException if w is not in (0,64] or either k or a are not in (0, +Infinity)
 */
public static Query newSigmoidQuery(String fieldName, String featureName, float weight, float pivot, float exp) {
 if (weight <= 0 || weight > MAX_WEIGHT) {
  throw new IllegalArgumentException("weight must be in (0, " + MAX_WEIGHT + "], got: " + weight);
 }
 if (pivot <= 0 || Float.isFinite(pivot) == false) {
  throw new IllegalArgumentException("pivot must be > 0, got: " + pivot);
 }
 if (exp <= 0 || Float.isFinite(exp) == false) {
  throw new IllegalArgumentException("exp must be > 0, got: " + exp);
 }
 Query q = new FeatureQuery(fieldName, featureName, new SigmoidFunction(pivot, exp));
 if (weight != 1f) {
  q = new BoostQuery(q, weight);
 }
 return q;
}

代码示例来源:origin: org.apache.lucene/lucene-core

private static Query newSaturationQuery(String fieldName, String featureName, float weight, Float pivot) {
 if (weight <= 0 || weight > MAX_WEIGHT) {
  throw new IllegalArgumentException("weight must be in (0, " + MAX_WEIGHT + "], got: " + weight);
 }
 if (pivot != null && (pivot <= 0 || Float.isFinite(pivot) == false)) {
  throw new IllegalArgumentException("pivot must be > 0, got: " + pivot);
 }
 Query q = new FeatureQuery(fieldName, featureName, new SaturationFunction(fieldName, featureName, pivot));
 if (weight != 1f) {
  q = new BoostQuery(q, weight);
 }
 return q;
}

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Return a new {@link Query} that will score documents as
 * {@code weight * Math.log(scalingFactor + S)} where S is the value of the static feature.
 * @param fieldName     field that stores features
 * @param featureName   name of the feature
 * @param weight        weight to give to this feature, must be in (0,64]
 * @param scalingFactor scaling factor applied before taking the logarithm, must be in [1, +Infinity)
 * @throws IllegalArgumentException if weight is not in (0,64] or scalingFactor is not in [1, +Infinity)
 */
public static Query newLogQuery(String fieldName, String featureName, float weight, float scalingFactor) {
 if (weight <= 0 || weight > MAX_WEIGHT) {
  throw new IllegalArgumentException("weight must be in (0, " + MAX_WEIGHT + "], got: " + weight);
 }
 if (scalingFactor < 1 || Float.isFinite(scalingFactor) == false) {
  throw new IllegalArgumentException("scalingFactor must be >= 1, got: " + scalingFactor);
 }
 Query q = new FeatureQuery(fieldName, featureName, new LogFunction(scalingFactor));
 if (weight != 1f) {
  q = new BoostQuery(q, weight);
 }
 return q;
}

代码示例来源:origin: prestodb/presto

private void testNonTrivialAggregation(Float[] y, Float[] x)
  {
    SimpleRegression regression = new SimpleRegression();
    for (int i = 0; i < x.length; i++) {
      regression.addData(x[i], y[i]);
    }
    float expected = (float) regression.getIntercept();
    checkArgument(Float.isFinite(expected) && expected != 0.f, "Expected result is trivial");
    testAggregation(expected, createBlockOfReals(y), createBlockOfReals(x));
  }
}

代码示例来源:origin: prestodb/presto

private void testNonTrivialAggregation(Float[] y, Float[] x)
  {
    SimpleRegression regression = new SimpleRegression();
    for (int i = 0; i < x.length; i++) {
      regression.addData(x[i], y[i]);
    }
    float expected = (float) regression.getSlope();
    checkArgument(Float.isFinite(expected) && expected != 0.0f, "Expected result is trivial");
    testAggregation(expected, createBlockOfReals(y), createBlockOfReals(x));
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private void validateParsed(float value) {
    if (!Float.isFinite(value)) {
      throw new IllegalArgumentException("[float] supports only finite values, but got [" + value + "]");
    }
  }
},

代码示例来源:origin: ahmetaa/zemberek-nlp

/**
 * @param a input float array
 * @return true if array includes at least one Not-a-Number (NaN) or infinite value, false
 * otherwise
 */
public static boolean containsNanOrInfinite(float[] a) {
 for (float v : a) {
  if (Float.isNaN(v) || !Float.isFinite(v)) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: ahmetaa/zemberek-nlp

/**
 * Converts to an integer array. if values are outside of the given boundaries, throws Exception.
 */
public static int[] toInteger(float[] input, int min, int max) {
 validateArray(input);
 int[] result = new int[input.length];
 int i = 0;
 for (float v : input) {
  if (!Float.isFinite(v) || Float.isNaN(v)) {
   throw new IllegalStateException("Value" + v + " cannot be converted.");
  }
  if (v < min || v > max) {
   throw new IllegalStateException("Value" + v + "is outside of min-max boundaries.");
  }
  result[i] = (int) v;
  i++;
 }
 return result;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private void validateParsed(float value) {
    if (!Float.isFinite(HalfFloatPoint.sortableShortToHalfFloat(HalfFloatPoint.halfFloatToSortableShort(value)))) {
      throw new IllegalArgumentException("[half_float] supports only finite values, but got [" + value + "]");
    }
  }
},

代码示例来源:origin: org.graalvm.truffle/truffle-api

@Override
public boolean fitsInDouble(Object receiver) {
  float originalReceiver = (float) receiver;
  double castValue = originalReceiver;
  return !Float.isFinite(originalReceiver) || castValue == originalReceiver;
}

代码示例来源:origin: com.oracle.truffle/truffle-api

@Override
public boolean fitsInDouble(Object receiver) {
  float originalReceiver = (float) receiver;
  double castValue = originalReceiver;
  return !Float.isFinite(originalReceiver) || castValue == originalReceiver;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

private void validateParsed(float value) {
    if (!Float.isFinite(value)) {
      throw new IllegalArgumentException("[float] supports only finite values, but got [" + value + "]");
    }
  }
},

代码示例来源:origin: jtransc/jtransc

static private void constTest() {
  System.out.println("Float.isInfinite(Float.POSITIVE_INFINITY): " + Float.isInfinite(Float.POSITIVE_INFINITY));
  System.out.println("Float.isInfinite(Float.NEGATIVE_INFINITY): " + Float.isInfinite(Float.NEGATIVE_INFINITY));
  System.out.println("Float.isInfinite(Float.NaN): " + Float.isInfinite(Float.NaN));
  System.out.println("Float.isFinite(Float.POSITIVE_INFINITY): " + Float.isFinite(Float.POSITIVE_INFINITY));
  System.out.println("Float.isFinite(Float.NEGATIVE_INFINITY): " + Float.isFinite(Float.NEGATIVE_INFINITY));
  System.out.println("Float.isFinite(Float.NaN): " + Float.isFinite(Float.NaN));
  System.out.println("Float.isNaN(Float.POSITIVE_INFINITY): " + Float.isNaN(Float.POSITIVE_INFINITY));
  System.out.println("Float.isNaN(Float.NEGATIVE_INFINITY): " + Float.isNaN(Float.NEGATIVE_INFINITY));
  System.out.println("Float.isNaN(Float.NaN): " + Float.isNaN(Float.NaN));
}

代码示例来源:origin: org.elasticsearch.client/elasticsearch-rest-high-level-client

Params withRequestsPerSecond(float requestsPerSecond) {
  // the default in AbstractBulkByScrollRequest is Float.POSITIVE_INFINITY,
  // but we don't want to add that to the URL parameters, instead we use -1
  if (Float.isFinite(requestsPerSecond)) {
    return putParam(RethrottleRequest.REQUEST_PER_SECOND_PARAMETER, Float.toString(requestsPerSecond));
  } else {
    return putParam(RethrottleRequest.REQUEST_PER_SECOND_PARAMETER, "-1");
  }
}

代码示例来源:origin: io.prestosql/presto-main

private void testNonTrivialAggregation(Float[] y, Float[] x)
  {
    SimpleRegression regression = new SimpleRegression();
    for (int i = 0; i < x.length; i++) {
      regression.addData(x[i], y[i]);
    }
    float expected = (float) regression.getIntercept();
    checkArgument(Float.isFinite(expected) && expected != 0.f, "Expected result is trivial");
    testAggregation(expected, createBlockOfReals(y), createBlockOfReals(x));
  }
}

代码示例来源:origin: io.prestosql/presto-main

private void testNonTrivialAggregation(Float[] y, Float[] x)
  {
    SimpleRegression regression = new SimpleRegression();
    for (int i = 0; i < x.length; i++) {
      regression.addData(x[i], y[i]);
    }
    float expected = (float) regression.getSlope();
    checkArgument(Float.isFinite(expected) && expected != 0.0f, "Expected result is trivial");
    testAggregation(expected, createBlockOfReals(y), createBlockOfReals(x));
  }
}

相关文章