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

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

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

Vector.compress介绍

[英]Returns a vector with the same data than this vector but encoded in a more compact way, or this if this method can not do better than current Vector instance. Examples:

  • Vector is backed by an int[] array while values could be stored as short values.
  • Vector contains increasing or decreasing values with a constant delta between consecutive values.
    The returned vector may or may not be backed by the array given to the #create(Object,boolean) method. Since the returned array may be a copy of this array, caller should not retain reference to thisor reference to the backing array after this method call (otherwise an unnecessary duplication of data may exist in memory).

When to use
It is usually not worth to compress small arrays. Performance-critical arrays may not be compressed neither. This method is best suited for vectors that may potentially be large and for which the cost of fetching values in that vector is small compared to the calculation performed with the values.
[中]返回一个向量,该向量的数据与该向量相同,但编码方式更紧凑,如果该方法不能比当前向量实例更好,则返回该向量。例如:
*向量由int[]数组支持,而值可以存储为短值。
*向量包含递增或递减的值,连续值之间的增量为常数。
返回的向量可以由#create(Object,boolean)方法的数组支持,也可以不支持。由于返回的数组可能是该数组的副本,因此调用方不应在该方法调用后保留对该数组的引用或对支持数组的引用(否则内存中可能存在不必要的数据重复)。
何时使用
压缩小数组通常不值得。性能关键型阵列也可能无法压缩。此方法最适合于可能较大的向量,并且与使用值执行的计算相比,获取该向量中的值的成本较小。

代码示例

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

/**
 * Creates a new list for the given times.
 */
DateList(final long[] millis) {
  times = Vector.create(millis, false).compress(0);
}

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

/**
 * Creates a new list for the given times.
 */
DateList(final long[] millis) {
  times = Vector.create(millis, false).compress(0);
}

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

/**
 * If the vector can not be compressed, copies data in a new vector in order to have a smaller vector
 * than the one backing this view. This is advantageous only on the assumption that user do not keep
 * a reference to the original vector after {@link Vector#compress(double)} call.
 */
@Override
public Vector compress(final double tolerance) {
  final Vector c = super.compress(tolerance);
  return (c != this) ? c : copy();
}

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

/**
   * If the vector can not be compressed, copies data in a new vector in order to have a smaller vector
   * than the one backing this view. This is advantageous only on the assumption that user do not keep
   * a reference to the original vector after {@link Vector#compress(double)} call.
   */
  @Override
  public Vector compress(final double tolerance) {
    final Vector c = super.compress(tolerance);
    return (c != this) ? c : copy();
  }
}

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

/**
 * Creates a vector of repeated data from the result of a call to {@link Vector#repetitions(int...)}.
 *
 * @param base         the vector on which this vector is derived from.
 * @param repetitions  results of {@link Vector#repetitions(int...)}. Must be non-empty.
 * @param tolerance    tolerance factor for compression of the base vector.
 */
RepeatedVector(final Vector base, final int[] repetitions, final double tolerance) {
  size        = base.size();
  occurrences = repetitions[0];
  cycleLength = (repetitions.length >= 2) ? repetitions[1] : size / occurrences;
  this.base   = base.subSampling(0, occurrences, cycleLength).compress(tolerance);
}

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

/**
 * Sets the values in this variable. The values are normally read from the netCDF file by the {@link #read()} method,
 * but this {@code setValues(Object)} method may also be invoked if we want to overwrite those values.
 *
 * @param  array  the values as an array of primitive type (for example {@code float[]}.
 */
final void setValues(final Object array) {
  Vector data = createDecimalVector(array, dataType.isUnsigned);
  /*
   * This method is usually invoked with vector of increasing or decreasing values.  Set a tolerance threshold to the
   * precision of gratest (in magnitude) number, provided that this precision is not larger than increment. If values
   * are not sorted in increasing or decreasing order, the tolerance computed below will be smaller than it could be.
   * This is okay it will cause more conservative compression (i.e. it does not increase the risk of data loss).
   */
  double tolerance = 0;
  if (Numbers.isFloat(data.getElementType())) {
    final int n = data.size() - 1;
    if (n >= 0) {
      double first = data.doubleValue(0);
      double last  = data.doubleValue(n);
      double inc   = Math.abs((last - first) / n);
      if (!Double.isNaN(inc)) {
        double ulp = Math.ulp(Math.max(Math.abs(first), Math.abs(last)));
        tolerance = Math.min(inc, ulp);
      }
    }
  }
  values = data.compress(tolerance);
  values = SHARED_VECTORS.unique(values);
}

代码示例来源:origin: org.apache.sis.storage/sis-netcdf

.compress(0);

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

Vector compressed = vec.compress(0);
assertSame(vec, compressed);
assertNotSame(vec, compressed = vec.compress(0));
assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
assertEquals("elementType", Byte.class, compressed.getElementType());
assertNotSame(vec, compressed = vec.compress(0));
assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
assertEquals("elementType", Byte.class, compressed.getElementType());
assertNotSame(vec, compressed = vec.compress(0));
assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
assertEquals("elementType", Short.class, compressed.getElementType());
assertNotSame(vec, compressed = vec.compress(0));
assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
assertEquals("elementType", Short.class, compressed.getElementType());
assertNotSame(vec, compressed = vec.compress(0));
assertInstanceOf("vector.compress(0)", PackedVector.class, compressed);
assertContentEquals(vec, compressed);
assertNotSame(vec, compressed = vec.compress(0));
assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
assertEquals("elementType", Byte.class, compressed.getElementType());
assertNotSame(vec, compressed = vec.compress(0));
assertInstanceOf("vector.compress(0)", PackedVector.class, compressed);

相关文章