本文整理汇总了Java中com.google.common.primitives.Floats类的典型用法代码示例。如果您正苦于以下问题:Java Floats类的具体用法?Java Floats怎么用?Java Floats使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Floats类属于com.google.common.primitives包,在下文中一共展示了Floats类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: topKProbabilities
import com.google.common.primitives.Floats; //导入依赖的package包/类
private List<Integer> topKProbabilities(final float[] labelProbabilities, int k) {
List<Integer> list = new ArrayList<>(labelProbabilities.length);
for (int i = 0; i < labelProbabilities.length; i++) {
list.add(i);
}
List<Integer> topK = new Ordering<Integer>() {
@Override
public int compare(Integer left, Integer right) {
return Floats.compare(labelProbabilities[left], labelProbabilities[right]);
}
}.greatestOf(list, k);
return topK;
}
开发者ID:tzolov,项目名称:tensorflow-spring-cloud-stream-app-starters,代码行数:17,代码来源:LabelImageTensorflowOutputConverter.java
示例2: toArray
import com.google.common.primitives.Floats; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
if (componentType == boolean.class) {
return Booleans.toArray((Collection) values);
} else if (componentType == byte.class) {
return Bytes.toArray((Collection) values);
} else if (componentType == short.class) {
return Shorts.toArray((Collection) values);
} else if (componentType == int.class) {
return Ints.toArray((Collection) values);
} else if (componentType == long.class) {
return Longs.toArray((Collection) values);
} else if (componentType == float.class) {
return Floats.toArray((Collection) values);
} else if (componentType == double.class) {
return Doubles.toArray((Collection) values);
} else if (componentType == char.class) {
return Chars.toArray((Collection) values);
}
return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
示例3: deserializeSingleElement
import com.google.common.primitives.Floats; //导入依赖的package包/类
private Length deserializeSingleElement(JsonElement json)
{
if (json.isJsonPrimitive())
{
JsonPrimitive primitive = json.getAsJsonPrimitive();
if (primitive.isString())
{
String value = primitive.getAsString();
if (value.endsWith("%"))
{
value = value.substring(0, value.length() - 1);
Float percentValue = Floats.tryParse(value);
if (percentValue != null)
return relative(percentValue / 100f);
}
} else
{
return absolute(json.getAsInt());
}
}
return Length.ZERO;
}
示例4: getValues
import com.google.common.primitives.Floats; //导入依赖的package包/类
static
public List<?> getValues(Tensor tensor){
DataType dataType = tensor.dataType();
switch(dataType){
case FLOAT:
return Floats.asList(TensorUtil.toFloatArray(tensor));
case DOUBLE:
return Doubles.asList(TensorUtil.toDoubleArray(tensor));
case INT32:
return Ints.asList(TensorUtil.toIntArray(tensor));
case INT64:
return Longs.asList(TensorUtil.toLongArray(tensor));
case STRING:
return Arrays.asList(TensorUtil.toStringArray(tensor));
case BOOL:
return Booleans.asList(TensorUtil.toBooleanArray(tensor));
default:
throw new IllegalArgumentException();
}
}
示例5: determineType
import com.google.common.primitives.Floats; //导入依赖的package包/类
private static URI determineType(final String data) {
if (Ints.tryParse(data) != null) {
return XMLSchema.INTEGER;
} else if (Doubles.tryParse(data) != null) {
return XMLSchema.DOUBLE;
} else if (Floats.tryParse(data) != null) {
return XMLSchema.FLOAT;
} else if (isShort(data)) {
return XMLSchema.SHORT;
} else if (Longs.tryParse(data) != null) {
return XMLSchema.LONG;
} if (Boolean.parseBoolean(data)) {
return XMLSchema.BOOLEAN;
} else if (isByte(data)) {
return XMLSchema.BYTE;
} else if (isDate(data)) {
return XMLSchema.DATETIME;
} else if (isUri(data)) {
return XMLSchema.ANYURI;
}
return XMLSchema.STRING;
}
示例6: testMapOfMultipleThings
import com.google.common.primitives.Floats; //导入依赖的package包/类
@Test
public void testMapOfMultipleThings() throws Exception {
String[] arr = {"foo", "bar", "baz", "buz", "biz"};
int[] vals = {1, 2, 3, 4, 5};
float[] floats = {1f, 2f, 3f, 4f, 5f};
Set<String> set = new LinkedHashSet<>(Arrays.asList(arr));
BufferCharSequenceSet bcsSet = new BufferCharSequenceSet(set);
int[] indices = Arrays.stream(arr).mapToInt(bcsSet::getIndex).toArray();
int[] newVals = Ints.toArray(Reorder.reorderCopy(Ints.asList(vals), indices));
float[] newFloats = Floats.toArray(Reorder.reorderCopy(Floats.asList(floats), indices));
for (int i = 0; i < arr.length; i++) {
String word = arr[i];
int index = bcsSet.getIndex(word);
assertThat(newVals[index], is(vals[i]));
assertThat(newFloats[index], is(floats[i]));
}
}
示例7: compareTo
import com.google.common.primitives.Floats; //导入依赖的package包/类
@Override
public int compareTo(ScoredFeature o) {
int c = -Float.compare(Floats.max(scores), Floats.max(o.scores));
if (c != 0) {
return c;
}
c = Integer.compare(featureScore.termIds.length, o.featureScore.termIds.length);
if (c != 0) {
return c;
}
for (int j = 0; j < featureScore.termIds.length; j++) {
c = featureScore.termIds[j].compareTo(o.featureScore.termIds[j]);
if (c != 0) {
return c;
}
}
return 0;
}
示例8: displayQRFinderPoints
import com.google.common.primitives.Floats; //导入依赖的package包/类
/**
* Update IProgress with QR finder points that were
* found during the QR decoding. It orders the (x,y)
* coordinates as follows: [x1,y2,x2,y2...xi,yi...].
*/
private void displayQRFinderPoints(Iterable<Result> decodedQRCodes) {
List<Float> list = Lists.newArrayList();
for (Result qr : decodedQRCodes) {
ResultPoint[] points = qr.getResultPoints();
if(points != null) {
for (ResultPoint point : points) {
if (point != null) {
list.add(point.getX());
list.add(point.getY());
}
}
}
}
progress.drawFinderPoints(Floats.toArray(list));
}
示例9: create
import com.google.common.primitives.Floats; //导入依赖的package包/类
public static <V> BinGenerator<V> create(
Random random, Iterable<? extends Pair<Float, ? extends V>> weightedValues) {
final ImmutableRangeMap.Builder<Float, V> bins = ImmutableRangeMap.builder();
Float lower = Float.valueOf(0.0f);
for (Pair<Float, ? extends V> weightedValue: weightedValues) {
if (weightedValue.first().floatValue() <= 0.0f) {
continue;
}
Float upper = Float.valueOf(Floats.min(1.0f, lower.floatValue() + weightedValue.first().floatValue()));
checkArgument(upper.floatValue() > lower.floatValue());
Range<Float> range = Range.closedOpen(lower, upper);
bins.put(range, weightedValue.second());
lower = upper;
}
checkArgument(Float.compare(lower.floatValue(), 1.0f) == 0);
return new BinGenerator<V>(random, bins.build());
}
示例10: getCacheKey
import com.google.common.primitives.Floats; //导入依赖的package包/类
@Override
public byte[] getCacheKey()
{
ByteBuffer abscissaBuffer = ByteBuffer.allocate(abscissa.length * Floats.BYTES);
abscissaBuffer.asFloatBuffer().put(abscissa);
final byte[] abscissaCacheKey = abscissaBuffer.array();
ByteBuffer ordinateBuffer = ByteBuffer.allocate(ordinate.length * Floats.BYTES);
ordinateBuffer.asFloatBuffer().put(ordinate);
final byte[] ordinateCacheKey = ordinateBuffer.array();
final ByteBuffer cacheKey = ByteBuffer
.allocate(1 + abscissaCacheKey.length + ordinateCacheKey.length + Ints.BYTES)
.put(abscissaCacheKey)
.put(ordinateCacheKey)
.putInt(getLimit())
.put(CACHE_TYPE_ID);
return cacheKey.array();
}
示例11: getCacheKey
import com.google.common.primitives.Floats; //导入依赖的package包/类
@Override
public byte[] getCacheKey()
{
ByteBuffer minCoordsBuffer = ByteBuffer.allocate(minCoords.length * Floats.BYTES);
minCoordsBuffer.asFloatBuffer().put(minCoords);
final byte[] minCoordsCacheKey = minCoordsBuffer.array();
ByteBuffer maxCoordsBuffer = ByteBuffer.allocate(maxCoords.length * Floats.BYTES);
maxCoordsBuffer.asFloatBuffer().put(maxCoords);
final byte[] maxCoordsCacheKey = maxCoordsBuffer.array();
final ByteBuffer cacheKey = ByteBuffer
.allocate(1 + minCoordsCacheKey.length + maxCoordsCacheKey.length + Ints.BYTES)
.put(minCoordsCacheKey)
.put(maxCoordsCacheKey)
.putInt(limit)
.put(CACHE_TYPE_ID);
return cacheKey.array();
}
示例12: ImmutableNode
import com.google.common.primitives.Floats; //导入依赖的package包/类
public ImmutableNode(
int numDims,
int initialOffset,
int offsetFromInitial,
ByteBuffer data,
BitmapFactory bitmapFactory
)
{
this.bitmapFactory = bitmapFactory;
this.numDims = numDims;
this.initialOffset = initialOffset;
this.offsetFromInitial = offsetFromInitial;
short header = data.getShort(initialOffset + offsetFromInitial);
this.isLeaf = (header & 0x8000) != 0;
this.numChildren = (short) (header & 0x7FFF);
final int sizePosition = initialOffset + offsetFromInitial + HEADER_NUM_BYTES + 2 * numDims * Floats.BYTES;
int bitmapSize = data.getInt(sizePosition);
this.childrenOffset = initialOffset
+ offsetFromInitial
+ HEADER_NUM_BYTES
+ 2 * numDims * Floats.BYTES
+ Ints.BYTES
+ bitmapSize;
this.data = data;
}
示例13: func_175327_a
import com.google.common.primitives.Floats; //导入依赖的package包/类
private void func_175327_a(float p_175327_1_)
{
Gui gui = this.field_175349_r.func_178056_g();
if (gui instanceof GuiTextField)
{
float f = p_175327_1_;
if (GuiScreen.isShiftKeyDown())
{
f = p_175327_1_ * 0.1F;
if (GuiScreen.isCtrlKeyDown())
{
f *= 0.1F;
}
}
else if (GuiScreen.isCtrlKeyDown())
{
f = p_175327_1_ * 10.0F;
if (GuiScreen.isAltKeyDown())
{
f *= 10.0F;
}
}
GuiTextField guitextfield = (GuiTextField)gui;
Float f1 = Floats.tryParse(guitextfield.getText());
if (f1 != null)
{
f1 = Float.valueOf(f1.floatValue() + f);
int i = guitextfield.getId();
String s = this.func_175330_b(guitextfield.getId(), f1.floatValue());
guitextfield.setText(s);
this.func_175319_a(i, s);
}
}
}
示例14: modifyFocusValue
import com.google.common.primitives.Floats; //导入依赖的package包/类
private void modifyFocusValue(float p_175327_1_)
{
Gui gui = this.list.getFocusedControl();
if (gui instanceof GuiTextField)
{
float f = p_175327_1_;
if (GuiScreen.isShiftKeyDown())
{
f = p_175327_1_ * 0.1F;
if (GuiScreen.isCtrlKeyDown())
{
f *= 0.1F;
}
}
else if (GuiScreen.isCtrlKeyDown())
{
f = p_175327_1_ * 10.0F;
if (GuiScreen.isAltKeyDown())
{
f *= 10.0F;
}
}
GuiTextField guitextfield = (GuiTextField)gui;
Float f1 = Floats.tryParse(guitextfield.getText());
if (f1 != null)
{
f1 = Float.valueOf(f1.floatValue() + f);
int i = guitextfield.getId();
String s = this.getFormattedValue(guitextfield.getId(), f1.floatValue());
guitextfield.setText(s);
this.setEntryValue(i, s);
}
}
}
示例15: func_175327_a
import com.google.common.primitives.Floats; //导入依赖的package包/类
private void func_175327_a(float p_175327_1_)
{
Gui gui = this.field_175349_r.getFocusedControl();
if (gui instanceof GuiTextField)
{
float f1 = p_175327_1_;
if (GuiScreen.isShiftKeyDown())
{
f1 = p_175327_1_ * 0.1F;
if (GuiScreen.isCtrlKeyDown())
{
f1 *= 0.1F;
}
}
else if (GuiScreen.isCtrlKeyDown())
{
f1 = p_175327_1_ * 10.0F;
if (GuiScreen.isAltKeyDown())
{
f1 *= 10.0F;
}
}
GuiTextField guitextfield = (GuiTextField)gui;
Float f2 = Floats.tryParse(guitextfield.getText());
if (f2 != null)
{
f2 = Float.valueOf(f2.floatValue() + f1);
int i = guitextfield.getId();
String s = this.func_175330_b(guitextfield.getId(), f2.floatValue());
guitextfield.setText(s);
this.setEntryValue(i, s);
}
}
}