本文整理了Java中org.apache.sis.math.Vector.getElementType()
方法的一些代码示例,展示了Vector.getElementType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.getElementType()
方法的具体详情如下:
包路径:org.apache.sis.math.Vector
类名称:Vector
方法名:getElementType
[英]Returns the type of elements in this vector. If this vector is backed by an array of a primitive type, then this method returns the wrapper class, not the primitive type. For example if this vector is backed by an array of type float[], then this method returns Float.class, not Float#TYPE.
The information returned by this method is only indicative; it is not guaranteed to specify accurately this kind of objects returned by the #get(int) method. There is various situation where the types may not match:
Users of the #doubleValue(int) method do not need to care about this information since Vector will perform automatically the type conversion. Users of other methods may want to verify this information for avoiding ArithmeticException.
[中]返回此向量中元素的类型。如果此向量由基元类型的数组支持,则此方法返回wrapper类,而不是基元类型。例如,如果该向量由float[]类型的数组支持,则该方法返回float。类,而不是浮动类型。
此方法返回的信息仅供参考;不能保证精确指定#get(int)方法返回的此类对象。在各种情况下,类型可能不匹配:
*如果此向量#为unsigned(),则get(int)返回的值可能是比此向量用于存储值的类型更宽的类型的实例。
*如果这个向量是#createForDecimal(float[]),那么get(int)返回的值将使用双精度,即使这个向量将这些值存储为单精度浮点数。
*如果此向量#compress(double),则此方法返回的类型无法准确描述此向量可以存储的值的范围。
#doubleValue(int)方法的用户不需要关心这些信息,因为Vector将自动执行类型转换。其他方法的用户可能希望验证此信息,以避免算术异常。
代码示例来源:origin: apache/sis
/**
* Returns the type of values, which is inherited from the {@linkplain #base} vector.
*/
@Override
public final Class<? extends Number> getElementType() {
return base.getElementType();
}
代码示例来源:origin: org.apache.sis.core/sis-utility
/** Returns the type of elements in this vector. */
@Override public Class<? extends Number> getElementType() {
return Vector.this.getElementType();
}
代码示例来源:origin: org.apache.sis.core/sis-utility
/** Returns the type of elements in this vector. */
@Override public Class<? extends Number> getElementType() {
return Vector.this.getElementType();
}
代码示例来源:origin: apache/sis
/** Returns the type of elements in this vector. */
@Override public Class<? extends Number> getElementType() {
return Vector.this.getElementType();
}
代码示例来源:origin: apache/sis
/** Returns the type of elements in this vector. */
@Override public Class<? extends Number> getElementType() {
return Vector.this.getElementType();
}
代码示例来源:origin: org.apache.sis.core/sis-utility
/**
* Returns the parent type of the two vectors.
*/
@Override
public Class<? extends Number> getElementType() {
return Classes.findCommonClass(first.getElementType(), second.getElementType()).asSubclass(Number.class);
}
代码示例来源:origin: apache/sis
/**
* Returns the parent type of the two vectors.
*/
@Override
public Class<? extends Number> getElementType() {
return Classes.findCommonClass(first.getElementType(), second.getElementType()).asSubclass(Number.class);
}
代码示例来源:origin: apache/sis
/**
* Returns an estimation of the number of bits used by each value in this vector.
* This is an estimation only and should be used only as a hint.
*/
private int getBitCount() {
try {
return Numbers.primitiveBitCount(getElementType());
} catch (IllegalArgumentException e) {
return Integer.SIZE; // Assume references compressed on 32 bits.
}
}
代码示例来源:origin: org.apache.sis.core/sis-utility
/**
* Returns {@code true} if this vector contains only integer values.
* This method may iterate over all values for performing this verification.
*
* @return {@code true} if this vector contains only integer values.
*/
public boolean isInteger() {
if (!Numbers.isInteger(getElementType())) {
for (int i=size(); --i >= 0;) {
final double v = doubleValue(i);
if (v != Math.floor(v)) {
return false;
}
}
}
return true;
}
代码示例来源:origin: apache/sis
/**
* Returns {@code true} if this vector contains only integer values.
* This method may iterate over all values for performing this verification.
*
* @return {@code true} if this vector contains only integer values.
*/
public boolean isInteger() {
if (!Numbers.isInteger(getElementType())) {
for (int i=size(); --i >= 0;) {
final double v = doubleValue(i);
if (v != Math.floor(v)) {
return false;
}
}
}
return true;
}
代码示例来源: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.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
/**
* 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
default: throw new AssertionError(type);
String message = vec.getElementType().getSimpleName();
if (vec.isUnsigned()) {
message = "Unsigned " + message;
assertNotNull(message, inc);
assertEquals (message, 3, inc.doubleValue(), STRICT);
assertEquals (message, vec.getElementType(), inc.getClass());
代码示例来源:origin: apache/sis
/**
* Tests {@link SequenceVector} with byte values.
*/
@Test
public void testSequenceOfBytes() {
vector = Vector.createSequence(100, 2, 10);
assertEquals(Integer.class, vector.getElementType());
assertEquals(10, vector.size());
for (int i=0; i<vector.size(); i++) {
assertEquals(100 + 2*i, vector.byteValue(i));
}
}
代码示例来源:origin: apache/sis
/**
* Tests {@link SequenceVector} with float values.
*/
@Test
public void testSequenceOfFloats() {
vector = Vector.createSequence(100, 0.1, 10);
assertEquals(Double.class, vector.getElementType());
assertEquals(10, vector.size());
for (int i=0; i<vector.size(); i++) {
assertEquals(100 + 0.1*i, vector.doubleValue(i), 1E-10);
}
}
代码示例来源:origin: apache/sis
/**
* Tests {@link ArrayVector} backed by an array of float type.
*/
@Test
public void testFloatArray() {
final float[] array = new float[400];
for (int i=0; i<array.length; i++) {
array[i] = (i + 100) * 10;
}
vector = Vector.create(array, false);
assertEquals("Floats", vector.getClass().getSimpleName());
assertSame(vector, Vector.create(vector, false));
assertEquals(array.length, vector.size());
assertEquals(Float.class, vector.getElementType());
/*
* Tests element values.
*/
for (int i=0; i<array.length; i++) {
assertEquals(array[i], vector.floatValue (i), 0f);
assertEquals(array[i], vector.doubleValue(i), STRICT);
}
}
代码示例来源:origin: apache/sis
/**
* Tests {@link ArrayVector} backed by an array of double type.
*/
@Test
public void testDoubleArray() {
final double[] array = new double[400];
for (int i=0; i<array.length; i++) {
array[i] = (i + 100) * 10;
}
vector = Vector.create(array, false);
assertEquals("Doubles", vector.getClass().getSimpleName());
assertSame(vector, Vector.create(vector, false));
assertEquals(array.length, vector.size());
assertEquals(Double.class, vector.getElementType());
/*
* Tests element values.
*/
for (int i=0; i<array.length; i++) {
assertEquals(array[i], vector.floatValue (i), 0f);
assertEquals(array[i], vector.doubleValue(i), STRICT);
}
}
代码示例来源:origin: apache/sis
/**
* Tests {@link Variable#read()} on a one-dimensional variable.
*
* @throws IOException if an error occurred while reading the netCDF file.
* @throws DataStoreException if a logical error occurred.
*/
@Test
public void testRead1D() throws IOException, DataStoreException {
final Variable variable = selectDataset(TestData.NETCDF_2D_GEOGRAPHIC).getVariables()[2];
assertEquals("lon", variable.getName());
final Vector data = variable.read();
assertEquals("lon", Float.class, data.getElementType());
final int length = data.size();
assertEquals("length", 73, length);
for (int i=0; i<length; i++) {
assertEquals("Longitude value", -180 + 5*i, data.floatValue(i), 0f);
}
}
}
代码示例来源:origin: apache/sis
Vector v3 = v1.concatenate(v2);
assertEquals("Length of V3 should be the sum of V1 and V2 length.", 60, v3.size());
assertEquals("Component type should be the common parent of V1 and V2.", Number.class, v3.getElementType());
assertEquals("Sample from V1.", Float .valueOf(200), v3.get(20));
assertEquals("Sample from V2.", Integer.valueOf(500), v3.get(50));
内容来源于网络,如有侵权,请联系作者删除!