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

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

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

Vector.repetitions介绍

[英]Detects repetition patterns in the values contained in this vector. The repetitions detected by this method are patterns that at repeated at a regular interval on the whole vector; this method does not search for repetitions occurring at irregular intervals. This method returns an array of typically 0, 1 or 2 elements where zero element means that no repetition has been found, one element describes a repetition (see the example below), and two elements describes a repetition of the repetitions (examples below). More elements (deeper recursivity) are theoretically possible but not yet implemented.

If the values in this vector are of the form (x, x, …, x, y, y, …, y, z, z, …, z, …), then the first integer in the returned array is the number of consecutive x values before the y values. That number of occurrences must be the same than the number of consecutive y values before the z values, the number of consecutive z values before the next values, and so on until the end of the vector.

Examples: in the following vector, each value is repeated 3 times. So the array returned by this method would be {4}}, meaning that the first number appears 4 times, followed by a new number appearing 4 times, followed by a new number appearing 4 times, and so on until the end of the vector. text For the next level (the second integer in the returned array), this method represents above repetitions by single entities then reapplies the same repetition detection. This method processes has if the (x, x, …, x, y, y, …, y, z, z, …, z, …) vector was replaced by a new (x, y, z, …) vector, then the same detection algorithm was applied recursively.

Examples: in the following vector, each value is repeated 2 times, then the sequence of 12 values is itself repeated 2 times. So the array returned by this method would be {3,4}}, meaning that the first number appears 3 times, followed by a new number appearing 3 times, etc. until we counted 4 groups of 3 numbers. Then the whole sequence is repeated until the end of the vector. text

This method is useful for analyzing the localization grid provided by some files (for example in netCDF format). Those grids sometime have constant longitude for the same column index, or constant latitude for the same row index. This method can detect such regularity, which allows more efficient handling of the grid to CRS transform.
[中]检测此向量中包含的值中的重复模式。该方法检测到的重复是在整个向量上以规则间隔重复的模式;这种方法不会搜索不规则间隔的重复。此方法返回一个通常由0、1或2个元素组成的数组,其中0个元素表示未找到重复,一个元素表示重复(参见下面的示例),两个元素表示重复的重复(下面的示例)。更多元素(更深层的递归性)在理论上是可能的,但尚未实现。
如果此向量中的值的形式为(x,x,…,x,y,y,…,y,z,z,…,z,…),则返回数组中的第一个整数是y值之前的连续x值数。该出现次数必须与z值之前的连续y值数量、下一个值之前的连续z值数量等相同,直到向量结束。
示例:在以下向量中,每个值重复3次。所以这个方法返回的数组将是{4},这意味着第一个数字出现4次,后面是一个新数字出现4次,后面是一个新数字出现4次,依此类推,直到向量结束。对于下一级(返回数组中的第二个整数),此方法表示单个实体的上述重复,然后重新应用相同的重复检测。该方法处理的是,如果(x,x,…,x,y,y,…,y,z,…)向量被一个新的(x,y,z,…)向量替换,则递归地应用相同的检测算法。
示例:在以下向量中,每个值重复2次,然后12个值的序列本身重复2次。所以这个方法返回的数组是{3,4},这意味着第一个数字出现了3次,然后一个新数字出现了3次,以此类推,直到我们计算了4组3个数字。然后重复整个序列,直到向量结束。文本
此方法对于分析某些文件(例如netCDF格式)提供的本地化网格非常有用。这些网格有时对同一列索引具有恒定的经度,或对同一行索引具有恒定的纬度。这种方法可以检测到这种规律性,从而可以更有效地处理网格到CRS的变换。

代码示例

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

/**
 * Tests {@link Vector#repetitions(int...)}.
 */
@Test
public void testRepetitions() {
  Vector vec = Vector.create(new int[] {
      10, 10, 10, 10,
      12, 12, 13, 12,             // Different value (13) break the regularity.
      15, 15, 15, 15}, false);
  assertArrayEquals(new int[] {}, vec.repetitions());
  vec = Vector.create(new int[] {
      10, 10, 10, 10,
      12, 12, 12, 12,
      15, 15, 15, 15}, false);
  assertArrayEquals(new int[] {4}, vec.repetitions());
  vec = Vector.create(new int[] {
      10, 10, 10,  12, 12, 12,  15, 15, 15,  18, 18, 18,
      10, 10, 10,  12, 12, 12,  15, 15, 15,  18, 18, 18,
      10, 10, 10,  12, 12, 12,  15, 15, 15,  18, 18, 18}, false);
  assertArrayEquals(new int[] {3,4}, vec.repetitions());
  vec = Vector.create(new int[] {
      10, 12, 15, 18,
      10, 12, 15, 18,
      10, 12, 15, 18}, false);
  assertArrayEquals(new int[] {1,4}, vec.repetitions());
}

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

final int[] repetitions = data.repetitions(sourceSizes);    // Detects repetitions as illustrated above.
if (repetitions.length != 0) {
  for (int i=0; i<sourceDimensions.length; i++) {

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

final int[] repetitions = repetitions(MathFunctions.divisors(length));
switch (repetitions.length) {
  default: if (length - repetitions[1] < length/4) break;               // Otherwise fallthrough.

代码示例来源: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

/**
 * 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

10, 10, 10,  12, 15, 18}, false);
vec = new RepeatedVector(vec, vec.repetitions(), 0);
final int expectedBackingVectorLength = (ip == 10) ? 6 : 12;
assertArrayEquals(new int[] {1, expectedBackingVectorLength}, vec.repetitions());

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

10, 10, 10,  12, 12, 12,  15, 15, 15,  18, 18, 18}, false);
vec = new RepeatedVector(vec, vec.repetitions(), 0);
assertArrayEquals(new int[] {3,4}, vec.repetitions());

相关文章