org.apache.sis.math.Vector.floatValues()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(81)

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

Vector.floatValues介绍

[英]Copies all values in an array of single precision floating point numbers. This method is for inter-operability with APIs requiring an array of primitive type.

The default implementation invokes #floatValue(int) for all indices from 0 inclusive to #size() exclusive. Subclasses may override with more efficient implementation.
[中]复制单精度浮点数数组中的所有值。此方法用于与需要基元类型数组的API的互操作性。
默认实现为从0到#size()exclusive的所有索引调用#floatValue(int)。子类可以通过更高效的实现进行重写。

代码示例

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

/**
 * Creates the sequence as a floating point array.
 */
@Override
public float[] floatValues() {
  if (increment(0).doubleValue() == 0) {
    final float[] array = new float[size()];
    Arrays.fill(array, floatValue(0));
    return array;
  }
  return super.floatValues();
}

代码示例来源:origin: apache/sis

/**
 * Creates the sequence as a floating point array.
 */
@Override
public float[] floatValues() {
  if (increment(0).doubleValue() == 0) {
    final float[] array = new float[size()];
    Arrays.fill(array, floatValue(0));
    return array;
  }
  return super.floatValues();
}

代码示例来源:origin: apache/sis

/**
 * Returns a vector with the same data than the given vector but encoded in a more compact way,
 * or {@code null} if this method can not do better than the given {@code Vector} instance.
 * This method shall be invoked only for vector of floating point values (this is not verified).
 */
static Vector compress(final Vector source, final double tolerance) {
  if (!Float.class.equals(source.getElementType())) {
    /*
     * For floating point types, verify if values are equivalent to 'float' values.
     * There is two different ways to pad extra fraction digits in 'double' values:
     * with zero fraction digits in base 2 representation (the standard Java cast),
     * or with zero fraction digits in base 10 representation.
     */
    final int length = source.size();
    int i = 0;
    double v;
    do if (i >= length) {
      return new Floats(source.floatValues());
    } while (!(Math.abs((v = source.doubleValue(i++)) - (float) v) > tolerance));    // Use '!' for accepting NaN.
    /*
     * Same try than above loop, but now using base 10 representation.
     * This is a more costly computation.
     */
    i = 0;
    do if (i >= length) {
      return new Decimal(source.floatValues());
    } while (!(Math.abs((v = source.doubleValue(i++)) - DecimalFunctions.floatToDouble((float) v)) > tolerance));
  }
  return null;
}

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

/**
 * Returns a vector with the same data than the given vector but encoded in a more compact way,
 * or {@code null} if this method can not do better than the given {@code Vector} instance.
 * This method shall be invoked only for vector of floating point values (this is not verified).
 */
static Vector compress(final Vector source, final double tolerance) {
  if (!Float.class.equals(source.getElementType())) {
    /*
     * For floating point types, verify if values are equivalent to 'float' values.
     * There is two different ways to pad extra fraction digits in 'double' values:
     * with zero fraction digits in base 2 representation (the standard Java cast),
     * or with zero fraction digits in base 10 representation.
     */
    final int length = source.size();
    int i = 0;
    double v;
    do if (i >= length) {
      return new Floats(source.floatValues());
    } while (!(Math.abs((v = source.doubleValue(i++)) - (float) v) > tolerance));    // Use '!' for accepting NaN.
    /*
     * Same try than above loop, but now using base 10 representation.
     * This is a more costly computation.
     */
    i = 0;
    do if (i >= length) {
      return new Decimal(source.floatValues());
    } while (!(Math.abs((v = source.doubleValue(i++)) - DecimalFunctions.floatToDouble((float) v)) > tolerance));
  }
  return null;
}

代码示例来源:origin: apache/sis

array = floatValues();
if (size != 0 && get(0) instanceof Double) {
  return createForDecimal((float[]) array);

代码示例来源:origin: apache/sis

assertArrayEquals(new float[] {10, 10, 10, 12, 15, 18}, sub.floatValues(), (float) STRICT);
                10, ip, 10, 12, 15, 18}, sub.floatValues(), (float) STRICT);

代码示例来源:origin: apache/sis

/**
 * Tests the case where values in a grid are repeated horizontally.
 */
@Test
public void testHorizontal() {
  Vector vec = Vector.create(new int[] {
      10, 10, 10, 10,
      12, 12, 12, 12,
      15, 15, 15, 15}, false);
  vec = new RepeatedVector(vec, vec.repetitions(), 0);
  assertArrayEquals(new int[] {4}, vec.repetitions());
  assertEquals(10, vec.intValue  ( 0));
  assertEquals(10, vec.shortValue( 1));
  assertEquals(10, vec.longValue ( 2));
  assertEquals(10, vec.intValue  ( 3));
  assertEquals(12, vec.intValue  ( 4));
  assertEquals(12, vec.shortValue( 7));
  assertEquals(15, vec.longValue ( 8));
  assertEquals(15, vec.intValue  (11));
  Vector sub = vec.subSampling(0, 4, 3);
  assertFalse("Expected the backing array.", sub instanceof RepeatedVector);
  assertArrayEquals(new float[] {10, 12, 15}, sub.floatValues(), (float) STRICT);
}

代码示例来源:origin: apache/sis

/**
 * Tests the case where values in a grid are repeated vertically.
 */
@Test
public void testVertical() {
  Vector vec = Vector.create(new int[] {
      10, 12, 15, 18,
      10, 12, 15, 18,
      10, 12, 15, 18}, false);
  vec = new RepeatedVector(vec, vec.repetitions(), 0);
  assertArrayEquals(new int[] {1,4}, vec.repetitions());
  assertEquals(10, vec.intValue  ( 0));
  assertEquals(12, vec.shortValue( 1));
  assertEquals(15, vec.longValue ( 2));
  assertEquals(18, vec.intValue  ( 3));
  assertEquals(10, vec.intValue  ( 4));
  assertEquals(18, vec.shortValue( 7));
  assertEquals(10, vec.longValue ( 8));
  assertEquals(15, vec.intValue  (10));
  Vector sub = vec.subList(0, 4);
  assertFalse("Expected the backing array.", sub instanceof RepeatedVector);
  assertArrayEquals(new float[] {10, 12, 15, 18}, sub.floatValues(), (float) STRICT);
}

代码示例来源:origin: apache/sis

assertArrayEquals(new float[] {10, 12, 15, 18}, sub.floatValues(), (float) STRICT);

相关文章